Fix new conversations

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-05-10 15:18:22 +02:00
parent f2aee50a74
commit 59b54d1f7b
4 changed files with 60 additions and 31 deletions

View File

@ -137,7 +137,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
/* /*
TODO: TODO:
- check push notifications - check push notifications
- new conversation handling
*/ */
public ChatController(Bundle args) { public ChatController(Bundle args) {
super(args); super(args);

View File

@ -57,7 +57,7 @@ import com.nextcloud.talk.adapters.items.UserItem;
import com.nextcloud.talk.api.NcApi; 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.controllers.bottomsheet.EntryMenuController; import com.nextcloud.talk.controllers.bottomsheet.OperationsMenuController;
import com.nextcloud.talk.events.BottomSheetLockEvent; import com.nextcloud.talk.events.BottomSheetLockEvent;
import com.nextcloud.talk.models.RetrofitBucket; import com.nextcloud.talk.models.RetrofitBucket;
import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.database.UserEntity;
@ -67,7 +67,6 @@ import com.nextcloud.talk.models.json.rooms.RoomOverall;
import com.nextcloud.talk.models.json.sharees.Sharee; import com.nextcloud.talk.models.json.sharees.Sharee;
import com.nextcloud.talk.models.json.sharees.ShareesOverall; import com.nextcloud.talk.models.json.sharees.ShareesOverall;
import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.KeyboardUtils;
import com.nextcloud.talk.utils.animations.ViewHidingBehaviourAnimation; import com.nextcloud.talk.utils.animations.ViewHidingBehaviourAnimation;
import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.database.user.UserUtils;
@ -275,9 +274,9 @@ public class ContactsController extends BaseController implements SearchView.OnQ
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser)); bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) { if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
conversationIntent.putExtras(bundle);
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, bundle.putString(BundleKeys.KEY_CONVERSATION_NAME,
roomOverall.getOcs().getData().getDisplayName()); roomOverall.getOcs().getData().getDisplayName());
conversationIntent.putExtras(bundle);
getRouter().pushController((RouterTransaction.with(new ChatController(bundle)) getRouter().pushController((RouterTransaction.with(new ChatController(bundle))
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()))); .popChangeHandler(new HorizontalChangeHandler())));
@ -657,7 +656,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
} }
getChildRouter((ViewGroup) view).setRoot( getChildRouter((ViewGroup) view).setRoot(
RouterTransaction.with(new EntryMenuController(bundle)) RouterTransaction.with(new OperationsMenuController(bundle))
.popChangeHandler(new VerticalChangeHandler()) .popChangeHandler(new VerticalChangeHandler())
.pushChangeHandler(new VerticalChangeHandler())); .pushChangeHandler(new VerticalChangeHandler()));
@ -671,7 +670,8 @@ public class ContactsController extends BaseController implements SearchView.OnQ
} }
}); });
bottomSheet.setOnShowListener(dialog -> new KeyboardUtils(getActivity(), bottomSheet.getLayout())); bottomSheet.setOnShowListener(dialog -> eventBus.post(new BottomSheetLockEvent(false, 0,
false, false)));
bottomSheet.show(); bottomSheet.show();
} }
@ -689,7 +689,9 @@ public class ContactsController extends BaseController implements SearchView.OnQ
bottomSheet.setOnCancelListener(null); bottomSheet.setOnCancelListener(null);
bottomSheet.cancel(); bottomSheet.cancel();
new Handler().postDelayed(() -> getRouter().popCurrentController(), 100); if (bottomSheetLockEvent.isDismissView()) {
new Handler().postDelayed(() -> getRouter().popCurrentController(), 100);
}
}, bottomSheetLockEvent.getDelay()); }, bottomSheetLockEvent.getDelay());
} }
} }

View File

