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 3c69d5787..20d53d849 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java @@ -410,7 +410,6 @@ public class ChatController extends BaseController implements MessagesListAdapte private void showConversationInfoScreen() { Bundle bundle = new Bundle(); bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser); - bundle.putString(BundleKeys.KEY_BASE_URL, conversationUser.getBaseUrl()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken); getRouter().pushController((RouterTransaction.with(new ConversationInfoController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java index f3df4f0dd..e521945e7 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java @@ -21,6 +21,7 @@ package com.nextcloud.talk.controllers; import android.app.Activity; +import android.content.Context; import android.os.Bundle; import android.text.TextUtils; import android.view.LayoutInflater; @@ -59,6 +60,8 @@ import com.nextcloud.talk.utils.DisplayUtils; import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.preferencestorage.DatabaseStorageModule; import com.vanniktech.emoji.EmojiTextView; +import com.yarolegovich.lovelydialog.LovelySaveStateHandler; +import com.yarolegovich.lovelydialog.LovelyStandardDialog; import com.yarolegovich.mp.MaterialChoicePreference; import com.yarolegovich.mp.MaterialPreferenceCategory; import com.yarolegovich.mp.MaterialPreferenceScreen; @@ -79,6 +82,8 @@ import java.util.List; @AutoInjector(NextcloudTalkApplication.class) public class ConversationInfoController extends BaseController { + private static final int ID_DELETE_CONVERSATION_DIALOG = 0; + @BindView(R.id.notification_settings) MaterialPreferenceScreen materialPreferenceScreen; @BindView(R.id.progressBar) @@ -104,7 +109,9 @@ public class ConversationInfoController extends BaseController { @Inject NcApi ncApi; - private String baseUrl; + @Inject + Context context; + private String conversationToken; private UserEntity conversationUser; private String credentials; @@ -116,13 +123,14 @@ public class ConversationInfoController extends BaseController { private FlexibleAdapter adapter; private List recyclerViewItems = new ArrayList<>(); + private LovelySaveStateHandler saveStateHandler; + public ConversationInfoController(Bundle args) { super(args); setHasOptionsMenu(true); NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); conversationUser = args.getParcelable(BundleKeys.KEY_USER_ENTITY); conversationToken = args.getString(BundleKeys.KEY_ROOM_TOKEN); - baseUrl = args.getString(BundleKeys.KEY_BASE_URL); credentials = ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()); } @@ -145,6 +153,11 @@ public class ConversationInfoController extends BaseController { @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); + + if (saveStateHandler == null) { + saveStateHandler = new LovelySaveStateHandler(); + } + materialPreferenceScreen.setStorageModule(new DatabaseStorageModule(conversationUser, conversationToken)); if (adapter == null) { fetchRoomInfo(); @@ -159,6 +172,55 @@ public class ConversationInfoController extends BaseController { } } + private void showLovelyDialog(int dialogId, Bundle savedInstanceState) { + switch (dialogId) { + case ID_DELETE_CONVERSATION_DIALOG: + showDeleteConversationDialog(savedInstanceState); + break; + default: + break; + } + } + + + private void showDeleteConversationDialog(Bundle savedInstanceState) { + if (getActivity() != null) { + new LovelyStandardDialog(getActivity(), LovelyStandardDialog.ButtonLayout.HORIZONTAL) + .setTopColorRes(R.color.nc_darkRed) + .setIcon(DisplayUtils.getTintedDrawable(context.getResources(), + R.drawable.ic_delete_black_24dp, R.color.white)) + .setPositiveButtonColor(context.getResources().getColor(R.color.nc_darkRed)) + .setTitle(R.string.nc_delete_call) + .setMessage(conversation.getDeleteWarningMessage()) + .setPositiveButton(R.string.nc_delete, new View.OnClickListener() { + @Override + public void onClick(View v) { + deleteConversation(); + } + }) + .setNegativeButton(R.string.nc_cancel, null) + .setInstanceStateHandler(ID_DELETE_CONVERSATION_DIALOG, saveStateHandler) + .setSavedInstanceState(savedInstanceState) + .show(); + } + } + + @Override + protected void onSaveViewState(@NonNull View view, @NonNull Bundle outState) { + saveStateHandler.saveInstanceState(outState); + super.onSaveViewState(view, outState); + } + + @Override + protected void onRestoreViewState(@NonNull View view, @NonNull Bundle savedViewState) { + super.onRestoreViewState(view, savedViewState); + if (LovelySaveStateHandler.wasDialogOnScreen(savedViewState)) { + //Dialog won't be restarted automatically, so we need to call this method. + //Each dialog knows how to restore its state + showLovelyDialog(LovelySaveStateHandler.getSavedDialogId(savedViewState), savedViewState); + } + } + private void setupAdapter() { Activity activity; @@ -254,8 +316,7 @@ public class ConversationInfoController extends BaseController { } } - @OnClick(R.id.deleteConversationAction) - void deleteConversation() { + private void deleteConversation() { Data data; if ((data = getWorkerData()) != null) { OneTimeWorkRequest deleteConversationWorker = @@ -265,6 +326,11 @@ public class ConversationInfoController extends BaseController { } } + @OnClick(R.id.deleteConversationAction) + void deleteConversationClick() { + showDeleteConversationDialog(null); + } + private Data getWorkerData() { if (!TextUtils.isEmpty(conversationToken) && conversationUser != null) { Data.Builder data = new Data.Builder(); @@ -278,9 +344,8 @@ public class ConversationInfoController extends BaseController { private void popTwoLastControllers() { List backstack = getRouter().getBackstack(); - backstack.remove(backstack.size() - 2); + backstack = backstack.subList(0, backstack.size() - 2); getRouter().setBackstack(backstack, new HorizontalChangeHandler()); - getRouter().popCurrentController(); } private void fetchRoomInfo() { diff --git a/app/src/main/java/com/nextcloud/talk/models/json/rooms/Conversation.java b/app/src/main/java/com/nextcloud/talk/models/json/rooms/Conversation.java index ae3562289..04e2f8ea2 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/rooms/Conversation.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/rooms/Conversation.java @@ -20,8 +20,11 @@ */ package com.nextcloud.talk.models.json.rooms; +import android.content.res.Resources; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.R; +import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.models.json.chat.ChatMessage; import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter; import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter; @@ -97,10 +100,22 @@ public class Conversation { } public boolean canLeave() { - return !canModerate() || (getType() != ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL && getCount() > 1); + return !canModerate() || (getType() != ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL && getParticipants().size() > 1); } + public String getDeleteWarningMessage() { + Resources resources = NextcloudTalkApplication.getSharedApplication().getResources(); + if (getType() == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) { + return String.format(resources.getString(R.string.nc_delete_conversation_one2one), + getDisplayName()); + } else if (getParticipants().size() > 1) { + return resources.getString(R.string.nc_delete_conversation_more); + } + + return resources.getString(R.string.nc_delete_conversation_default); + } + public enum NotificationLevel { DEFAULT, ALWAYS, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 79922453d..660a66048 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -145,6 +145,12 @@ Make conversation public Make conversation private Delete conversation + Delete + Please confirm your intent to remove the conversation. + If you delete the conversation, it will also be + deleted for %1$s. + If you delete the conversation, it will also be deleted for all other participants. + New conversation Join via link Join via web