mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-23 13:35:33 +03:00
Fix delete in conversation info
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
e936bf7479
commit
649df4ef07
4 changed files with 93 additions and 8 deletions
|
@ -410,7 +410,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
||||||
private void showConversationInfoScreen() {
|
private void showConversationInfoScreen() {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser);
|
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser);
|
||||||
bundle.putString(BundleKeys.KEY_BASE_URL, conversationUser.getBaseUrl());
|
|
||||||
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
|
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
|
||||||
getRouter().pushController((RouterTransaction.with(new ConversationInfoController(bundle))
|
getRouter().pushController((RouterTransaction.with(new ConversationInfoController(bundle))
|
||||||
.pushChangeHandler(new HorizontalChangeHandler())
|
.pushChangeHandler(new HorizontalChangeHandler())
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
package com.nextcloud.talk.controllers;
|
package com.nextcloud.talk.controllers;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
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.bundle.BundleKeys;
|
||||||
import com.nextcloud.talk.utils.preferencestorage.DatabaseStorageModule;
|
import com.nextcloud.talk.utils.preferencestorage.DatabaseStorageModule;
|
||||||
import com.vanniktech.emoji.EmojiTextView;
|
import com.vanniktech.emoji.EmojiTextView;
|
||||||
|
import com.yarolegovich.lovelydialog.LovelySaveStateHandler;
|
||||||
|
import com.yarolegovich.lovelydialog.LovelyStandardDialog;
|
||||||
import com.yarolegovich.mp.MaterialChoicePreference;
|
import com.yarolegovich.mp.MaterialChoicePreference;
|
||||||
import com.yarolegovich.mp.MaterialPreferenceCategory;
|
import com.yarolegovich.mp.MaterialPreferenceCategory;
|
||||||
import com.yarolegovich.mp.MaterialPreferenceScreen;
|
import com.yarolegovich.mp.MaterialPreferenceScreen;
|
||||||
|
@ -79,6 +82,8 @@ import java.util.List;
|
||||||
@AutoInjector(NextcloudTalkApplication.class)
|
@AutoInjector(NextcloudTalkApplication.class)
|
||||||
public class ConversationInfoController extends BaseController {
|
public class ConversationInfoController extends BaseController {
|
||||||
|
|
||||||
|
private static final int ID_DELETE_CONVERSATION_DIALOG = 0;
|
||||||
|
|
||||||
@BindView(R.id.notification_settings)
|
@BindView(R.id.notification_settings)
|
||||||
MaterialPreferenceScreen materialPreferenceScreen;
|
MaterialPreferenceScreen materialPreferenceScreen;
|
||||||
@BindView(R.id.progressBar)
|
@BindView(R.id.progressBar)
|
||||||
|
@ -104,7 +109,9 @@ public class ConversationInfoController extends BaseController {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
NcApi ncApi;
|
NcApi ncApi;
|
||||||
private String baseUrl;
|
@Inject
|
||||||
|
Context context;
|
||||||
|
|
||||||
private String conversationToken;
|
private String conversationToken;
|
||||||
private UserEntity conversationUser;
|
private UserEntity conversationUser;
|
||||||
private String credentials;
|
private String credentials;
|
||||||
|
@ -116,13 +123,14 @@ public class ConversationInfoController extends BaseController {
|
||||||
private FlexibleAdapter<AbstractFlexibleItem> adapter;
|
private FlexibleAdapter<AbstractFlexibleItem> adapter;
|
||||||
private List<AbstractFlexibleItem> recyclerViewItems = new ArrayList<>();
|
private List<AbstractFlexibleItem> recyclerViewItems = new ArrayList<>();
|
||||||
|
|
||||||
|
private LovelySaveStateHandler saveStateHandler;
|
||||||
|
|
||||||
public ConversationInfoController(Bundle args) {
|
public ConversationInfoController(Bundle args) {
|
||||||
super(args);
|
super(args);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
||||||
conversationUser = args.getParcelable(BundleKeys.KEY_USER_ENTITY);
|
conversationUser = args.getParcelable(BundleKeys.KEY_USER_ENTITY);
|
||||||
conversationToken = args.getString(BundleKeys.KEY_ROOM_TOKEN);
|
conversationToken = args.getString(BundleKeys.KEY_ROOM_TOKEN);
|
||||||
baseUrl = args.getString(BundleKeys.KEY_BASE_URL);
|
|
||||||
credentials = ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken());
|
credentials = ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,6 +153,11 @@ public class ConversationInfoController extends BaseController {
|
||||||
@Override
|
@Override
|
||||||
protected void onViewBound(@NonNull View view) {
|
protected void onViewBound(@NonNull View view) {
|
||||||
super.onViewBound(view);
|
super.onViewBound(view);
|
||||||
|
|
||||||
|
if (saveStateHandler == null) {
|
||||||
|
saveStateHandler = new LovelySaveStateHandler();
|
||||||
|
}
|
||||||
|
|
||||||
materialPreferenceScreen.setStorageModule(new DatabaseStorageModule(conversationUser, conversationToken));
|
materialPreferenceScreen.setStorageModule(new DatabaseStorageModule(conversationUser, conversationToken));
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
fetchRoomInfo();
|
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() {
|
private void setupAdapter() {
|
||||||
Activity activity;
|
Activity activity;
|
||||||
|
|
||||||
|
@ -254,8 +316,7 @@ public class ConversationInfoController extends BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.deleteConversationAction)
|
private void deleteConversation() {
|
||||||
void deleteConversation() {
|
|
||||||
Data data;
|
Data data;
|
||||||
if ((data = getWorkerData()) != null) {
|
if ((data = getWorkerData()) != null) {
|
||||||
OneTimeWorkRequest deleteConversationWorker =
|
OneTimeWorkRequest deleteConversationWorker =
|
||||||
|
@ -265,6 +326,11 @@ public class ConversationInfoController extends BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.deleteConversationAction)
|
||||||
|
void deleteConversationClick() {
|
||||||
|
showDeleteConversationDialog(null);
|
||||||
|
}
|
||||||
|
|
||||||
private Data getWorkerData() {
|
private Data getWorkerData() {
|
||||||
if (!TextUtils.isEmpty(conversationToken) && conversationUser != null) {
|
if (!TextUtils.isEmpty(conversationToken) && conversationUser != null) {
|
||||||
Data.Builder data = new Data.Builder();
|
Data.Builder data = new Data.Builder();
|
||||||
|
@ -278,9 +344,8 @@ public class ConversationInfoController extends BaseController {
|
||||||
|
|
||||||
private void popTwoLastControllers() {
|
private void popTwoLastControllers() {
|
||||||
List<RouterTransaction> backstack = getRouter().getBackstack();
|
List<RouterTransaction> backstack = getRouter().getBackstack();
|
||||||
backstack.remove(backstack.size() - 2);
|
backstack = backstack.subList(0, backstack.size() - 2);
|
||||||
getRouter().setBackstack(backstack, new HorizontalChangeHandler());
|
getRouter().setBackstack(backstack, new HorizontalChangeHandler());
|
||||||
getRouter().popCurrentController();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchRoomInfo() {
|
private void fetchRoomInfo() {
|
||||||
|
|
|
@ -20,8 +20,11 @@
|
||||||
*/
|
*/
|
||||||
package com.nextcloud.talk.models.json.rooms;
|
package com.nextcloud.talk.models.json.rooms;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
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.chat.ChatMessage;
|
||||||
import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter;
|
import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter;
|
||||||
import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter;
|
import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter;
|
||||||
|
@ -97,10 +100,22 @@ public class Conversation {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canLeave() {
|
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 {
|
public enum NotificationLevel {
|
||||||
DEFAULT,
|
DEFAULT,
|
||||||
ALWAYS,
|
ALWAYS,
|
||||||
|
|
|
@ -145,6 +145,12 @@
|
||||||
<string name="nc_make_call_public">Make conversation public</string>
|
<string name="nc_make_call_public">Make conversation public</string>
|
||||||
<string name="nc_make_call_private">Make conversation private</string>
|
<string name="nc_make_call_private">Make conversation private</string>
|
||||||
<string name="nc_delete_call">Delete conversation</string>
|
<string name="nc_delete_call">Delete conversation</string>
|
||||||
|
<string name="nc_delete">Delete</string>
|
||||||
|
<string name="nc_delete_conversation_default">Please confirm your intent to remove the conversation.</string>
|
||||||
|
<string name="nc_delete_conversation_one2one">If you delete the conversation, it will also be
|
||||||
|
deleted for %1$s.</string>
|
||||||
|
<string name="nc_delete_conversation_more">If you delete the conversation, it will also be deleted for all other participants.</string>
|
||||||
|
|
||||||
<string name="nc_new_conversation">New conversation</string>
|
<string name="nc_new_conversation">New conversation</string>
|
||||||
<string name="nc_join_via_link">Join via link</string>
|
<string name="nc_join_via_link">Join via link</string>
|
||||||
<string name="nc_join_via_web">Join via web</string>
|
<string name="nc_join_via_web">Join via web</string>
|
||||||
|
|
Loading…
Reference in a new issue