From c13b01da33ebaf21801bd0847782b48d6593aa38 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 15 Aug 2022 20:37:11 +0200 Subject: [PATCH 1/2] remove remaining traces of lovelyDialog from settings controller Signed-off-by: Andy Scherzinger --- .../talk/controllers/SettingsController.kt | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.kt b/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.kt index f903aab9c..2ba2cebbc 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.kt @@ -91,7 +91,6 @@ import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.preferences.MagicUserInputModule import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder -import com.yarolegovich.lovelydialog.LovelySaveStateHandler import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -364,12 +363,6 @@ class SettingsController : NewBaseController(R.layout.controller_settings) { ) } - private fun showLovelyDialog(dialogId: Int, savedInstanceState: Bundle?) { - if (dialogId == ID_REMOVE_ACCOUNT_WARNING_DIALOG) { - showRemoveAccountWarning(savedInstanceState) - } - } - fun sendLogs() { if (resources!!.getBoolean(R.bool.nc_is_debug)) { sendMailWithAttachment((context)!!) @@ -378,14 +371,9 @@ class SettingsController : NewBaseController(R.layout.controller_settings) { override fun onRestoreViewState(view: View, savedViewState: Bundle) { 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 fun showRemoveAccountWarning(savedInstanceState: Bundle?) { + private fun showRemoveAccountWarning() { if (activity != null) { val materialAlertDialogBuilder = MaterialAlertDialogBuilder(binding.messageText.context) .setTitle(R.string.nc_settings_remove_account) @@ -492,7 +480,7 @@ class SettingsController : NewBaseController(R.layout.controller_settings) { setupProfileQueryDisposable() binding.settingsRemoveAccount.addPreferenceClickListener { - showLovelyDialog(ID_REMOVE_ACCOUNT_WARNING_DIALOG, null) + showRemoveAccountWarning() } } setupMessageView() @@ -1067,7 +1055,6 @@ class SettingsController : NewBaseController(R.layout.controller_settings) { companion object { private const val TAG = "SettingsController" - private const val ID_REMOVE_ACCOUNT_WARNING_DIALOG = 0 private const val DURATION: Long = 2500 private const val START_DELAY: Long = 5000 private const val DISABLED_ALPHA: Float = 0.38f From 9621f1daf329f60ed8d029b521a0fbd0412aebd4 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 17 Aug 2022 23:48:26 +0200 Subject: [PATCH 2/2] Migrate dialogs on ConversationList to Material3 Signed-off-by: Andy Scherzinger --- .../ConversationsListController.java | 246 ++++++++---------- .../interfaces/ConversationMenuInterface.kt | 2 +- .../dialog/ConversationsListBottomDialog.kt | 5 +- 3 files changed, 105 insertions(+), 148 deletions(-) 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 e93fbaafb..87bc446cb 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java @@ -63,6 +63,7 @@ import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber; import com.facebook.imagepipeline.image.CloseableImage; import com.facebook.imagepipeline.request.ImageRequest; import com.google.android.material.button.MaterialButton; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.nextcloud.talk.R; import com.nextcloud.talk.activities.MainActivity; @@ -103,8 +104,6 @@ import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew; import com.nextcloud.talk.utils.preferences.AppPreferences; import com.nextcloud.talk.utils.rx.SearchViewObservable; import com.nextcloud.ui.popupbubble.PopupBubble; -import com.yarolegovich.lovelydialog.LovelySaveStateHandler; -import com.yarolegovich.lovelydialog.LovelyStandardDialog; import org.apache.commons.lang3.builder.CompareToBuilder; import org.greenrobot.eventbus.EventBus; @@ -124,6 +123,7 @@ import javax.inject.Inject; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.SearchView; import androidx.core.content.res.ResourcesCompat; import androidx.core.graphics.drawable.RoundedBitmapDrawable; @@ -154,7 +154,6 @@ import static com.nextcloud.talk.utils.Mimetype.TEXT_PLAIN; public class ConversationsListController extends BaseController implements FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, ConversationMenuInterface { public static final String TAG = "ConvListController"; - public static final int ID_DELETE_CONVERSATION_DIALOG = 0; public static final int UNREAD_BUBBLE_DELAY = 2500; private static final String KEY_SEARCH_QUERY = "ContactsController.searchQuery"; @@ -219,8 +218,6 @@ public class ConversationsListController extends BaseController implements Flexi private boolean isRefreshing; - private LovelySaveStateHandler saveStateHandler; - private Bundle conversationMenuBundle = null; private boolean showShareToScreen = false; @@ -267,10 +264,6 @@ public class ConversationsListController extends BaseController implements Flexi getActionBar().show(); } - if (saveStateHandler == null) { - saveStateHandler = new LovelySaveStateHandler(); - } - if (adapter == null) { adapter = new FlexibleAdapter<>(conversationItems, getActivity(), true); } else { @@ -857,7 +850,6 @@ public class ConversationsListController extends BaseController implements Flexi @Override public void onSaveViewState(@NonNull View view, @NonNull Bundle outState) { - saveStateHandler.saveInstanceState(outState); if (searchView != null && !TextUtils.isEmpty(searchView.getQuery())) { outState.putString(KEY_SEARCH_QUERY, searchView.getQuery().toString()); @@ -872,11 +864,6 @@ public class ConversationsListController extends BaseController implements Flexi if (savedViewState.containsKey(KEY_SEARCH_QUERY)) { searchQuery = savedViewState.getString(KEY_SEARCH_QUERY, ""); } - 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); - } } @Override @@ -1051,25 +1038,26 @@ public class ConversationsListController extends BaseController implements Flexi selectedConversation.getDisplayName()); } - new LovelyStandardDialog(getActivity()) - .setPositiveButtonColorRes(R.color.nc_darkGreen) + MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(floatingActionButton.getContext()) + .setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.upload)) .setTitle(confirmationQuestion) .setMessage(fileNamesWithLineBreaks.toString()) - .setPositiveButton(R.string.nc_yes, new View.OnClickListener() { - @Override - public void onClick(View v) { - upload(); - openConversation(); - } + .setPositiveButton(R.string.nc_yes, (dialog, which) -> { + upload(); + openConversation(); }) - .setNegativeButton(R.string.nc_no, new View.OnClickListener() { - @Override - public void onClick(View v) { - Log.d(TAG, "sharing files aborted, going back to share-to screen"); - showShareToScreen = true; - } - }) - .show(); + .setNegativeButton(R.string.nc_no, (dialog, which) -> { + Log.d(TAG, "sharing files aborted, going back to share-to screen"); + showShareToScreen = true; + }); + + viewThemeUtils.colorMaterialAlertDialogBackground(floatingActionButton.getContext(), dialogBuilder); + + AlertDialog dialog = dialogBuilder.show(); + + viewThemeUtils.colorTextButtons( + dialog.getButton(AlertDialog.BUTTON_POSITIVE), + dialog.getButton(AlertDialog.BUTTON_NEGATIVE)); } else { UploadAndShareFilesWorker.Companion.requestStoragePermission(ConversationsListController.this); } @@ -1232,103 +1220,54 @@ public class ConversationsListController extends BaseController implements Flexi }, 2500); } - private void showDeleteConversationDialog(Bundle savedInstanceState) { - if (getActivity() != null && conversationMenuBundle != null && currentUser != null && conversationMenuBundle.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID()) == currentUser.getId()) { + @Override + public void showDeleteConversationDialog(@NonNull Bundle bundle) { + conversationMenuBundle = bundle; + if (getActivity() != null && + conversationMenuBundle != null && + currentUser != null && + conversationMenuBundle.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID()) == currentUser.getId()) { Conversation conversation = Parcels.unwrap(conversationMenuBundle.getParcelable(BundleKeys.INSTANCE.getKEY_ROOM())); if (conversation != 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.bg_default)) - .setPositiveButtonColor(context.getResources().getColor(R.color.nc_darkRed)) - .setTitle(R.string.nc_delete_call) - .setMessage(R.string.nc_delete_conversation_more) - .setPositiveButton(R.string.nc_delete, new View.OnClickListener() { - @Override - public void onClick(View v) { + MaterialAlertDialogBuilder dialogBuilder = + new MaterialAlertDialogBuilder(floatingActionButton.getContext()) + .setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp)) + .setTitle(R.string.nc_delete_call) + .setMessage(R.string.nc_delete_conversation_more) + .setPositiveButton(R.string.nc_delete, (dialog, which) -> { Data.Builder data = new Data.Builder(); data.putLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), conversationMenuBundle.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID())); data.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), conversation.getToken()); conversationMenuBundle = null; deleteConversation(data.build()); - } - }) - .setNegativeButton(R.string.nc_cancel, new View.OnClickListener() { - @Override - public void onClick(View v) { + }) + .setNegativeButton(R.string.nc_cancel, (dialog, which) -> { conversationMenuBundle = null; - } - }) - .setInstanceStateHandler(ID_DELETE_CONVERSATION_DIALOG, saveStateHandler) - .setSavedInstanceState(savedInstanceState) - .show(); + }); + + viewThemeUtils.colorMaterialAlertDialogBackground(floatingActionButton.getContext(), dialogBuilder); + + AlertDialog dialog = dialogBuilder.show(); + + viewThemeUtils.colorTextButtons( + dialog.getButton(AlertDialog.BUTTON_POSITIVE), + dialog.getButton(AlertDialog.BUTTON_NEGATIVE)); } } } private void showUnauthorizedDialog() { 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.bg_default)) - .setPositiveButtonColor(context.getResources().getColor(R.color.nc_darkRed)) - .setCancelable(false) + MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(floatingActionButton.getContext()) + .setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp)) .setTitle(R.string.nc_dialog_invalid_password) .setMessage(R.string.nc_dialog_reauth_or_delete) - .setPositiveButton(R.string.nc_delete, new View.OnClickListener() { - @Override - public void onClick(View v) { - boolean otherUserExists = userManager - .scheduleUserForDeletionWithId(currentUser.getId()) - .blockingGet(); - - OneTimeWorkRequest accountRemovalWork = new OneTimeWorkRequest.Builder(AccountRemovalWorker.class).build(); - WorkManager.getInstance().enqueue(accountRemovalWork); - - if (otherUserExists && getView() != null) { - onViewBound(getView()); - onAttach(getView()); - } else if (!otherUserExists) { - getRouter().setRoot(RouterTransaction.with( - new ServerSelectionController()) - .pushChangeHandler(new VerticalChangeHandler()) - .popChangeHandler(new VerticalChangeHandler())); - } - } - }) - .setNegativeButton(R.string.nc_settings_reauthorize, new View.OnClickListener() { - @Override - public void onClick(View v) { - getRouter().pushController(RouterTransaction.with( - new WebViewLoginController(currentUser.getBaseUrl(), true)) - .pushChangeHandler(new VerticalChangeHandler()) - .popChangeHandler(new VerticalChangeHandler())); - } - }) - .setInstanceStateHandler(ID_DELETE_CONVERSATION_DIALOG, saveStateHandler) - .show(); - } - } - - private void showServerEOLDialog() { - new LovelyStandardDialog(getActivity(), LovelyStandardDialog.ButtonLayout.HORIZONTAL) - .setTopColorRes(R.color.nc_darkRed) - .setIcon(DisplayUtils.getTintedDrawable(context.getResources(), - R.drawable.ic_warning_white, - R.color.bg_default)) - .setPositiveButtonColor(context.getResources().getColor(R.color.nc_darkRed)) - .setCancelable(false) - .setTitle(R.string.nc_settings_server_eol_title) - .setMessage(R.string.nc_settings_server_eol) - .setPositiveButton(R.string.nc_settings_remove_account, new View.OnClickListener() { - @Override - public void onClick(View v) { + .setCancelable(false) + .setPositiveButton(R.string.nc_delete, (dialog, which) -> { boolean otherUserExists = userManager .scheduleUserForDeletionWithId(currentUser.getId()) .blockingGet(); @@ -1341,25 +1280,68 @@ public class ConversationsListController extends BaseController implements Flexi onAttach(getView()); } else if (!otherUserExists) { getRouter().setRoot(RouterTransaction.with( - new ServerSelectionController()) + new ServerSelectionController()) .pushChangeHandler(new VerticalChangeHandler()) .popChangeHandler(new VerticalChangeHandler())); } + }) + .setNegativeButton(R.string.nc_settings_reauthorize, (dialog, which) -> { + getRouter().pushController(RouterTransaction.with( + new WebViewLoginController(currentUser.getBaseUrl(), true)) + .pushChangeHandler(new VerticalChangeHandler()) + .popChangeHandler(new VerticalChangeHandler())); + }); + + viewThemeUtils.colorMaterialAlertDialogBackground(floatingActionButton.getContext(), dialogBuilder); + + AlertDialog dialog = dialogBuilder.show(); + + viewThemeUtils.colorTextButtons( + dialog.getButton(AlertDialog.BUTTON_POSITIVE), + dialog.getButton(AlertDialog.BUTTON_NEGATIVE)); + } + } + + private void showServerEOLDialog() { + MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(floatingActionButton.getContext()) + .setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_warning_white)) + .setTitle(R.string.nc_settings_server_eol_title) + .setMessage(R.string.nc_settings_server_eol) + .setCancelable(false) + .setPositiveButton(R.string.nc_settings_remove_account, (dialog, which) -> { + boolean otherUserExists = userManager + .scheduleUserForDeletionWithId(currentUser.getId()) + .blockingGet(); + + OneTimeWorkRequest accountRemovalWork = new OneTimeWorkRequest.Builder(AccountRemovalWorker.class).build(); + WorkManager.getInstance().enqueue(accountRemovalWork); + + if (otherUserExists && getView() != null) { + onViewBound(getView()); + onAttach(getView()); + } else if (!otherUserExists) { + getRouter().setRoot(RouterTransaction.with( + new ServerSelectionController()) + .pushChangeHandler(new VerticalChangeHandler()) + .popChangeHandler(new VerticalChangeHandler())); } }) - .setNegativeButton(R.string.nc_cancel, new View.OnClickListener() { - @Override - public void onClick(View v) { - if (userManager.getUsers().blockingGet().size() > 0) { - getRouter().pushController(RouterTransaction.with(new SwitchAccountController())); - } else { - getActivity().finishAffinity(); - getActivity().finish(); - } + .setNegativeButton(R.string.nc_cancel, (dialog, which) -> { + if (userManager.getUsers().blockingGet().size() > 0) { + getRouter().pushController(RouterTransaction.with(new SwitchAccountController())); + } else { + getActivity().finishAffinity(); + getActivity().finish(); } - }) - .setInstanceStateHandler(ID_DELETE_CONVERSATION_DIALOG, saveStateHandler) - .show(); + }); + + viewThemeUtils.colorMaterialAlertDialogBackground(floatingActionButton.getContext(), dialogBuilder); + + AlertDialog dialog = dialogBuilder.show(); + + viewThemeUtils.colorTextButtons( + dialog.getButton(AlertDialog.BUTTON_POSITIVE), + dialog.getButton(AlertDialog.BUTTON_NEGATIVE)); } private void deleteConversation(Data data) { @@ -1368,28 +1350,6 @@ public class ConversationsListController extends BaseController implements Flexi WorkManager.getInstance().enqueue(deleteConversationWorker); } - private void showLovelyDialog(int dialogId, Bundle savedInstanceState) { - switch (dialogId) { - case ID_DELETE_CONVERSATION_DIALOG: - showDeleteConversationDialog(savedInstanceState); - break; - default: - break; - } - } - - @Override - public void openLovelyDialogWithIdAndBundle(int dialogId, Bundle bundle) { - conversationMenuBundle = bundle; - switch (dialogId) { - case ID_DELETE_CONVERSATION_DIALOG: - showLovelyDialog(dialogId, null); - break; - default: - break; - } - } - @Override public AppBarLayoutType getAppBarLayoutType() { return AppBarLayoutType.SEARCH_BAR; diff --git a/app/src/main/java/com/nextcloud/talk/interfaces/ConversationMenuInterface.kt b/app/src/main/java/com/nextcloud/talk/interfaces/ConversationMenuInterface.kt index 9f6afdaf1..2b1d332e6 100644 --- a/app/src/main/java/com/nextcloud/talk/interfaces/ConversationMenuInterface.kt +++ b/app/src/main/java/com/nextcloud/talk/interfaces/ConversationMenuInterface.kt @@ -23,5 +23,5 @@ package com.nextcloud.talk.interfaces import android.os.Bundle interface ConversationMenuInterface { - fun openLovelyDialogWithIdAndBundle(dialogId: Int, bundle: Bundle) + fun showDeleteConversationDialog(bundle: Bundle) } diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt index a3387912a..1e77a7b38 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt @@ -204,10 +204,7 @@ class ConversationsListBottomDialog( bundle.putLong(KEY_INTERNAL_USER_ID, currentUser.id!!) bundle.putParcelable(KEY_ROOM, Parcels.wrap(conversation)) - controller.openLovelyDialogWithIdAndBundle( - ConversationsListController.ID_DELETE_CONVERSATION_DIALOG, - bundle - ) + controller.showDeleteConversationDialog(bundle) } dismiss()