From 8ea9663d5e98b2aae358c2e039af29d2973142f4 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Mon, 14 Feb 2022 18:48:52 +0100 Subject: [PATCH] fix to fetch conversations list after executing bottom sheet operations BottomSheetLockEvent was only used for old bottom dialog with "kennyc" lib instead ConversationsListFetchDataEvent.kt is now used to fetch the data in ConversationsListController whenever needed Signed-off-by: Marcel Hibbe --- .../ConversationsListController.java | 6 + .../bottomsheet/EntryMenuController.java | 6 - .../bottomsheet/OperationsMenuController.java | 18 +-- .../talk/events/BottomSheetLockEvent.java | 116 ------------------ .../events/ConversationsListFetchDataEvent.kt | 23 ++++ 5 files changed, 34 insertions(+), 135 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/events/BottomSheetLockEvent.java create mode 100644 app/src/main/java/com/nextcloud/talk/events/ConversationsListFetchDataEvent.kt diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java index ec9ff0da3..160489447 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java @@ -72,6 +72,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.controllers.base.BaseController; import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum; import com.nextcloud.talk.controllers.bottomsheet.EntryMenuController; +import com.nextcloud.talk.events.ConversationsListFetchDataEvent; import com.nextcloud.talk.events.EventStatus; import com.nextcloud.talk.interfaces.ConversationMenuInterface; import com.nextcloud.talk.jobs.AccountRemovalWorker; @@ -1063,6 +1064,11 @@ public class ConversationsListController extends BaseController implements Searc } } + @Subscribe(threadMode = ThreadMode.BACKGROUND) + public void onMessageEvent(ConversationsListFetchDataEvent conversationsListFetchDataEvent) { + fetchData(); + } + private void showDeleteConversationDialog(Bundle savedInstanceState) { if (getActivity() != null && conversationMenuBundle != null && currentUser != null && conversationMenuBundle.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID()) == currentUser.getId()) { diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.java b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.java index 97d6020ae..041ec7525 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.java @@ -41,7 +41,6 @@ import com.google.android.material.textfield.TextInputLayout; import com.nextcloud.talk.R; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.controllers.base.BaseController; -import com.nextcloud.talk.events.BottomSheetLockEvent; import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.utils.EmojiTextInputEditText; import com.nextcloud.talk.utils.ShareUtils; @@ -144,7 +143,6 @@ public class EntryMenuController extends BaseController { public void onProceedButtonClick() { Bundle bundle; if (operation == ConversationOperationEnum.JOIN_ROOM) { - eventBus.post(new BottomSheetLockEvent(false, 0, false, false)); bundle = new Bundle(); bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation)); bundle.putString(BundleKeys.INSTANCE.getKEY_CALL_URL(), callUrl); @@ -158,7 +156,6 @@ public class EntryMenuController extends BaseController { .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); } else if (operation != ConversationOperationEnum.SHARE_LINK && operation != ConversationOperationEnum.GET_JOIN_ROOM && operation != ConversationOperationEnum.INVITE_USERS) { - eventBus.post(new BottomSheetLockEvent(false, 0, false, false)); bundle = new Bundle(); if (operation == ConversationOperationEnum.CHANGE_PASSWORD || operation == ConversationOperationEnum.SET_PASSWORD) { conversation.setPassword(editText.getText().toString()); @@ -178,10 +175,8 @@ public class EntryMenuController extends BaseController { intent.setComponent(new ComponentName(packageName, name)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getActivity().startActivity(intent); - eventBus.post(new BottomSheetLockEvent(true, 0, false, true)); } } else if (operation != ConversationOperationEnum.INVITE_USERS) { - eventBus.post(new BottomSheetLockEvent(false, 0, false, false)); bundle = new Bundle(); bundle.putSerializable(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), operation); bundle.putString(BundleKeys.INSTANCE.getKEY_CALL_URL(), editText.getText().toString()); @@ -190,7 +185,6 @@ public class EntryMenuController extends BaseController { .popChangeHandler(new HorizontalChangeHandler())); } else if (operation == ConversationOperationEnum.INVITE_USERS) { - eventBus.post(new BottomSheetLockEvent(false, 0, false, false)); originalBundle.putString(BundleKeys.INSTANCE.getKEY_CONVERSATION_NAME(), editText.getText().toString()); getRouter().pushController(RouterTransaction.with(new OperationsMenuController(originalBundle)) .pushChangeHandler(new HorizontalChangeHandler()) 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 faf8f78f6..ecec5116a 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,7 +41,7 @@ import com.nextcloud.talk.R; import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.controllers.base.BaseController; -import com.nextcloud.talk.events.BottomSheetLockEvent; +import com.nextcloud.talk.events.ConversationsListFetchDataEvent; import com.nextcloud.talk.events.OpenConversationEvent; import com.nextcloud.talk.models.RetrofitBucket; import com.nextcloud.talk.models.database.CapabilitiesUtil; @@ -337,8 +337,7 @@ public class OperationsMenuController extends BaseController { public void onNext(@io.reactivex.annotations.NonNull RoomOverall roomOverall) { conversation = roomOverall.getOcs().getData(); if (conversation.isHasPassword() && conversation.isGuest()) { - eventBus.post(new BottomSheetLockEvent(true, 0, - true, false)); + eventBus.post(new ConversationsListFetchDataEvent()); Bundle bundle = new Bundle(); bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation)); bundle.putString(BundleKeys.INSTANCE.getKEY_CALL_URL(), callUrl); @@ -553,10 +552,8 @@ public class OperationsMenuController extends BaseController { } else { resultsTextView.setText(R.string.nc_failed_signaling_settings); webButton.setOnClickListener(v -> { - eventBus.post(new BottomSheetLockEvent(true, 0, false, true)); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(callUrl)); startActivity(browserIntent); - new BottomSheetLockEvent(true, 0, false, true); }); webButton.setVisibility(View.VISIBLE); } @@ -564,13 +561,11 @@ public class OperationsMenuController extends BaseController { resultsTextView.setVisibility(View.VISIBLE); if (everythingOK) { - eventBus.post(new BottomSheetLockEvent(true, 2500, true, true)); + eventBus.post(new ConversationsListFetchDataEvent()); } else { resultImageView.setImageDrawable(DisplayUtils.getTintedDrawable(getResources(), R.drawable .ic_cancel_black_24dp, R.color.nc_darkRed)); - okButton.setOnClickListener(v -> eventBus.post(new BottomSheetLockEvent(true, 0, - operation != ConversationOperationEnum.JOIN_ROOM - && operation != ConversationOperationEnum.GET_JOIN_ROOM, true))); + okButton.setOnClickListener(v -> eventBus.post(new ConversationsListFetchDataEvent())); okButton.setVisibility(View.VISIBLE); } } @@ -721,8 +716,7 @@ public class OperationsMenuController extends BaseController { } private void initiateConversation(boolean dismissView) { - eventBus.post(new BottomSheetLockEvent(true, 0, - true, true, dismissView)); + eventBus.post(new ConversationsListFetchDataEvent()); Bundle bundle = new Bundle(); bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), conversation.getToken()); @@ -741,8 +735,6 @@ public class OperationsMenuController extends BaseController { } else { Response response = ((HttpException) e).response(); if (response != null && response.code() == 403) { - eventBus.post(new BottomSheetLockEvent(true, 0, false, - false)); ApplicationWideMessageHolder.getInstance().setMessageType(ApplicationWideMessageHolder.MessageType.CALL_PASSWORD_WRONG); getRouter().popCurrentController(); } else { diff --git a/app/src/main/java/com/nextcloud/talk/events/BottomSheetLockEvent.java b/app/src/main/java/com/nextcloud/talk/events/BottomSheetLockEvent.java deleted file mode 100644 index b9c61e487..000000000 --- a/app/src/main/java/com/nextcloud/talk/events/BottomSheetLockEvent.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.events; - -public class BottomSheetLockEvent { - private final boolean cancelable; - 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; - } - - public boolean isCancelable() { - return this.cancelable; - } - - public int getDelay() { - return this.delay; - } - - public boolean isShouldRefreshData() { - return this.shouldRefreshData; - } - - public boolean isCancel() { - return this.cancel; - } - - public boolean isDismissView() { - return this.dismissView; - } - - public void setDismissView(boolean dismissView) { - this.dismissView = dismissView; - } - - public boolean equals(final Object o) { - if (o == this) { - return true; - } - if (!(o instanceof BottomSheetLockEvent)) { - return false; - } - final BottomSheetLockEvent other = (BottomSheetLockEvent) o; - if (!other.canEqual((Object) this)) { - return false; - } - if (this.isCancelable() != other.isCancelable()) { - return false; - } - if (this.getDelay() != other.getDelay()) { - return false; - } - if (this.isShouldRefreshData() != other.isShouldRefreshData()) { - return false; - } - if (this.isCancel() != other.isCancel()) { - return false; - } - - return this.isDismissView() == other.isDismissView(); - } - - protected boolean canEqual(final Object other) { - return other instanceof BottomSheetLockEvent; - } - - public int hashCode() { - final int PRIME = 59; - int result = 1; - result = result * PRIME + (this.isCancelable() ? 79 : 97); - result = result * PRIME + this.getDelay(); - result = result * PRIME + (this.isShouldRefreshData() ? 79 : 97); - result = result * PRIME + (this.isCancel() ? 79 : 97); - result = result * PRIME + (this.isDismissView() ? 79 : 97); - return result; - } - - public String toString() { - return "BottomSheetLockEvent(cancelable=" + this.isCancelable() + ", delay=" + this.getDelay() + ", shouldRefreshData=" + this.isShouldRefreshData() + ", cancel=" + this.isCancel() + ", dismissView=" + this.isDismissView() + ")"; - } -} diff --git a/app/src/main/java/com/nextcloud/talk/events/ConversationsListFetchDataEvent.kt b/app/src/main/java/com/nextcloud/talk/events/ConversationsListFetchDataEvent.kt new file mode 100644 index 000000000..867b10338 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/events/ConversationsListFetchDataEvent.kt @@ -0,0 +1,23 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2019 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.events + +class ConversationsListFetchDataEvent