From 59b54d1f7b11ce1f0b3f9e87f918f8a407a42549 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 10 May 2018 15:18:22 +0200 Subject: [PATCH] Fix new conversations Signed-off-by: Mario Danic --- .../talk/controllers/ChatController.java | 1 - .../talk/controllers/ContactsController.java | 14 ++-- .../bottomsheet/OperationsMenuController.java | 64 ++++++++++++------- .../talk/events/BottomSheetLockEvent.java | 12 ++++ 4 files changed, 60 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java index 25d3626b0..d3e53e950 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java @@ -137,7 +137,6 @@ public class ChatController extends BaseController implements MessagesListAdapte /* TODO: - check push notifications - - new conversation handling */ public ChatController(Bundle args) { super(args); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java index 6518253ba..8266b45a5 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java @@ -57,7 +57,7 @@ import com.nextcloud.talk.adapters.items.UserItem; import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.application.NextcloudTalkApplication; 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.models.RetrofitBucket; 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.ShareesOverall; import com.nextcloud.talk.utils.ApiUtils; -import com.nextcloud.talk.utils.KeyboardUtils; import com.nextcloud.talk.utils.animations.ViewHidingBehaviourAnimation; import com.nextcloud.talk.utils.bundle.BundleKeys; 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)); if (currentUser.hasSpreedCapabilityWithName("chat-v2")) { - conversationIntent.putExtras(bundle); bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, roomOverall.getOcs().getData().getDisplayName()); + conversationIntent.putExtras(bundle); getRouter().pushController((RouterTransaction.with(new ChatController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler()))); @@ -657,7 +656,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ } getChildRouter((ViewGroup) view).setRoot( - RouterTransaction.with(new EntryMenuController(bundle)) + RouterTransaction.with(new OperationsMenuController(bundle)) .popChangeHandler(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(); } @@ -689,7 +689,9 @@ public class ContactsController extends BaseController implements SearchView.OnQ bottomSheet.setOnCancelListener(null); bottomSheet.cancel(); - new Handler().postDelayed(() -> getRouter().popCurrentController(), 100); + if (bottomSheetLockEvent.isDismissView()) { + new Handler().postDelayed(() -> getRouter().popCurrentController(), 100); + } }, bottomSheetLockEvent.getDelay()); } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java index a0a98e6c5..c46afa2e9 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java @@ -41,6 +41,7 @@ import com.nextcloud.talk.R; import com.nextcloud.talk.activities.CallActivity; import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.controllers.ChatController; import com.nextcloud.talk.controllers.base.BaseController; import com.nextcloud.talk.events.BottomSheetLockEvent; import com.nextcloud.talk.models.RetrofitBucket; @@ -102,7 +103,7 @@ public class OperationsMenuController extends BaseController { private int operationCode; private Room room; - private UserEntity userEntity; + private UserEntity currentUser; private String callPassword; private String callUrl; @@ -114,7 +115,6 @@ public class OperationsMenuController extends BaseController { private Room.RoomType conversationType; private ArrayList invitedUsers = new ArrayList<>(); - private String conversationName; private String credentials; @@ -128,7 +128,6 @@ public class OperationsMenuController extends BaseController { this.callPassword = args.getString(BundleKeys.KEY_CALL_PASSWORD, ""); this.callUrl = args.getString(BundleKeys.KEY_CALL_URL, ""); - this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME, ""); if (args.containsKey(BundleKeys.KEY_INVITED_PARTICIPANTS)) { this.invitedUsers = args.getStringArrayList(BundleKeys.KEY_INVITED_PARTICIPANTS); } @@ -152,7 +151,7 @@ public class OperationsMenuController extends BaseController { } private void processOperation() { - userEntity = userUtils.getCurrentUser(); + currentUser = userUtils.getCurrentUser(); OperationsObserver operationsObserver = new OperationsObserver(); if (!TextUtils.isEmpty(callUrl)) { @@ -164,16 +163,16 @@ public class OperationsMenuController extends BaseController { } } - if (userEntity != null) { - credentials = ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()); + if (currentUser != null) { + 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; } switch (operationCode) { case 1: - ncApi.removeSelfFromRoom(credentials, ApiUtils.getUrlForRemoveSelfFromRoom(userEntity.getBaseUrl + ncApi.removeSelfFromRoom(credentials, ApiUtils.getUrlForRemoveSelfFromRoom(currentUser.getBaseUrl (), room.getToken())) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -181,7 +180,7 @@ public class OperationsMenuController extends BaseController { .subscribe(operationsObserver); break; case 2: - ncApi.renameRoom(credentials, ApiUtils.getRoom(userEntity.getBaseUrl(), room.getToken()), + ncApi.renameRoom(credentials, ApiUtils.getRoom(currentUser.getBaseUrl(), room.getToken()), room.getName()) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -189,7 +188,7 @@ public class OperationsMenuController extends BaseController { .subscribe(operationsObserver); break; case 3: - ncApi.makeRoomPublic(credentials, ApiUtils.getUrlForRoomVisibility(userEntity.getBaseUrl(), room + ncApi.makeRoomPublic(credentials, ApiUtils.getUrlForRoomVisibility(currentUser.getBaseUrl(), room .getToken())) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -203,7 +202,7 @@ public class OperationsMenuController extends BaseController { if (room.getPassword() != null) { pass = room.getPassword(); } - ncApi.setPassword(credentials, ApiUtils.getUrlForPassword(userEntity.getBaseUrl(), + ncApi.setPassword(credentials, ApiUtils.getUrlForPassword(currentUser.getBaseUrl(), room.getToken()), pass) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -214,7 +213,7 @@ public class OperationsMenuController extends BaseController { // Operation 7 is sharing, so we handle this differently break; case 8: - ncApi.makeRoomPrivate(credentials, ApiUtils.getUrlForRoomVisibility(userEntity.getBaseUrl(), room + ncApi.makeRoomPrivate(credentials, ApiUtils.getUrlForRoomVisibility(currentUser.getBaseUrl(), room .getToken())) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -222,7 +221,7 @@ public class OperationsMenuController extends BaseController { .subscribe(operationsObserver); break; case 9: - ncApi.deleteRoom(credentials, ApiUtils.getUrlForRoomParticipants(userEntity.getBaseUrl(), room.getToken())) + ncApi.deleteRoom(credentials, ApiUtils.getUrlForRoomParticipants(currentUser.getBaseUrl(), room.getToken())) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .retry(1) @@ -261,17 +260,17 @@ public class OperationsMenuController extends BaseController { RetrofitBucket retrofitBucket; boolean isGroupCallWorkaround = false; if (conversationType.equals(Room.RoomType.ROOM_PUBLIC_CALL) || - !userEntity.hasSpreedCapabilityWithName("empty-group-room")) { - retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), - "3", null, conversationName); + !currentUser.hasSpreedCapabilityWithName("empty-group-room")) { + retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(currentUser.getBaseUrl(), + "3", null, null); } else { String roomType = "2"; - if (!userEntity.hasSpreedCapabilityWithName("empty-group-room")) { + if (!currentUser.hasSpreedCapabilityWithName("empty-group-room")) { isGroupCallWorkaround = true; roomType = "3"; } - retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), - roomType, null, conversationName); + retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(currentUser.getBaseUrl(), + roomType, null, null); } final boolean isGroupCallWorkaroundFinal = isGroupCallWorkaround; @@ -323,7 +322,7 @@ public class OperationsMenuController extends BaseController { } 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()) .observeOn(AndroidSchedulers.mainThread()) .retry(1) @@ -465,7 +464,7 @@ public class OperationsMenuController extends BaseController { if (localInvitedUsers.size() > 0) { for (int i = 0; i < invitedUsers.size(); i++) { final String userId = invitedUsers.get(i); - retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(userEntity.getBaseUrl(), room.getToken(), + retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(currentUser.getBaseUrl(), room.getToken(), userId); ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) @@ -495,7 +494,24 @@ public class OperationsMenuController extends BaseController { } 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(); } @@ -510,8 +526,8 @@ public class OperationsMenuController extends BaseController { eventBus.post(new BottomSheetLockEvent(true, 0, true, true)); Bundle bundle = new Bundle(); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken()); - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(userEntity)); - if (baseUrl != null && !baseUrl.equals(userEntity.getBaseUrl())) { + bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser)); + if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) { bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl); } bundle.putString(BundleKeys.KEY_CALL_SESSION, callSession); diff --git a/app/src/main/java/com/nextcloud/talk/events/BottomSheetLockEvent.java b/app/src/main/java/com/nextcloud/talk/events/BottomSheetLockEvent.java index 113f22c6f..299cb02f6 100644 --- a/app/src/main/java/com/nextcloud/talk/events/BottomSheetLockEvent.java +++ b/app/src/main/java/com/nextcloud/talk/events/BottomSheetLockEvent.java @@ -28,11 +28,23 @@ public class BottomSheetLockEvent { private final int delay; private final boolean shouldRefreshData; private final boolean cancel; + private boolean dismissView; public BottomSheetLockEvent(boolean cancelable, int delay, boolean shouldRefreshData, boolean cancel) { this.cancelable = cancelable; this.delay = delay; this.shouldRefreshData = shouldRefreshData; 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; + } + }