Merge pull request #2310 from nextcloud/chore/noid/lovelyDialogs

Remove lovely dialogs uses
This commit is contained in:
Andy Scherzinger 2022-08-18 13:40:59 +02:00 committed by GitHub
commit 93c6c0638b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 163 deletions

View file

@ -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) {
.setPositiveButton(R.string.nc_yes, (dialog, which) -> {
upload();
openConversation();
}
})
.setNegativeButton(R.string.nc_no, new View.OnClickListener() {
@Override
public void onClick(View v) {
.setNegativeButton(R.string.nc_no, (dialog, which) -> {
Log.d(TAG, "sharing files aborted, going back to share-to screen");
showShareToScreen = true;
}
})
.show();
});
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,58 +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))
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, new View.OnClickListener() {
@Override
public void onClick(View v) {
.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) {
.setCancelable(false)
.setPositiveButton(R.string.nc_delete, (dialog, which) -> {
boolean otherUserExists = userManager
.scheduleUserForDeletionWithId(currentUser.getId())
.blockingGet();
@ -1300,35 +1284,31 @@ public class ConversationsListController extends BaseController implements Flexi
.pushChangeHandler(new VerticalChangeHandler())
.popChangeHandler(new VerticalChangeHandler()));
}
}
})
.setNegativeButton(R.string.nc_settings_reauthorize, new View.OnClickListener() {
@Override
public void onClick(View v) {
.setNegativeButton(R.string.nc_settings_reauthorize, (dialog, which) -> {
getRouter().pushController(RouterTransaction.with(
new WebViewLoginController(currentUser.getBaseUrl(), true))
.pushChangeHandler(new VerticalChangeHandler())
.popChangeHandler(new VerticalChangeHandler()));
}
})
.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 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)
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)
.setPositiveButton(R.string.nc_settings_remove_account, new View.OnClickListener() {
@Override
public void onClick(View v) {
.setCancelable(false)
.setPositiveButton(R.string.nc_settings_remove_account, (dialog, which) -> {
boolean otherUserExists = userManager
.scheduleUserForDeletionWithId(currentUser.getId())
.blockingGet();
@ -1345,21 +1325,23 @@ public class ConversationsListController extends BaseController implements Flexi
.pushChangeHandler(new VerticalChangeHandler())
.popChangeHandler(new VerticalChangeHandler()));
}
}
})
.setNegativeButton(R.string.nc_cancel, new View.OnClickListener() {
@Override
public void onClick(View v) {
.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;

View file

@ -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

View file

@ -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)
}

View file

@ -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()