@ -41,6 +41,7 @@ import com.nextcloud.talk.R;
import com.nextcloud.talk.activities.CallActivity; import com.nextcloud.talk.activities.CallActivity;
import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.controllers.ChatController;
import com.nextcloud.talk.controllers.base.BaseController; import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.events.BottomSheetLockEvent; import com.nextcloud.talk.events.BottomSheetLockEvent;
import com.nextcloud.talk.models.RetrofitBucket; import com.nextcloud.talk.models.RetrofitBucket;
@ -102,7 +103,7 @@ public class OperationsMenuController extends BaseController {
private int operationCode; private int operationCode;
private Room room; private Room room;
private UserEntity userEntity; private UserEntity currentUser;
private String callPassword; private String callPassword;
private String callUrl; private String callUrl;
@ -114,7 +115,6 @@ public class OperationsMenuController extends BaseController {
private Room.RoomType conversationType; private Room.RoomType conversationType;
private ArrayList<String> invitedUsers = new ArrayList<>(); private ArrayList<String> invitedUsers = new ArrayList<>();
private String conversationName;
private String credentials; private String credentials;
@ -128,7 +128,6 @@ public class OperationsMenuController extends BaseController {
this.callPassword = args.getString(BundleKeys.KEY_CALL_PASSWORD, ""); this.callPassword = args.getString(BundleKeys.KEY_CALL_PASSWORD, "");
this.callUrl = args.getString(BundleKeys.KEY_CALL_URL, ""); this.callUrl = args.getString(BundleKeys.KEY_CALL_URL, "");
this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME, "");
if (args.containsKey(BundleKeys.KEY_INVITED_PARTICIPANTS)) { if (args.containsKey(BundleKeys.KEY_INVITED_PARTICIPANTS)) {
this.invitedUsers = args.getStringArrayList(BundleKeys.KEY_INVITED_PARTICIPANTS); this.invitedUsers = args.getStringArrayList(BundleKeys.KEY_INVITED_PARTICIPANTS);
} }
@ -152,7 +151,7 @@ public class OperationsMenuController extends BaseController {
} }
private void processOperation() { private void processOperation() {
userEntity = userUtils.getCurrentUser(); currentUser = userUtils.getCurrentUser();
OperationsObserver operationsObserver = new OperationsObserver(); OperationsObserver operationsObserver = new OperationsObserver();
if (!TextUtils.isEmpty(callUrl)) { if (!TextUtils.isEmpty(callUrl)) {
@ -164,16 +163,16 @@ public class OperationsMenuController extends BaseController {
} }
} }
if (userEntity != null) { if (currentUser != null) {
credentials = ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()); credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
if (!TextUtils.isEmpty(baseUrl) && !baseUrl.equals(userEntity.getBaseUrl())) { if (!TextUtils.isEmpty(baseUrl) && !baseUrl.equals(currentUser.getBaseUrl())) {
credentials = null; credentials = null;
} }
switch (operationCode) { switch (operationCode) {
case 1: case 1:
ncApi.removeSelfFromRoom(credentials, ApiUtils.getUrlForRemoveSelfFromRoom(userEntity.getBaseUrl ncApi.removeSelfFromRoom(credentials, ApiUtils.getUrlForRemoveSelfFromRoom(currentUser.getBaseUrl
(), room.getToken())) (), room.getToken()))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -181,7 +180,7 @@ public class OperationsMenuController extends BaseController {
.subscribe(operationsObserver); .subscribe(operationsObserver);
break; break;
case 2: case 2:
ncApi.renameRoom(credentials, ApiUtils.getRoom(userEntity.getBaseUrl(), room.getToken()), ncApi.renameRoom(credentials, ApiUtils.getRoom(currentUser.getBaseUrl(), room.getToken()),
room.getName()) room.getName())
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -189,7 +188,7 @@ public class OperationsMenuController extends BaseController {
.subscribe(operationsObserver); .subscribe(operationsObserver);
break; break;
case 3: case 3:
ncApi.makeRoomPublic(credentials, ApiUtils.getUrlForRoomVisibility(userEntity.getBaseUrl(), room ncApi.makeRoomPublic(credentials, ApiUtils.getUrlForRoomVisibility(currentUser.getBaseUrl(), room
.getToken())) .getToken()))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -203,7 +202,7 @@ public class OperationsMenuController extends BaseController {
if (room.getPassword() != null) { if (room.getPassword() != null) {
pass = room.getPassword(); pass = room.getPassword();
} }
ncApi.setPassword(credentials, ApiUtils.getUrlForPassword(userEntity.getBaseUrl(), ncApi.setPassword(credentials, ApiUtils.getUrlForPassword(currentUser.getBaseUrl(),
room.getToken()), pass) room.getToken()), pass)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -214,7 +213,7 @@ public class OperationsMenuController extends BaseController {
// Operation 7 is sharing, so we handle this differently // Operation 7 is sharing, so we handle this differently
break; break;
case 8: case 8:
ncApi.makeRoomPrivate(credentials, ApiUtils.getUrlForRoomVisibility(userEntity.getBaseUrl(), room ncApi.makeRoomPrivate(credentials, ApiUtils.getUrlForRoomVisibility(currentUser.getBaseUrl(), room
.getToken())) .getToken()))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -222,7 +221,7 @@ public class OperationsMenuController extends BaseController {
.subscribe(operationsObserver); .subscribe(operationsObserver);
break; break;
case 9: case 9:
ncApi.deleteRoom(credentials, ApiUtils.getUrlForRoomParticipants(userEntity.getBaseUrl(), room.getToken())) ncApi.deleteRoom(credentials, ApiUtils.getUrlForRoomParticipants(currentUser.getBaseUrl(), room.getToken()))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.retry(1) .retry(1)
@ -261,17 +260,17 @@ public class OperationsMenuController extends BaseController {
RetrofitBucket retrofitBucket; RetrofitBucket retrofitBucket;
boolean isGroupCallWorkaround = false; boolean isGroupCallWorkaround = false;
if (conversationType.equals(Room.RoomType.ROOM_PUBLIC_CALL) || if (conversationType.equals(Room.RoomType.ROOM_PUBLIC_CALL) ||
!userEntity.hasSpreedCapabilityWithName("empty-group-room")) { !currentUser.hasSpreedCapabilityWithName("empty-group-room")) {
retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(currentUser.getBaseUrl(),
"3", null, conversationName); "3", null, null);
} else { } else {
String roomType = "2"; String roomType = "2";
if (!userEntity.hasSpreedCapabilityWithName("empty-group-room")) { if (!currentUser.hasSpreedCapabilityWithName("empty-group-room")) {
isGroupCallWorkaround = true; isGroupCallWorkaround = true;
roomType = "3"; roomType = "3";
} }
retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(currentUser.getBaseUrl(),
roomType, null, conversationName); roomType, null, null);
} }
final boolean isGroupCallWorkaroundFinal = isGroupCallWorkaround; final boolean isGroupCallWorkaroundFinal = isGroupCallWorkaround;
@ -323,7 +322,7 @@ public class OperationsMenuController extends BaseController {
} }
private void performGroupCallWorkaround(String credentials) { private void performGroupCallWorkaround(String credentials) {
ncApi.makeRoomPrivate(credentials, ApiUtils.getUrlForRoomVisibility(userEntity.getBaseUrl(), room.getToken())) ncApi.makeRoomPrivate(credentials, ApiUtils.getUrlForRoomVisibility(currentUser.getBaseUrl(), room.getToken()))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.retry(1) .retry(1)
@ -465,7 +464,7 @@ public class OperationsMenuController extends BaseController {
if (localInvitedUsers.size() > 0) { if (localInvitedUsers.size() > 0) {
for (int i = 0; i < invitedUsers.size(); i++) { for (int i = 0; i < invitedUsers.size(); i++) {
final String userId = invitedUsers.get(i); final String userId = invitedUsers.get(i);
retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(userEntity.getBaseUrl(), room.getToken(), retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(currentUser.getBaseUrl(), room.getToken(),
userId); userId);
ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap())
@ -495,7 +494,24 @@ public class OperationsMenuController extends BaseController {
} }
if (localInvitedUsers.size() == 0) { if (localInvitedUsers.size() == 0) {
initiateCall(); if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
eventBus.post(new BottomSheetLockEvent(true, 0,
true, true, false));
Intent conversationIntent = new Intent(getActivity(), CallActivity.class);
Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken());
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, room.getDisplayName());
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
conversationIntent.putExtras(bundle);
getParentController().getRouter().pushController((RouterTransaction.with(
new ChatController(bundle)).pushChangeHandler(
new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler())));
} else {
initiateCall();
}
} }
dispose(); dispose();
} }
@ -510,8 +526,8 @@ public class OperationsMenuController extends BaseController {
eventBus.post(new BottomSheetLockEvent(true, 0, true, true)); eventBus.post(new BottomSheetLockEvent(true, 0, true, true));
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken());
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(userEntity)); bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
if (baseUrl != null && !baseUrl.equals(userEntity.getBaseUrl())) { if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) {
bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl); bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl);
} }
bundle.putString(BundleKeys.KEY_CALL_SESSION, callSession); bundle.putString(BundleKeys.KEY_CALL_SESSION, callSession);

View File

@ -28,11 +28,23 @@ public class BottomSheetLockEvent {
private final int delay; private final int delay;
private final boolean shouldRefreshData; private final boolean shouldRefreshData;
private final boolean cancel; private final boolean cancel;
private boolean dismissView;
public BottomSheetLockEvent(boolean cancelable, int delay, boolean shouldRefreshData, boolean cancel) { public BottomSheetLockEvent(boolean cancelable, int delay, boolean shouldRefreshData, boolean cancel) {
this.cancelable = cancelable; this.cancelable = cancelable;
this.delay = delay; this.delay = delay;
this.shouldRefreshData = shouldRefreshData; this.shouldRefreshData = shouldRefreshData;
this.cancel = cancel; this.cancel = cancel;
this.dismissView = true;
} }
public BottomSheetLockEvent(boolean cancelable, int delay, boolean shouldRefreshData, boolean cancel, boolean
dismissView) {
this.cancelable = cancelable;
this.delay = delay;
this.shouldRefreshData = shouldRefreshData;
this.cancel = cancel;
this.dismissView = dismissView;
}
} }