Add support for chat via new conversation

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-04-28 09:51:53 +02:00
parent e20f4c9d82
commit b268c8aba6
3 changed files with 59 additions and 13 deletions

View File

@ -23,14 +23,16 @@ package com.nextcloud.talk.controllers;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; 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.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CircleCrop; import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions; 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.application.NextcloudTalkApplication;
import com.nextcloud.talk.controllers.base.BaseController; import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.models.database.UserEntity; 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.call.CallOverall;
import com.nextcloud.talk.models.json.chat.ChatMessage; import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.nextcloud.talk.models.json.chat.ChatOverall; import com.nextcloud.talk.models.json.chat.ChatOverall;
@ -86,6 +89,9 @@ public class ChatController extends BaseController implements MessagesListAdapte
private String conversationName; private String conversationName;
private String roomToken; private String roomToken;
private UserEntity currentUser; private UserEntity currentUser;
private String roomPassword;
private Call currentCall;
private boolean inChat = false; private boolean inChat = false;
private boolean historyRead = 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.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME);
this.currentUser = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_USER_ENTITY)); this.currentUser = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_USER_ENTITY));
this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN); this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN);
this.roomPassword = args.getString(BundleKeys.KEY_ROOM_PASSWORD, "");
} }
@Override @Override
@ -146,7 +153,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
}); });
if (adapterWasNull) { if (adapterWasNull) {
joinRoomWithPassword(null); joinRoomWithPassword();
} }
} }
@ -168,20 +175,46 @@ public class ChatController extends BaseController implements MessagesListAdapte
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
inChat = false; 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; return true;
default: default:
return super.onOptionsItemSelected(item); 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 @Override
public void onDestroy() { public void onDestroy() {
inChat = false; inChat = false;
super.onDestroy(); 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 ncApi.joinRoom(ApiUtils.getCredentials(currentUser.getUserId(), currentUser.getToken()), ApiUtils
.getUrlForRoomParticipants(currentUser.getBaseUrl(), roomToken), password) .getUrlForRoomParticipants(currentUser.getBaseUrl(), roomToken), password)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
@ -197,6 +230,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
public void onNext(CallOverall callOverall) { public void onNext(CallOverall callOverall) {
inChat = true; inChat = true;
pullChatMessages(0); pullChatMessages(0);
currentCall = callOverall.getOcs().getData();
} }
@Override @Override

View File

@ -110,9 +110,11 @@ public class ContactsController extends BaseController implements SearchView.OnQ
public static final String TAG = "ContactsController"; public static final String TAG = "ContactsController";
private static final String KEY_SEARCH_QUERY = "ContactsController.searchQuery"; 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; public RelativeLayout initialRelativeLayout;
@Nullable @BindView(R.id.secondary_relative_layout) @Nullable
@BindView(R.id.secondary_relative_layout)
public RelativeLayout secondaryRelativeLayout; public RelativeLayout secondaryRelativeLayout;
@Inject @Inject
UserUtils userUtils; UserUtils userUtils;
@ -267,13 +269,21 @@ public class ContactsController extends BaseController implements SearchView.OnQ
@Override @Override
public void onNext(RoomOverall roomOverall) { public void onNext(RoomOverall roomOverall) {
if (getActivity() != null) { Intent conversationIntent = new Intent(getActivity(), CallActivity.class);
Intent callIntent = new Intent(getActivity(), CallActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser)); bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
callIntent.putExtras(bundle);
startActivity(callIntent); 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); new Handler().postDelayed(() -> getRouter().popCurrentController(), 100);
} }
} }
@ -414,6 +424,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) retrofitBucket.getUrl(), retrofitBucket.getQueryMap())
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.retry(3)
.subscribe((ShareesOverall shareesOverall) -> { .subscribe((ShareesOverall shareesOverall) -> {
if (shareesOverall != null) { if (shareesOverall != null) {

View File

@ -46,4 +46,5 @@ public class BundleKeys {
public static final String KEY_CONVERSATION_TYPE = "KEY_CONVERSATION_TYPE"; 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_INVITED_PARTICIPANTS = "KEY_INVITED_PARTICIPANTS";
public static final String KEY_CONVERSATION_NAME = "KEY_CONVERSATION_NAME"; public static final String KEY_CONVERSATION_NAME = "KEY_CONVERSATION_NAME";
public static final String KEY_ROOM_PASSWORD = "KEY_ROOM_PASSWORD";
} }