diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/alternatives/ui/AlternativesActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/alternatives/ui/AlternativesActivity.kt index aefe5ce3b..9c9e16920 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/alternatives/ui/AlternativesActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/alternatives/ui/AlternativesActivity.kt @@ -9,7 +9,6 @@ import androidx.activity.viewModels import androidx.core.graphics.Insets import androidx.core.view.updatePadding import coil.ImageLoader -import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver @@ -18,8 +17,8 @@ import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga import org.koitharu.kotatsu.core.parser.MangaIntent import org.koitharu.kotatsu.core.ui.BaseActivity import org.koitharu.kotatsu.core.ui.BaseListAdapter +import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener -import org.koitharu.kotatsu.core.util.ext.DIALOG_THEME_CENTERED import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observeEvent import org.koitharu.kotatsu.databinding.ActivityAlternativesBinding @@ -89,22 +88,23 @@ class AlternativesActivity : BaseActivity(), } private fun confirmMigration(target: Manga) { - MaterialAlertDialogBuilder(this, DIALOG_THEME_CENTERED) - .setIcon(R.drawable.ic_replace) - .setTitle(R.string.manga_migration) - .setMessage( + buildAlertDialog(this, isCentered = true) { + setIcon(R.drawable.ic_replace) + setTitle(R.string.manga_migration) + setMessage( getString( R.string.migrate_confirmation, viewModel.manga.title, - viewModel.manga.source.getTitle(this), + viewModel.manga.source.getTitle(context), target.title, - target.source.getTitle(this), + target.source.getTitle(context), ), ) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.migrate) { _, _ -> + setNegativeButton(android.R.string.cancel, null) + setPositiveButton(R.string.migrate) { _, _ -> viewModel.migrate(target) - }.show() + } + }.show() } companion object { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/AlertDialogs.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/AlertDialogs.kt new file mode 100644 index 000000000..bfdf6dde3 --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/AlertDialogs.kt @@ -0,0 +1,67 @@ +package org.koitharu.kotatsu.core.ui.dialog + +import android.content.Context +import android.view.LayoutInflater +import android.widget.CompoundButton.OnCheckedChangeListener +import androidx.annotation.StringRes +import androidx.appcompat.app.AlertDialog +import androidx.core.view.updatePadding +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.hannesdorfmann.adapterdelegates4.AdapterDelegate +import com.hannesdorfmann.adapterdelegates4.AdapterDelegatesManager +import com.hannesdorfmann.adapterdelegates4.ListDelegationAdapter +import org.koitharu.kotatsu.R +import org.koitharu.kotatsu.databinding.DialogCheckboxBinding +import com.google.android.material.R as materialR + +inline fun buildAlertDialog( + context: Context, + isCentered: Boolean = false, + block: MaterialAlertDialogBuilder.() -> Unit, +): AlertDialog = MaterialAlertDialogBuilder( + context, + if (isCentered) materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered else 0, +).apply(block).create() + +fun B.setCheckbox( + @StringRes textResId: Int, + isChecked: Boolean, + onCheckedChangeListener: OnCheckedChangeListener +) = apply { + val binding = DialogCheckboxBinding.inflate(LayoutInflater.from(context)) + binding.checkbox.setText(textResId) + binding.checkbox.isChecked = isChecked + binding.checkbox.setOnCheckedChangeListener(onCheckedChangeListener) + setView(binding.root) +} + +fun B.setRecyclerViewList( + list: List, + delegate: AdapterDelegate>, +) = apply { + val delegatesManager = AdapterDelegatesManager>() + delegatesManager.addDelegate(delegate) + setRecyclerViewList(ListDelegationAdapter(delegatesManager).also { it.items = list }) +} + +fun B.setRecyclerViewList( + list: List, + vararg delegates: AdapterDelegate>, +) = apply { + val delegatesManager = AdapterDelegatesManager>() + delegates.forEach { delegatesManager.addDelegate(it) } + setRecyclerViewList(ListDelegationAdapter(delegatesManager).also { it.items = list }) +} + +fun B.setRecyclerViewList(adapter: RecyclerView.Adapter<*>) = apply { + val recyclerView = RecyclerView(context) + recyclerView.layoutManager = LinearLayoutManager(context) + recyclerView.updatePadding( + top = context.resources.getDimensionPixelOffset(R.dimen.list_spacing), + ) + recyclerView.clipToPadding = false + recyclerView.adapter = adapter + setView(recyclerView) +} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/CheckBoxAlertDialog.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/CheckBoxAlertDialog.kt deleted file mode 100644 index f246aba42..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/CheckBoxAlertDialog.kt +++ /dev/null @@ -1,80 +0,0 @@ -package org.koitharu.kotatsu.core.ui.dialog - -import android.content.Context -import android.content.DialogInterface -import android.view.LayoutInflater -import androidx.annotation.DrawableRes -import androidx.annotation.StringRes -import androidx.appcompat.app.AlertDialog -import com.google.android.material.dialog.MaterialAlertDialogBuilder -import org.koitharu.kotatsu.databinding.DialogCheckboxBinding - -class CheckBoxAlertDialog private constructor(private val delegate: AlertDialog) : - DialogInterface by delegate { - - fun show() = delegate.show() - - class Builder(context: Context) { - - private val binding = DialogCheckboxBinding.inflate(LayoutInflater.from(context)) - - private val delegate = MaterialAlertDialogBuilder(context) - .setView(binding.root) - - fun setTitle(@StringRes titleResId: Int): Builder { - delegate.setTitle(titleResId) - return this - } - - fun setTitle(title: CharSequence): Builder { - delegate.setTitle(title) - return this - } - - fun setMessage(@StringRes messageId: Int): Builder { - delegate.setMessage(messageId) - return this - } - - fun setMessage(message: CharSequence): Builder { - delegate.setMessage(message) - return this - } - - fun setCheckBoxText(@StringRes textId: Int): Builder { - binding.checkbox.setText(textId) - return this - } - - fun setCheckBoxChecked(isChecked: Boolean): Builder { - binding.checkbox.isChecked = isChecked - return this - } - - fun setIcon(@DrawableRes iconId: Int): Builder { - delegate.setIcon(iconId) - return this - } - - fun setPositiveButton( - @StringRes textId: Int, - listener: (DialogInterface, Boolean) -> Unit - ): Builder { - delegate.setPositiveButton(textId) { dialog, _ -> - listener(dialog, binding.checkbox.isChecked) - } - return this - } - - fun setNegativeButton( - @StringRes textId: Int, - listener: DialogInterface.OnClickListener? = null - ): Builder { - delegate.setNegativeButton(textId, listener) - return this - } - - fun create() = CheckBoxAlertDialog(delegate.create()) - - } -} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/RecyclerViewAlertDialog.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/RecyclerViewAlertDialog.kt deleted file mode 100644 index f5acf5d36..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/RecyclerViewAlertDialog.kt +++ /dev/null @@ -1,101 +0,0 @@ -package org.koitharu.kotatsu.core.ui.dialog - -import android.content.Context -import android.content.DialogInterface -import androidx.annotation.DrawableRes -import androidx.annotation.StringRes -import androidx.appcompat.app.AlertDialog -import androidx.core.view.updatePadding -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.google.android.material.dialog.MaterialAlertDialogBuilder -import com.hannesdorfmann.adapterdelegates4.AdapterDelegate -import com.hannesdorfmann.adapterdelegates4.AdapterDelegatesManager -import com.hannesdorfmann.adapterdelegates4.ListDelegationAdapter -import org.koitharu.kotatsu.R - -class RecyclerViewAlertDialog private constructor( - private val delegate: AlertDialog -) : DialogInterface by delegate { - - fun show() = delegate.show() - - class Builder(context: Context) { - - private val recyclerView = RecyclerView(context) - private val delegatesManager = AdapterDelegatesManager>() - private var items: List? = null - - private val delegate = MaterialAlertDialogBuilder(context) - .setView(recyclerView) - - init { - recyclerView.layoutManager = LinearLayoutManager(context) - recyclerView.updatePadding( - top = context.resources.getDimensionPixelOffset(R.dimen.list_spacing), - ) - recyclerView.clipToPadding = false - } - - fun setTitle(@StringRes titleResId: Int): Builder { - delegate.setTitle(titleResId) - return this - } - - fun setTitle(title: CharSequence): Builder { - delegate.setTitle(title) - return this - } - - fun setIcon(@DrawableRes iconId: Int): Builder { - delegate.setIcon(iconId) - return this - } - - fun setPositiveButton( - @StringRes textId: Int, - listener: DialogInterface.OnClickListener, - ): Builder { - delegate.setPositiveButton(textId, listener) - return this - } - - fun setNegativeButton( - @StringRes textId: Int, - listener: DialogInterface.OnClickListener? = null - ): Builder { - delegate.setNegativeButton(textId, listener) - return this - } - - fun setNeutralButton( - @StringRes textId: Int, - listener: DialogInterface.OnClickListener, - ): Builder { - delegate.setNeutralButton(textId, listener) - return this - } - - fun setCancelable(isCancelable: Boolean): Builder { - delegate.setCancelable(isCancelable) - return this - } - - fun addAdapterDelegate(subject: AdapterDelegate>): Builder { - delegatesManager.addDelegate(subject) - return this - } - - fun setItems(list: List): Builder { - items = list - return this - } - - fun create(): RecyclerViewAlertDialog { - recyclerView.adapter = ListDelegationAdapter(delegatesManager).also { - it.items = items - } - return RecyclerViewAlertDialog(delegate.create()) - } - } -} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/RememberCheckListener.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/RememberCheckListener.kt new file mode 100644 index 000000000..572fbee70 --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/dialog/RememberCheckListener.kt @@ -0,0 +1,16 @@ +package org.koitharu.kotatsu.core.ui.dialog + +import android.widget.CompoundButton +import android.widget.CompoundButton.OnCheckedChangeListener + +class RememberCheckListener( + initialValue: Boolean, +) : OnCheckedChangeListener { + + var isChecked: Boolean = initialValue + private set + + override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) { + this.isChecked = isChecked + } +} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Theme.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Theme.kt index 0d3a8d738..e5b713d8f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Theme.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Theme.kt @@ -8,11 +8,9 @@ import androidx.annotation.AttrRes import androidx.annotation.ColorInt import androidx.annotation.FloatRange import androidx.annotation.Px -import androidx.annotation.StyleRes import androidx.core.content.ContextCompat import androidx.core.content.res.use import androidx.core.graphics.ColorUtils -import com.google.android.material.R as materialR fun Context.getThemeDrawable( @AttrRes resId: Int, @@ -77,7 +75,3 @@ fun TypedArray.getDrawableCompat(context: Context, index: Int): Drawable? { val resId = getResourceId(index, 0) return if (resId != 0) ContextCompat.getDrawable(context, resId) else null } - -@get:StyleRes -val DIALOG_THEME_CENTERED: Int - inline get() = materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DownloadDialogHelper.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DownloadDialogHelper.kt index 7fa8ef877..50f8fe3d9 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DownloadDialogHelper.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DownloadDialogHelper.kt @@ -4,7 +4,8 @@ import android.content.DialogInterface import android.view.View import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.model.ids -import org.koitharu.kotatsu.core.ui.dialog.RecyclerViewAlertDialog +import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog +import org.koitharu.kotatsu.core.ui.dialog.setRecyclerViewList import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.download.ui.dialog.DownloadOption import org.koitharu.kotatsu.download.ui.dialog.downloadOptionAD @@ -53,16 +54,14 @@ class DownloadDialogHelper( callback.onItemClick(item, host) dialog?.dismiss() } - dialog = RecyclerViewAlertDialog.Builder(host.context) - .addAdapterDelegate(downloadOptionAD(listener)) - .setCancelable(true) - .setTitle(R.string.download) - .setNegativeButton(android.R.string.cancel) - .setNeutralButton(R.string.settings) { _, _ -> + dialog = buildAlertDialog(host.context) { + setCancelable(true) + setTitle(R.string.download) + setNegativeButton(android.R.string.cancel, null) + setNeutralButton(R.string.settings) { _, _ -> host.context.startActivity(SettingsActivity.newDownloadsSettingsIntent(host.context)) } - .setItems(options) - .create() - .also { it.show() } + setRecyclerViewList(options, downloadOptionAD(listener)) + }.also { it.show() } } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadsMenuProvider.kt b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadsMenuProvider.kt index 1c6b6e92b..128412c2f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadsMenuProvider.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadsMenuProvider.kt @@ -5,9 +5,8 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import androidx.core.view.MenuProvider -import com.google.android.material.dialog.MaterialAlertDialogBuilder import org.koitharu.kotatsu.R -import org.koitharu.kotatsu.core.util.ext.DIALOG_THEME_CENTERED +import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog import org.koitharu.kotatsu.settings.SettingsActivity class DownloadsMenuProvider( @@ -42,24 +41,22 @@ class DownloadsMenuProvider( } private fun confirmCancelAll() { - MaterialAlertDialogBuilder(context, DIALOG_THEME_CENTERED) - .setTitle(R.string.cancel_all) - .setMessage(R.string.cancel_all_downloads_confirm) - .setIcon(R.drawable.ic_cancel_multiple) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.confirm) { _, _ -> - viewModel.cancelAll() - }.show() + buildAlertDialog(context, isCentered = true) { + setTitle(R.string.cancel_all) + setMessage(R.string.cancel_all_downloads_confirm) + setIcon(R.drawable.ic_cancel_multiple) + setNegativeButton(android.R.string.cancel, null) + setPositiveButton(R.string.confirm) { _, _ -> viewModel.cancelAll() } + }.show() } private fun confirmRemoveCompleted() { - MaterialAlertDialogBuilder(context, DIALOG_THEME_CENTERED) - .setTitle(R.string.remove_completed) - .setMessage(R.string.remove_completed_downloads_confirm) - .setIcon(R.drawable.ic_clear_all) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.clear) { _, _ -> - viewModel.removeCompleted() - }.show() + buildAlertDialog(context, isCentered = true) { + setTitle(R.string.remove_completed) + setMessage(R.string.remove_completed_downloads_confirm) + setIcon(R.drawable.ic_clear_all) + setNegativeButton(android.R.string.cancel, null) + setPositiveButton(R.string.clear) { _, _ -> viewModel.removeCompleted() } + }.show() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/CategoriesSelectionCallback.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/CategoriesSelectionCallback.kt index c0ab6302d..0a269669e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/CategoriesSelectionCallback.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/CategoriesSelectionCallback.kt @@ -4,10 +4,9 @@ import android.view.Menu import android.view.MenuItem import androidx.appcompat.view.ActionMode import androidx.recyclerview.widget.RecyclerView -import com.google.android.material.dialog.MaterialAlertDialogBuilder import org.koitharu.kotatsu.R +import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog import org.koitharu.kotatsu.core.ui.list.ListSelectionController -import org.koitharu.kotatsu.core.util.ext.DIALOG_THEME_CENTERED class CategoriesSelectionCallback( private val recyclerView: RecyclerView, @@ -74,15 +73,15 @@ class CategoriesSelectionCallback( } private fun confirmDeleteCategories(ids: Set, mode: ActionMode) { - val context = recyclerView.context - MaterialAlertDialogBuilder(context, DIALOG_THEME_CENTERED) - .setMessage(R.string.categories_delete_confirm) - .setTitle(R.string.remove_category) - .setIcon(R.drawable.ic_delete) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.remove) { _, _ -> + buildAlertDialog(recyclerView.context, isCentered = true) { + setMessage(R.string.categories_delete_confirm) + setTitle(R.string.remove_category) + setIcon(R.drawable.ic_delete) + setNegativeButton(android.R.string.cancel, null) + setPositiveButton(R.string.remove) { _, _ -> viewModel.deleteCategories(ids) mode.finish() - }.show() + } + }.show() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/container/FavouriteTabPopupMenuProvider.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/container/FavouriteTabPopupMenuProvider.kt index 64a26395a..dbd29e6c4 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/container/FavouriteTabPopupMenuProvider.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/container/FavouriteTabPopupMenuProvider.kt @@ -5,9 +5,8 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import androidx.core.view.MenuProvider -import com.google.android.material.dialog.MaterialAlertDialogBuilder import org.koitharu.kotatsu.R -import org.koitharu.kotatsu.core.util.ext.DIALOG_THEME_CENTERED +import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog import org.koitharu.kotatsu.favourites.ui.categories.edit.FavouritesCategoryEditActivity import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment.Companion.NO_ID @@ -41,13 +40,12 @@ class FavouriteTabPopupMenuProvider( } private fun confirmDelete() { - MaterialAlertDialogBuilder(context, DIALOG_THEME_CENTERED) - .setMessage(R.string.categories_delete_confirm) - .setTitle(R.string.remove_category) - .setIcon(R.drawable.ic_delete) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.remove) { _, _ -> - viewModel.deleteCategory(categoryId) - }.show() + buildAlertDialog(context, isCentered = true) { + setMessage(R.string.categories_delete_confirm) + setTitle(R.string.remove_category) + setIcon(R.drawable.ic_delete) + setNegativeButton(android.R.string.cancel, null) + setPositiveButton(R.string.remove) { _, _ -> viewModel.deleteCategory(categoryId) } + }.show() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListMenuProvider.kt b/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListMenuProvider.kt index ab1a49ccd..a30adb5f2 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListMenuProvider.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListMenuProvider.kt @@ -6,16 +6,14 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import androidx.core.view.MenuProvider -import com.google.android.material.dialog.MaterialAlertDialogBuilder import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.ui.dialog.RememberSelectionDialogListener -import org.koitharu.kotatsu.core.util.ext.DIALOG_THEME_CENTERED +import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog import org.koitharu.kotatsu.stats.ui.StatsActivity import java.time.Instant import java.time.LocalDate import java.time.ZoneId import java.time.temporal.ChronoUnit -import com.google.android.material.R as materialR class HistoryListMenuProvider( private val context: Context, @@ -49,9 +47,9 @@ class HistoryListMenuProvider( private fun showClearHistoryDialog() { val selectionListener = RememberSelectionDialogListener(2) - MaterialAlertDialogBuilder(context, DIALOG_THEME_CENTERED) - .setTitle(R.string.clear_history) - .setSingleChoiceItems( + buildAlertDialog(context, isCentered = true) { + setTitle(R.string.clear_history) + setSingleChoiceItems( arrayOf( context.getString(R.string.last_2_hours), context.getString(R.string.today), @@ -60,9 +58,9 @@ class HistoryListMenuProvider( selectionListener.selection, selectionListener, ) - .setIcon(R.drawable.ic_delete) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.clear) { _, _ -> + setIcon(R.drawable.ic_delete_all) + setNegativeButton(android.R.string.cancel, null) + setPositiveButton(R.string.clear) { _, _ -> val minDate = when (selectionListener.selection) { 0 -> Instant.now().minus(2, ChronoUnit.HOURS) 1 -> LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant() @@ -70,6 +68,7 @@ class HistoryListMenuProvider( else -> return@setPositiveButton } viewModel.clearHistory(minDate) - }.show() + } + }.show() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/SearchSuggestionMenuProvider.kt b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/SearchSuggestionMenuProvider.kt index 8483287c1..232e392ac 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/SearchSuggestionMenuProvider.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/SearchSuggestionMenuProvider.kt @@ -6,12 +6,10 @@ import android.view.MenuInflater import android.view.MenuItem import androidx.activity.result.ActivityResultLauncher import androidx.core.view.MenuProvider -import com.google.android.material.dialog.MaterialAlertDialogBuilder import org.koitharu.kotatsu.R -import org.koitharu.kotatsu.core.util.ext.DIALOG_THEME_CENTERED +import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog import org.koitharu.kotatsu.core.util.ext.resolve import org.koitharu.kotatsu.core.util.ext.tryLaunch -import com.google.android.material.R as materialR class SearchSuggestionMenuProvider( private val context: Context, @@ -44,13 +42,13 @@ class SearchSuggestionMenuProvider( } private fun clearSearchHistory() { - MaterialAlertDialogBuilder(context, DIALOG_THEME_CENTERED) - .setTitle(R.string.clear_search_history) - .setIcon(R.drawable.ic_clear_all) - .setMessage(R.string.text_clear_search_history_prompt) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.clear) { _, _ -> - viewModel.clearSearchHistory() - }.show() + buildAlertDialog(context, isCentered = true) { + setTitle(R.string.clear_search_history) + setIcon(R.drawable.ic_clear_all) + setCancelable(true) + setMessage(R.string.text_clear_search_history_prompt) + setNegativeButton(android.R.string.cancel, null) + setPositiveButton(R.string.clear) { _, _ -> viewModel.clearSearchHistory() } + }.show() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/nav/NavConfigFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/nav/NavConfigFragment.kt index ec9bca2d3..0d470973d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/nav/NavConfigFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/nav/NavConfigFragment.kt @@ -15,7 +15,8 @@ import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.prefs.NavItem import org.koitharu.kotatsu.core.ui.BaseFragment import org.koitharu.kotatsu.core.ui.BaseListAdapter -import org.koitharu.kotatsu.core.ui.dialog.RecyclerViewAlertDialog +import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog +import org.koitharu.kotatsu.core.ui.dialog.setRecyclerViewList import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.ui.util.RecyclerViewOwner import org.koitharu.kotatsu.core.util.ext.observe @@ -85,14 +86,12 @@ class NavConfigFragment : BaseFragment(), Recycl viewModel.addItem(item) dialog?.dismiss() } - dialog = RecyclerViewAlertDialog.Builder(v.context) - .setTitle(R.string.add) - .addAdapterDelegate(navAvailableAD(listener)) - .setCancelable(true) - .setItems(viewModel.availableItems) - .setNegativeButton(android.R.string.cancel, null) - .create() - .apply { show() } + dialog = buildAlertDialog(v.context) { + setTitle(R.string.add) + setCancelable(true) + setRecyclerViewList(viewModel.availableItems, navAvailableAD(listener)) + setNegativeButton(android.R.string.cancel, null) + }.apply { show() } } override fun onItemClick(item: NavItem, view: View) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/stats/ui/StatsActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/stats/ui/StatsActivity.kt index 5c9676008..fff0a64f0 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/stats/ui/StatsActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/stats/ui/StatsActivity.kt @@ -1,13 +1,11 @@ package org.koitharu.kotatsu.stats.ui import android.os.Bundle -import android.view.Gravity import android.view.Menu import android.view.MenuItem import android.view.View import android.view.ViewStub import android.widget.CompoundButton -import android.widget.Toast import androidx.activity.viewModels import androidx.appcompat.widget.PopupMenu import androidx.core.graphics.Insets @@ -17,16 +15,15 @@ import androidx.recyclerview.widget.AsyncListDiffer import coil.ImageLoader import com.google.android.material.chip.Chip import com.google.android.material.chip.ChipDrawable -import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.model.FavouriteCategory import org.koitharu.kotatsu.core.ui.BaseActivity import org.koitharu.kotatsu.core.ui.BaseListAdapter +import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.ui.util.ReversibleActionObserver import org.koitharu.kotatsu.core.util.KotatsuColors -import org.koitharu.kotatsu.core.util.ext.DIALOG_THEME_CENTERED import org.koitharu.kotatsu.core.util.ext.enqueueWith import org.koitharu.kotatsu.core.util.ext.newImageRequest import org.koitharu.kotatsu.core.util.ext.observe @@ -167,14 +164,13 @@ class StatsActivity : BaseActivity(), } private fun showClearConfirmDialog() { - MaterialAlertDialogBuilder(this, DIALOG_THEME_CENTERED) - .setMessage(R.string.clear_stats_confirm) - .setTitle(R.string.clear_stats) - .setIcon(R.drawable.ic_delete) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.clear) { _, _ -> - viewModel.clearStats() - }.show() + buildAlertDialog(this, isCentered = true) { + setMessage(R.string.clear_stats_confirm) + setTitle(R.string.clear_stats) + setIcon(R.drawable.ic_delete_all) + setNegativeButton(android.R.string.cancel, null) + setPositiveButton(R.string.clear) { _, _ -> viewModel.clearStats() } + }.show() } private fun showPeriodSelector() { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/FeedMenuProvider.kt b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/FeedMenuProvider.kt index 063046c32..4ba1c37ea 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/FeedMenuProvider.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/FeedMenuProvider.kt @@ -7,7 +7,9 @@ import android.view.MenuItem import android.view.View import androidx.core.view.MenuProvider import org.koitharu.kotatsu.R -import org.koitharu.kotatsu.core.ui.dialog.CheckBoxAlertDialog +import org.koitharu.kotatsu.core.ui.dialog.RememberCheckListener +import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog +import org.koitharu.kotatsu.core.ui.dialog.setCheckbox class FeedMenuProvider( private val snackbarHost: View, @@ -38,15 +40,17 @@ class FeedMenuProvider( } R.id.action_clear_feed -> { - CheckBoxAlertDialog.Builder(context) - .setTitle(R.string.clear_updates_feed) - .setMessage(R.string.text_clear_updates_feed_prompt) - .setNegativeButton(android.R.string.cancel, null) - .setCheckBoxChecked(true) - .setCheckBoxText(R.string.clear_new_chapters_counters) - .setPositiveButton(R.string.clear) { _, isChecked -> - viewModel.clearFeed(isChecked) - }.create().show() + val checkListener = RememberCheckListener(true) + buildAlertDialog(context, isCentered = true) { + setIcon(R.drawable.ic_clear_all) + setTitle(R.string.clear_updates_feed) + setMessage(R.string.text_clear_updates_feed_prompt) + setNegativeButton(android.R.string.cancel, null) + setCheckbox(R.string.clear_new_chapters_counters, true, checkListener) + setPositiveButton(R.string.clear) { _, _ -> + viewModel.clearFeed(checkListener.isChecked) + } + }.show() true } diff --git a/app/src/main/res/drawable/ic_delete_all.xml b/app/src/main/res/drawable/ic_delete_all.xml new file mode 100644 index 000000000..cee2e59dd --- /dev/null +++ b/app/src/main/res/drawable/ic_delete_all.xml @@ -0,0 +1,11 @@ + + +