mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-02 12:42:20 +00:00
Add support for chat via new conversation
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
e20f4c9d82
commit
b268c8aba6
@ -23,14 +23,16 @@ package com.nextcloud.talk.controllers;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bluelinelabs.conductor.RouterTransaction;
|
||||
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
@ -40,6 +42,7 @@ import com.nextcloud.talk.api.NcApi;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.controllers.base.BaseController;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.models.json.call.Call;
|
||||
import com.nextcloud.talk.models.json.call.CallOverall;
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage;
|
||||
import com.nextcloud.talk.models.json.chat.ChatOverall;
|
||||
@ -86,6 +89,9 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
||||
private String conversationName;
|
||||
private String roomToken;
|
||||
private UserEntity currentUser;
|
||||
private String roomPassword;
|
||||
|
||||
private Call currentCall;
|
||||
|
||||
private boolean inChat = false;
|
||||
private boolean historyRead = false;
|
||||
@ -100,6 +106,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
||||
this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME);
|
||||
this.currentUser = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_USER_ENTITY));
|
||||
this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN);
|
||||
this.roomPassword = args.getString(BundleKeys.KEY_ROOM_PASSWORD, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -146,7 +153,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
||||
});
|
||||
|
||||
if (adapterWasNull) {
|
||||
joinRoomWithPassword(null);
|
||||
joinRoomWithPassword();
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,20 +175,46 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
inChat = false;
|
||||
getRouter().popCurrentController();
|
||||
if (getRouter().hasRootController()) {
|
||||
getRouter().popToRoot(new HorizontalChangeHandler());
|
||||
} else {
|
||||
getRouter().setRoot(RouterTransaction.with(new MagicBottomNavigationController())
|
||||
.pushChangeHandler(new HorizontalChangeHandler())
|
||||
.popChangeHandler(new HorizontalChangeHandler()));
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean handleBack() {
|
||||
if (getRouter().hasRootController()) {
|
||||
getRouter().popToRoot(new HorizontalChangeHandler());
|
||||
} else {
|
||||
getRouter().setRoot(RouterTransaction.with(new MagicBottomNavigationController())
|
||||
.pushChangeHandler(new HorizontalChangeHandler())
|
||||
.popChangeHandler(new HorizontalChangeHandler()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
inChat = false;
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void joinRoomWithPassword(@Nullable String password) {
|
||||
private void joinRoomWithPassword() {
|
||||
String password = "";
|
||||
|
||||
if (TextUtils.isEmpty(roomPassword)) {
|
||||
password = roomPassword;
|
||||
}
|
||||
|
||||
ncApi.joinRoom(ApiUtils.getCredentials(currentUser.getUserId(), currentUser.getToken()), ApiUtils
|
||||
.getUrlForRoomParticipants(currentUser.getBaseUrl(), roomToken), password)
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
@ -197,6 +230,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
||||
public void onNext(CallOverall callOverall) {
|
||||
inChat = true;
|
||||
pullChatMessages(0);
|
||||
currentCall = callOverall.getOcs().getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,9 +110,11 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
||||
public static final String TAG = "ContactsController";
|
||||
|
||||
private static final String KEY_SEARCH_QUERY = "ContactsController.searchQuery";
|
||||
@Nullable @BindView(R.id.initial_relative_layout)
|
||||
@Nullable
|
||||
@BindView(R.id.initial_relative_layout)
|
||||
public RelativeLayout initialRelativeLayout;
|
||||
@Nullable @BindView(R.id.secondary_relative_layout)
|
||||
@Nullable
|
||||
@BindView(R.id.secondary_relative_layout)
|
||||
public RelativeLayout secondaryRelativeLayout;
|
||||
@Inject
|
||||
UserUtils userUtils;
|
||||
@ -267,13 +269,21 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
||||
|
||||
@Override
|
||||
public void onNext(RoomOverall roomOverall) {
|
||||
if (getActivity() != null) {
|
||||
Intent callIntent = new Intent(getActivity(), CallActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
|
||||
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
|
||||
callIntent.putExtras(bundle);
|
||||
startActivity(callIntent);
|
||||
Intent conversationIntent = new Intent(getActivity(), CallActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
|
||||
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
|
||||
|
||||
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
|
||||
conversationIntent.putExtras(bundle);
|
||||
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME,
|
||||
roomOverall.getOcs().getData().getDisplayName());
|
||||
getRouter().pushController((RouterTransaction.with(new ChatController(bundle))
|
||||
.pushChangeHandler(new HorizontalChangeHandler())
|
||||
.popChangeHandler(new HorizontalChangeHandler())));
|
||||
} else {
|
||||
conversationIntent.putExtras(bundle);
|
||||
startActivity(conversationIntent);
|
||||
new Handler().postDelayed(() -> getRouter().popCurrentController(), 100);
|
||||
}
|
||||
}
|
||||
@ -414,6 +424,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
||||
retrofitBucket.getUrl(), retrofitBucket.getQueryMap())
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.retry(3)
|
||||
.subscribe((ShareesOverall shareesOverall) -> {
|
||||
if (shareesOverall != null) {
|
||||
|
||||
|
@ -46,4 +46,5 @@ public class BundleKeys {
|
||||
public static final String KEY_CONVERSATION_TYPE = "KEY_CONVERSATION_TYPE";
|
||||
public static final String KEY_INVITED_PARTICIPANTS = "KEY_INVITED_PARTICIPANTS";
|
||||
public static final String KEY_CONVERSATION_NAME = "KEY_CONVERSATION_NAME";
|
||||
public static final String KEY_ROOM_PASSWORD = "KEY_ROOM_PASSWORD";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user