diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupConst.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupConst.kt index d7c48f09cd..643c469a28 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupConst.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupConst.kt @@ -6,10 +6,8 @@ object BackupConst { const val INTENT_FILTER = "SettingsBackupFragment" const val ACTION_BACKUP_COMPLETED_DIALOG = "$ID.$INTENT_FILTER.ACTION_BACKUP_COMPLETED_DIALOG" - const val ACTION_SET_PROGRESS_DIALOG = "$ID.$INTENT_FILTER.ACTION_SET_PROGRESS_DIALOG" const val ACTION_ERROR_BACKUP_DIALOG = "$ID.$INTENT_FILTER.ACTION_ERROR_BACKUP_DIALOG" const val ACTION_ERROR_RESTORE_DIALOG = "$ID.$INTENT_FILTER.ACTION_ERROR_RESTORE_DIALOG" - const val ACTION_RESTORE_COMPLETED_DIALOG = "$ID.$INTENT_FILTER.ACTION_RESTORE_COMPLETED_DIALOG" const val ACTION = "$ID.$INTENT_FILTER.ACTION" const val EXTRA_PROGRESS = "$ID.$INTENT_FILTER.EXTRA_PROGRESS" const val EXTRA_AMOUNT = "$ID.$INTENT_FILTER.EXTRA_AMOUNT" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryCreateDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryCreateDialog.kt index 82306d0795..c6d0cc37a7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryCreateDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryCreateDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.category import android.app.Dialog import android.os.Bundle import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.input.input import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.DialogController @@ -13,11 +14,6 @@ import eu.kanade.tachiyomi.ui.base.controller.DialogController class CategoryCreateDialog(bundle: Bundle? = null) : DialogController(bundle) where T : Controller, T : CategoryCreateDialog.Listener { - /** - * Name of the new category. Value updated with each input from the user. - */ - private var currentName = "" - constructor(target: T) : this() { targetController = target } @@ -29,15 +25,13 @@ class CategoryCreateDialog(bundle: Bundle? = null) : DialogController(bundle) * @return a new dialog instance. */ override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) + return MaterialDialog(activity!!) .title(R.string.action_add_category) - .negativeText(android.R.string.cancel) - .alwaysCallInputCallback() - .input(resources?.getString(R.string.name), currentName, false) { _, input -> - currentName = input.toString() + .positiveButton(android.R.string.ok) + .negativeButton(android.R.string.cancel) + .input(hintRes = R.string.name) { _, input -> + (targetController as? Listener)?.createCategory(input.toString()) } - .onPositive { _, _ -> (targetController as? Listener)?.createCategory(currentName) } - .build() } interface Listener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryRenameDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryRenameDialog.kt index 023333c833..80bd01ca81 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryRenameDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryRenameDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.category import android.app.Dialog import android.os.Bundle import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.input.input import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category @@ -34,15 +35,13 @@ class CategoryRenameDialog(bundle: Bundle? = null) : DialogController(bundle) * @return a new dialog instance. */ override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) + return MaterialDialog(activity!!) .title(R.string.action_rename_category) - .negativeText(android.R.string.cancel) - .alwaysCallInputCallback() - .input(resources!!.getString(R.string.name), currentName, false) { _, input -> + .negativeButton(android.R.string.cancel) + .input(hintRes = R.string.name, prefill = currentName) { _, input -> currentName = input.toString() } - .onPositive { _, _ -> onPositive() } - .build() + .positiveButton(android.R.string.ok) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionTrustDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionTrustDialog.kt index 6c1f8bc0a0..577b27fd0a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionTrustDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionTrustDialog.kt @@ -18,18 +18,15 @@ class ExtensionTrustDialog(bundle: Bundle? = null) : DialogController(bundle) } override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) + return MaterialDialog(activity!!) .title(R.string.untrusted_extension) - .content(R.string.untrusted_extension_message) - .positiveText(R.string.ext_trust) - .negativeText(R.string.ext_uninstall) - .onPositive { _, _ -> + .message(R.string.untrusted_extension_message) + .positiveButton(R.string.ext_trust) { (targetController as? Listener)?.trustSignature(args.getString(SIGNATURE_KEY)!!) } - .onNegative { _, _ -> + .negativeButton(R.string.ext_uninstall) { (targetController as? Listener)?.uninstallExtension(args.getString(PKGNAME_KEY)!!) } - .build() } private companion object { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt index 8513ac91ee..d2f56131fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.library import android.app.Dialog import android.os.Bundle import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItemsMultiChoice import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category @@ -28,17 +29,18 @@ class ChangeMangaCategoriesDialog(bundle: Bundle? = null) : } override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .title(R.string.action_move_category) - .items(categories.map { it.name }) - .itemsCallbackMultiChoice(preselected) { dialog, _, _ -> - val newCategories = dialog.selectedIndices?.map { categories[it] }.orEmpty() - (targetController as? Listener)?.updateCategoriesForMangas(mangas, newCategories) - true - } - .positiveText(android.R.string.ok) - .negativeText(android.R.string.cancel) - .build() + return MaterialDialog(activity!!) + .title(R.string.action_move_category) + .listItemsMultiChoice( + items = categories.map { it.name }, + initialSelection = preselected.toIntArray(), + allowEmptySelection = true + ) { _, selections, _ -> + val newCategories = selections.map { categories[it] } + (targetController as? Listener)?.updateCategoriesForMangas(mangas, newCategories) + } + .positiveButton(android.R.string.ok) + .negativeButton(android.R.string.cancel) } interface Listener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/ChangelogDialogController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/ChangelogDialogController.kt index 5e659c5b5e..0af5118f4d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/ChangelogDialogController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/ChangelogDialogController.kt @@ -5,6 +5,7 @@ import android.content.Context import android.os.Bundle import android.util.AttributeSet import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.DialogController @@ -15,11 +16,10 @@ class ChangelogDialogController : DialogController() { override fun onCreateDialog(savedViewState: Bundle?): Dialog { val activity = activity!! val view = WhatsNewRecyclerView(activity) - return MaterialDialog.Builder(activity) - .title(if (BuildConfig.DEBUG) "Notices" else "Changelog") - .customView(view, false) - .positiveText(android.R.string.yes) - .build() + return MaterialDialog(activity) + .title(text = if (BuildConfig.DEBUG) "Notices" else "Changelog") + .customView(view = view, scrollable = false) + .positiveButton(android.R.string.yes) } class WhatsNewRecyclerView(context: Context) : ChangeLogRecyclerView(context) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index da3425ea0e..b9754fea84 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -491,13 +491,10 @@ class ChaptersController() : NucleusController(), fun deleteChapters(chapters: List) { destroyActionModeIfNeeded() if (chapters.isEmpty()) return - - DeletingChaptersDialog().showDialog(router) presenter.deleteChapters(chapters) } fun onChaptersDeleted(chapters: List) { - dismissDeletingDialog() //this is needed so the downloaded text gets removed from the item chapters.forEach { adapter?.updateItem(it) @@ -506,14 +503,9 @@ class ChaptersController() : NucleusController(), } fun onChaptersDeletedError(error: Throwable) { - dismissDeletingDialog() Timber.e(error) } - private fun dismissDeletingDialog() { - router.popControllerWithTag(DeletingChaptersDialog.TAG) - } - // OVERFLOW MENU DIALOGS private fun showDisplayModeDialog() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeleteChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeleteChaptersDialog.kt index 1ac72e7316..234fd88c6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeleteChaptersDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeleteChaptersDialog.kt @@ -15,14 +15,13 @@ class DeleteChaptersDialog(bundle: Bundle? = null) : DialogController(bundle) } override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .content(R.string.confirm_delete_chapters) - .positiveText(android.R.string.yes) - .negativeText(android.R.string.no) - .onPositive { _, _ -> - (targetController as? Listener)?.deleteChapters() - } - .show() + return MaterialDialog(activity!!).show { + message(R.string.confirm_delete_chapters) + positiveButton(android.R.string.yes) { + (targetController as? Listener)?.deleteChapters() + } + negativeButton(android.R.string.no) + } } interface Listener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeletingChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeletingChaptersDialog.kt deleted file mode 100644 index 07a3f318f8..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DeletingChaptersDialog.kt +++ /dev/null @@ -1,27 +0,0 @@ -package eu.kanade.tachiyomi.ui.manga.chapter - -import android.app.Dialog -import android.os.Bundle -import com.afollestad.materialdialogs.MaterialDialog -import com.bluelinelabs.conductor.Router -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.base.controller.DialogController - -class DeletingChaptersDialog(bundle: Bundle? = null) : DialogController(bundle) { - - companion object { - const val TAG = "deleting_dialog" - } - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .progress(true, 0) - .content(R.string.deleting) - .build() - } - - override fun showDialog(router: Router) { - showDialog(router, TAG) - } - -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadChaptersDialog.kt index 6b1f6077ad..a3dfe078ce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadChaptersDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadChaptersDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.app.Dialog import android.os.Bundle import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItems import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.DialogController @@ -26,14 +27,13 @@ class DownloadChaptersDialog(bundle: Bundle? = null) : DialogController(bundl R.string.download_all ).map { activity.getString(it) } - return MaterialDialog.Builder(activity) + return MaterialDialog(activity) .title(R.string.manga_download) - .negativeText(android.R.string.cancel) - .items(choices) - .itemsCallback { _, _, position, _ -> + .negativeButton(android.R.string.cancel) + .listItems(items = choices){dialog, position, _ -> (targetController as? Listener)?.downloadChapters(position) + dialog.dismiss() } - .build() } interface Listener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadCustomChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadCustomChaptersDialog.kt index 22ddee7bf8..13e2e80f7d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadCustomChaptersDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadCustomChaptersDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.app.Dialog import android.os.Bundle import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.DialogController @@ -55,15 +56,13 @@ class DownloadCustomChaptersDialog : DialogController // Build dialog. // when positive dialog is pressed call custom listener. - return MaterialDialog.Builder(activity) + return MaterialDialog(activity) .title(R.string.custom_download) - .customView(view, true) - .positiveText(android.R.string.ok) - .negativeText(android.R.string.cancel) - .onPositive { _, _ -> + .customView(view = view, scrollable = true) + .positiveButton(android.R.string.ok) { (targetController as? Listener)?.downloadCustomChapters(view.amount) } - .build() + .negativeButton(android.R.string.cancel) } interface Listener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetDisplayModeDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetDisplayModeDialog.kt index 56ce4affef..3f32539049 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetDisplayModeDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetDisplayModeDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.app.Dialog import android.os.Bundle import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga @@ -25,15 +26,12 @@ class SetDisplayModeDialog(bundle: Bundle? = null) : DialogController(bundle) val choices = intArrayOf(R.string.show_title, R.string.show_chapter_number) .map { activity.getString(it) } - return MaterialDialog.Builder(activity) + return MaterialDialog(activity) .title(R.string.action_display_mode) - .items(choices) - .itemsIds(ids) - .itemsCallbackSingleChoice(selectedIndex) { _, itemView, _, _ -> - (targetController as? Listener)?.setDisplayMode(itemView.id) - true + .listItemsSingleChoice(items = choices, initialSelection = selectedIndex) + {_, position, _ -> + (targetController as? Listener)?.setDisplayMode(ids[position]) } - .build() } interface Listener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetSortingDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetSortingDialog.kt index 861afaf1bc..949689be1d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetSortingDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetSortingDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.app.Dialog import android.os.Bundle import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga @@ -25,15 +26,12 @@ class SetSortingDialog(bundle: Bundle? = null) : DialogController(bundle) val choices = intArrayOf(R.string.sort_by_source, R.string.sort_by_number) .map { activity.getString(it) } - return MaterialDialog.Builder(activity) + return MaterialDialog(activity) .title(R.string.sorting_mode) - .items(choices) - .itemsIds(ids) - .itemsCallbackSingleChoice(selectedIndex) { _, itemView, _, _ -> - (targetController as? Listener)?.setSorting(itemView.id) - true + .listItemsSingleChoice(items = choices, initialSelection = selectedIndex){ + _, position, _ -> + (targetController as? Listener)?.setSorting(ids[position]) } - .build() } interface Listener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index cdef034626..fac7f830c2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -21,11 +21,9 @@ import androidx.core.content.pm.ShortcutInfoCompat import androidx.core.content.pm.ShortcutManagerCompat import androidx.core.graphics.drawable.IconCompat import com.afollestad.materialdialogs.MaterialDialog -import com.bumptech.glide.load.DataSource +import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.bumptech.glide.load.engine.DiskCacheStrategy -import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.load.resource.bitmap.RoundedCorners -import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition import com.bumptech.glide.signature.ObjectKey @@ -62,7 +60,6 @@ import eu.kanade.tachiyomi.util.updateLayoutParams import eu.kanade.tachiyomi.util.updatePaddingRelative import jp.wasabeef.glide.transformations.CropSquareTransformation import jp.wasabeef.glide.transformations.MaskTransformation -import kotlinx.android.synthetic.main.catalogue_list_item.* import kotlinx.android.synthetic.main.manga_info_controller.* import uy.kohesive.injekt.injectLazy import java.io.File @@ -554,14 +551,14 @@ class MangaInfoController : NucleusController(), R.string.square_icon, R.string.star_icon) - return MaterialDialog.Builder(activity!!) + return MaterialDialog(activity!!) .title(R.string.icon_shape) - .negativeText(android.R.string.cancel) - .items(modes.map { activity?.getString(it) }) - .itemsCallback { _, _, i, _ -> + .negativeButton(android.R.string.cancel) + .listItemsSingleChoice ( + items = modes.map { activity?.getString(it) as CharSequence }) + { _, i, _ -> (targetController as? MangaInfoController)?.createShortcutForShape(i) } - .build() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt index 59279a2efa..dd3f65d98f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackChaptersDialog.kt @@ -4,6 +4,8 @@ import android.app.Dialog import android.os.Bundle import android.widget.NumberPicker import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView +import com.afollestad.materialdialogs.customview.getCustomView import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track @@ -34,31 +36,25 @@ class SetTrackChaptersDialog : DialogController override fun onCreateDialog(savedViewState: Bundle?): Dialog { val item = item - val dialog = MaterialDialog.Builder(activity!!) - .title(R.string.chapters) - .customView(R.layout.track_chapters_dialog, false) - .positiveText(android.R.string.ok) - .negativeText(android.R.string.cancel) - .onPositive { dialog, _ -> - val view = dialog.customView - if (view != null) { - // Remove focus to update selected number - val np: NumberPicker = view.findViewById(R.id.chapters_picker) - np.clearFocus() + val dialog = MaterialDialog(activity!!) + .title(R.string.chapters) + .customView(viewRes = R.layout.track_chapters_dialog, scrollable = false) + .negativeButton(android.R.string.cancel) + .positiveButton(android.R.string.ok) { dialog -> + val view = dialog.getCustomView() + // Remove focus to update selected number + val np: NumberPicker = view.findViewById(R.id.chapters_picker) + np.clearFocus() + (targetController as? Listener)?.setChaptersRead(item, np.value) + } - (targetController as? Listener)?.setChaptersRead(item, np.value) - } - } - .build() + val view = dialog.getCustomView() + val np: NumberPicker = view.findViewById(R.id.chapters_picker) + // Set initial value + np.value = item.track?.last_chapter_read ?: 0 + // Don't allow to go from 0 to 9999 + np.wrapSelectorWheel = false - val view = dialog.customView - if (view != null) { - val np: NumberPicker = view.findViewById(R.id.chapters_picker) - // Set initial value - np.value = item.track?.last_chapter_read ?: 0 - // Don't allow to go from 0 to 9999 - np.wrapSelectorWheel = false - } return dialog } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt index 382a29a112..6aac10037e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackScoreDialog.kt @@ -4,6 +4,8 @@ import android.app.Dialog import android.os.Bundle import android.widget.NumberPicker import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView +import com.afollestad.materialdialogs.customview.getCustomView import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track @@ -34,36 +36,32 @@ class SetTrackScoreDialog : DialogController override fun onCreateDialog(savedViewState: Bundle?): Dialog { val item = item - val dialog = MaterialDialog.Builder(activity!!) - .title(R.string.score) - .customView(R.layout.track_score_dialog, false) - .positiveText(android.R.string.ok) - .negativeText(android.R.string.cancel) - .onPositive { dialog, _ -> - val view = dialog.customView - if (view != null) { - // Remove focus to update selected number - val np: NumberPicker = view.findViewById(R.id.score_picker) - np.clearFocus() + val dialog = MaterialDialog(activity!!) + .title(R.string.score) + .customView(R.layout.track_score_dialog, scrollable = false) + .negativeButton(android.R.string.cancel) + .positiveButton(android.R.string.ok) { dialog -> + val view = dialog.getCustomView() + // Remove focus to update selected number + val np: NumberPicker = view.findViewById(R.id.score_picker) + np.clearFocus() - (targetController as? Listener)?.setScore(item, np.value) - } - } - .show() + (targetController as? Listener)?.setScore(item, np.value) - val view = dialog.customView - if (view != null) { - val np: NumberPicker = view.findViewById(R.id.score_picker) - val scores = item.service.getScoreList().toTypedArray() - np.maxValue = scores.size - 1 - np.displayedValues = scores - - // Set initial value - val displayedScore = item.service.displayScore(item.track!!) - if (displayedScore != "-") { - val index = scores.indexOf(displayedScore) - np.value = if (index != -1) index else 0 } + + + val view = dialog.getCustomView() + val np: NumberPicker = view.findViewById(R.id.score_picker) + val scores = item.service.getScoreList().toTypedArray() + np.maxValue = scores.size - 1 + np.displayedValues = scores + + // Set initial value + val displayedScore = item.service.displayScore(item.track!!) + if (displayedScore != "-") { + val index = scores.indexOf(displayedScore) + np.value = if (index != -1) index else 0 } return dialog diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt index 8b2f929fcd..535fd744a1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackStatusDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.track import android.app.Dialog import android.os.Bundle import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track @@ -36,15 +37,14 @@ class SetTrackStatusDialog : DialogController val statusString = statusList.mapNotNull { item.service.getStatus(it) } val selectedIndex = statusList.indexOf(item.track?.status) - return MaterialDialog.Builder(activity!!) - .title(R.string.status) - .negativeText(android.R.string.cancel) - .items(statusString) - .itemsCallbackSingleChoice(selectedIndex) { _, _, i, _ -> - (targetController as? Listener)?.setStatus(item, i) - true - } - .build() + return MaterialDialog(activity!!) + .title(R.string.status) + .negativeButton(android.R.string.cancel) + .listItemsSingleChoice(items = statusString, initialSelection = selectedIndex) + { dialog, position, _ -> + (targetController as? Listener)?.setStatus(item, position) + dialog.dismiss() + } } interface Listener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt index f93293812d..e07c682627 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt @@ -4,6 +4,7 @@ import android.app.Dialog import android.os.Bundle import android.view.View import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView import com.jakewharton.rxbinding.widget.itemClicks import com.jakewharton.rxbinding.widget.textChanges import eu.kanade.tachiyomi.R @@ -51,12 +52,10 @@ class TrackSearchDialog : DialogController { } override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val dialog = MaterialDialog.Builder(activity!!) - .customView(R.layout.track_search_dialog, false) - .positiveText(android.R.string.ok) - .negativeText(android.R.string.cancel) - .onPositive { _, _ -> onPositiveButtonClick() } - .build() + val dialog = MaterialDialog(activity!!) + .customView(viewRes = R.layout.track_search_dialog, scrollable = false) + .negativeButton(android.R.string.cancel) + .positiveButton(android.R.string.ok) { onPositiveButtonClick() } if (subscriptions.isUnsubscribed) { subscriptions = CompositeSubscription() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt index ab525375eb..f426763156 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt @@ -105,16 +105,6 @@ class MigrationController : NucleusController(), } } - fun renderIsReplacingManga(state: ViewState) { - if (state.isReplacingManga) { - if (router.getControllerWithTag(LOADING_DIALOG_TAG) == null) { - LoadingController().showDialog(router, LOADING_DIALOG_TAG) - } - } else { - router.popControllerWithTag(LOADING_DIALOG_TAG) - } - } - override fun onItemClick(view: View?, position: Int): Boolean { val item = adapter?.getItem(position) ?: return false @@ -157,22 +147,6 @@ class MigrationController : NucleusController(), presenter.migrateManga(prevManga, manga, replace) return null } - - class LoadingController : DialogController() { - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .progress(true, 0) - .content(R.string.migrating) - .cancelable(false) - .build() - } - } - - companion object { - const val LOADING_DIALOG_TAG = "LoadingDialog" - } - } interface MigrationInterface { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationMangaDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationMangaDialog.kt index ad29b0a015..671a8442c1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationMangaDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationMangaDialog.kt @@ -27,15 +27,13 @@ class MigrationMangaDialog(bundle: Bundle? = null) : DialogController(bundle) if (mangaSkipped > 0) " " + applicationContext?.getString(R.string.skipping_x, mangaSkipped) ?: "" else "")) ?: "" - return MaterialDialog.Builder(activity!!) - .content(confirmString) - .positiveText(android.R.string.yes) - .negativeText(android.R.string.no) - .onPositive { _, _ -> - if (copy) - (targetController as? MigrationListController)?.copyMangas() - else - (targetController as? MigrationListController)?.migrateMangas() - }.show() + return MaterialDialog(activity!!).show { + message(text = confirmString) + positiveButton(android.R.string.yes) { + if (copy) (targetController as? MigrationListController)?.copyMangas() + else (targetController as? MigrationListController)?.migrateMangas() + } + negativeButton(android.R.string.no) + } } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationPresenter.kt index e1a350c1ac..0715ee770d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationPresenter.kt @@ -56,8 +56,8 @@ class MigrationPresenter( .distinctUntilChanged { t1, t2 -> t1.isReplacingManga != t2.isReplacingManga } .subscribeLatestCache(MigrationController::render) - stateRelay.distinctUntilChanged { state -> state.isReplacingManga } - .subscribeLatestCache(MigrationController::renderIsReplacingManga) + /* stateRelay.distinctUntilChanged { state -> state.isReplacingManga } + .subscribeLatestCache(MigrationController::renderIsReplacingManga)*/ } fun setSelectedSource(source: Source) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt index fc4b46c2b0..281ed277d6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt @@ -7,6 +7,7 @@ import android.view.MenuInflater import android.view.MenuItem import androidx.appcompat.widget.SearchView import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItemsMultiChoice import com.jakewharton.rxbinding.support.v7.widget.queryTextChangeEvents import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga @@ -137,27 +138,20 @@ class SearchController( val preselected = MigrationFlags.getEnabledFlagsPositions(prefValue) - return MaterialDialog.Builder(activity!!) - .content(R.string.migration_dialog_what_to_include) - .items(MigrationFlags.titles.map { resources?.getString(it) }) - .alwaysCallMultiChoiceCallback() - .itemsCallbackMultiChoice(preselected.toTypedArray()) { _, positions, _ -> - // Save current settings for the next time - val newValue = MigrationFlags.getFlagsFromPositions(positions) + return MaterialDialog(activity!!) + .message(R.string.migration_dialog_what_to_include) + .listItemsMultiChoice(items = MigrationFlags.titles.map + { resources?.getString(it) as CharSequence }, + initialSelection = preselected.toIntArray()) { _, positions, _ -> + val newValue = MigrationFlags.getFlagsFromPositions(positions.toTypedArray()) preferences.migrateFlags().set(newValue) - - true } - .positiveText(R.string.migrate) - .negativeText(R.string.copy) - .neutralText(android.R.string.cancel) - .onPositive { _, _ -> + .positiveButton(R.string.migrate) { (targetController as? SearchController)?.migrateManga() } - .onNegative { _, _ -> + .negativeButton(R.string.copy) { (targetController as? SearchController)?.copyManga() } - .build() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt index 272d2fb1ee..4293dc39a8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt @@ -113,16 +113,6 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), } } - fun migrationFailure() { - activity?.let { - MaterialDialog.Builder(it) - .title("Migration failure") - .content("An unknown error occured while migrating this manga!") - .positiveText("Ok") - .show() - } - } - suspend fun runMigrations(mangas: List) { val useSourceWithMost = preferences.useSourceWithMost().getOrDefault() @@ -381,14 +371,14 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), override fun handleBack(): Boolean { activity?.let { - MaterialDialog.Builder(it).title(R.string.stop_migration) - .positiveText(R.string.yes) - .negativeText(R.string.no) - .onPositive { _, _ -> + MaterialDialog(it).show { + title(R.string.stop_migration) + positiveButton (R.string.yes) { router.popCurrentController() migrationsJob?.cancel() } - .show() + negativeButton(R.string.no) + } } return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt index 1d70ed08a7..da1acb6a0c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt @@ -44,14 +44,13 @@ class ReaderPageSheet( private fun setAsCover() { if (page.status != Page.READY) return - MaterialDialog.Builder(activity) - .content(activity.getString(R.string.confirm_set_image_as_cover)) - .positiveText(android.R.string.yes) - .negativeText(android.R.string.no) - .onPositive { _, _ -> + MaterialDialog(activity) + .title(R.string.confirm_set_image_as_cover) + .positiveButton(android.R.string.yes) { activity.setAsCover(page) dismiss() } + .negativeButton(android.R.string.no) .show() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/ConfirmDeleteChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/ConfirmDeleteChaptersDialog.kt index 1e6c058dea..c5e8c3bf59 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/ConfirmDeleteChaptersDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/ConfirmDeleteChaptersDialog.kt @@ -18,14 +18,12 @@ class ConfirmDeleteChaptersDialog(bundle: Bundle? = null) : DialogController( } override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .content(R.string.confirm_delete_chapters) - .positiveText(android.R.string.yes) - .negativeText(android.R.string.no) - .onPositive { _, _ -> + return MaterialDialog(activity!!) + .message(R.string.confirm_delete_chapters) + .positiveButton(android.R.string.yes) { (targetController as? Listener)?.deleteChapters(chaptersToDelete) } - .build() + .negativeButton(android.R.string.no) } interface Listener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/DeletingChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/DeletingChaptersDialog.kt deleted file mode 100644 index 4d310c7e30..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/DeletingChaptersDialog.kt +++ /dev/null @@ -1,27 +0,0 @@ -package eu.kanade.tachiyomi.ui.recent_updates - -import android.app.Dialog -import android.os.Bundle -import com.afollestad.materialdialogs.MaterialDialog -import com.bluelinelabs.conductor.Router -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.base.controller.DialogController - -class DeletingChaptersDialog(bundle: Bundle? = null) : DialogController(bundle) { - - companion object { - const val TAG = "deleting_dialog" - } - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .progress(true, 0) - .content(R.string.deleting) - .build() - } - - override fun showDialog(router: Router) { - showDialog(router, TAG) - } - -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt index 9d858a71a9..8ca0d8a25b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt @@ -216,14 +216,13 @@ class RecentChaptersController : NucleusController(), override fun deleteChapters(chaptersToDelete: List) { destroyActionModeIfNeeded() - DeletingChaptersDialog().showDialog(router) presenter.deleteChapters(chaptersToDelete) } /** * Destory [ActionMode] if it's shown */ - fun destroyActionModeIfNeeded() { + private fun destroyActionModeIfNeeded() { actionMode?.finish() } @@ -248,7 +247,6 @@ class RecentChaptersController : NucleusController(), * @param chapter selected chapter with manga */ fun deleteChapter(chapter: RecentChapterItem) { - DeletingChaptersDialog().showDialog(router) presenter.deleteChapters(listOf(chapter)) } @@ -266,7 +264,6 @@ class RecentChaptersController : NucleusController(), * Called when chapters are deleted */ fun onChaptersDeleted() { - dismissDeletingDialog() adapter?.notifyDataSetChanged() } @@ -275,17 +272,9 @@ class RecentChaptersController : NucleusController(), * @param error error message */ fun onChaptersDeletedError(error: Throwable) { - dismissDeletingDialog() Timber.e(error) } - /** - * Called to dismiss deleting dialog - */ - fun dismissDeletingDialog() { - router.popControllerWithTag(DeletingChaptersDialog.TAG) - } - /** * Called when ActionMode created. * @param mode the ActionMode object diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RemoveHistoryDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RemoveHistoryDialog.kt index 8385b4ed43..b0e1202826 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RemoveHistoryDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RemoveHistoryDialog.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.recently_read import android.app.Dialog import android.os.Bundle import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.History @@ -32,13 +33,12 @@ class RemoveHistoryDialog(bundle: Bundle? = null) : DialogController(bundle) setOptionDescription(R.string.dialog_with_checkbox_reset) } - return MaterialDialog.Builder(activity) + return MaterialDialog(activity) .title(R.string.action_remove) - .customView(dialogCheckboxView, true) - .positiveText(R.string.action_remove) - .negativeText(android.R.string.cancel) - .onPositive { _, _ -> onPositive(dialogCheckboxView.isChecked()) } - .build() + .customView(view = dialogCheckboxView, scrollable = true) + .positiveButton(R.string.action_remove) { onPositive(dialogCheckboxView.isChecked + ()) } + .negativeButton(android.R.string.cancel) } private fun onPositive(checked: Boolean) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt index 105af56bd5..4307118ae6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt @@ -128,12 +128,10 @@ class SettingsAboutController : SettingsController() { }) override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) + return MaterialDialog(activity!!) .title(R.string.update_check_title) - .content(args.getString(BODY_KEY) ?: "") - .positiveText(R.string.update_check_confirm) - .negativeText(R.string.update_check_ignore) - .onPositive { _, _ -> + .message(text = args.getString(BODY_KEY) ?: "") + .positiveButton(R.string.update_check_confirm) { val appContext = applicationContext if (appContext != null) { // Start download @@ -141,7 +139,7 @@ class SettingsAboutController : SettingsController() { UpdaterService.downloadUpdate(appContext, url) } } - .build() + .negativeButton(R.string.update_check_ignore) } private companion object { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index 0195f45635..f65bdf3ee7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -84,10 +84,6 @@ class SettingsAdvancedController : SettingsController() { var deletedFiles = 0 - val ctrl = DeletingFilesDialogController() - ctrl.total = files.size - ctrl.showDialog(router) - Observable.defer { Observable.from(files) } .doOnNext { file -> if (chapterCache.removeFileFromCache(file.name)) { @@ -97,61 +93,23 @@ class SettingsAdvancedController : SettingsController() { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ - ctrl.setProgress(deletedFiles) }, { activity?.toast(R.string.cache_delete_error) }, { - ctrl.finish() activity?.toast(resources?.getString(R.string.cache_deleted, deletedFiles)) findPreference(CLEAR_CACHE_KEY)?.summary = resources?.getString(R.string.used_cache, chapterCache.readableSize) }) } - class DeletingFilesDialogController : DialogController() { - - var total = 0 - - private var materialDialog: MaterialDialog? = null - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .title(R.string.deleting) - .progress(false, total, true) - .cancelable(false) - .build() - .also { materialDialog = it } - } - - override fun onDestroyView(view: View) { - super.onDestroyView(view) - materialDialog = null - } - - override fun onRestoreInstanceState(savedInstanceState: Bundle) { - super.onRestoreInstanceState(savedInstanceState) - finish() - } - - fun setProgress(deletedFiles: Int) { - materialDialog?.setProgress(deletedFiles) - } - - fun finish() { - router.popController(this) - } - } - class ClearDatabaseDialogController : DialogController() { override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .content(R.string.clear_database_confirmation) - .positiveText(android.R.string.yes) - .negativeText(android.R.string.no) - .onPositive { _, _ -> + return MaterialDialog(activity!!) + .message(R.string.clear_database_confirmation) + .positiveButton(android.R.string.yes) { (targetController as? SettingsAdvancedController)?.clearDatabase() } - .build() + .negativeButton(android.R.string.no) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index b24500a047..bee201d4fa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -9,6 +9,7 @@ import android.os.Bundle import android.view.View import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItemsMultiChoice import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.backup.BackupConst @@ -168,7 +169,6 @@ class SettingsBackupController : SettingsController() { val file = UniFile.fromUri(activity, uri) - CreatingBackupDialog().showDialog(router, TAG_CREATING_BACKUP_DIALOG) BackupCreateService.makeBackup(activity, file.uri, backupFlags) } CODE_BACKUP_RESTORE -> if (data != null && resultCode == Activity.RESULT_OK) { @@ -207,12 +207,12 @@ class SettingsBackupController : SettingsController() { R.string.track, R.string.history) .map { activity.getString(it) } - return MaterialDialog.Builder(activity) + return MaterialDialog(activity) .title(R.string.pref_create_backup) - .content(R.string.backup_choice) - .items(options) - .itemsDisabledIndices(0) - .itemsCallbackMultiChoice(arrayOf(0, 1, 2, 3, 4)) { _, positions, _ -> + .message(R.string.backup_choice) + .listItemsMultiChoice(items = options, disabledIndices = intArrayOf(0), + initialSelection = intArrayOf(0)) + { _, positions, _ -> var flags = 0 for (i in 1 until positions.size) { when (positions[i]) { @@ -224,27 +224,9 @@ class SettingsBackupController : SettingsController() { } (targetController as? SettingsBackupController)?.createBackup(flags) - true } - .positiveText(R.string.action_create) - .negativeText(android.R.string.cancel) - .build() - } - } - - class CreatingBackupDialog : DialogController() { - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .title(R.string.backup) - .content(R.string.creating_backup) - .progress(true, 0) - .cancelable(false) - .build() - } - - override fun onRestoreInstanceState(savedInstanceState: Bundle) { - super.onRestoreInstanceState(savedInstanceState) - router.popController(this) + .positiveButton(R.string.action_create) + .negativeButton(android.R.string.cancel) } } @@ -256,18 +238,16 @@ class SettingsBackupController : SettingsController() { override fun onCreateDialog(savedViewState: Bundle?): Dialog { val activity = activity!! val unifile = UniFile.fromUri(activity, args.getParcelable(KEY_URI)) - return MaterialDialog.Builder(activity) + return MaterialDialog(activity) .title(R.string.backup_created) - .content(activity.getString(R.string.file_saved, unifile.filePath)) - .positiveText(R.string.action_close) - .negativeText(R.string.action_export) - .onNegative { _, _ -> + .message(R.string.file_saved, unifile.filePath) + .positiveButton(R.string.action_close) + .negativeButton(R.string.action_export) { val sendIntent = Intent(Intent.ACTION_SEND) sendIntent.type = "application/json" sendIntent.putExtra(Intent.EXTRA_STREAM, unifile.uri) startActivity(Intent.createChooser(sendIntent, "")) } - .build() } private companion object { @@ -281,18 +261,16 @@ class SettingsBackupController : SettingsController() { }) override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) + return MaterialDialog(activity!!) .title(R.string.pref_restore_backup) - .content(R.string.backup_restore_content) - .positiveText(R.string.action_restore) - .onPositive { _, _ -> + .message(R.string.backup_restore_content) + .positiveButton(R.string.action_restore) { val context = applicationContext if (context != null) { activity?.toast(R.string.restoring_backup) BackupRestoreService.start(context, args.getParcelable(KEY_URI)!!) } } - .build() } private companion object { @@ -300,102 +278,6 @@ class SettingsBackupController : SettingsController() { } } - class RestoringBackupDialog : DialogController() { - private var materialDialog: MaterialDialog? = null - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .title(R.string.backup) - .content(R.string.restoring_backup) - .progress(false, 100, true) - .cancelable(false) - .negativeText(R.string.action_stop) - .onNegative { _, _ -> - applicationContext?.let { BackupRestoreService.stop(it) } - } - .build() - .also { materialDialog = it } - } - - override fun onDestroyView(view: View) { - super.onDestroyView(view) - materialDialog = null - } - - override fun onRestoreInstanceState(savedInstanceState: Bundle) { - super.onRestoreInstanceState(savedInstanceState) - router.popController(this) - } - - fun updateProgress(content: String?, progress: Int, amount: Int) { - val dialog = materialDialog ?: return - dialog.setContent(content) - dialog.setProgress(progress) - dialog.maxProgress = amount - } - } - - class RestoredBackupDialog(bundle: Bundle? = null) : DialogController(bundle) { - constructor(time: Long, errorCount: Int, path: String, file: String, errors: String) : this - (Bundle().apply { - putLong(KEY_TIME, time) - putInt(KEY_ERROR_COUNT, errorCount) - putString(KEY_PATH, path) - putString(KEY_FILE, file) - putString(KEY_MINI_ERRORS, errors) - }) - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val activity = activity!! - val time = args.getLong(KEY_TIME) - val errors = args.getInt(KEY_ERROR_COUNT) - val path = args.getString(KEY_PATH) - val file = args.getString(KEY_FILE) - val miniErrors = args.getString(KEY_MINI_ERRORS) - val timeString = String.format("%02d min, %02d sec", - TimeUnit.MILLISECONDS.toMinutes(time), - TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds( - TimeUnit.MILLISECONDS.toMinutes(time)) - ) - - var errorString = activity.getString(R.string.restore_completed_content, timeString, - if (errors > 0) "$errors" else activity.getString(android.R.string - .no)) - if (errors > 0) - errorString = errorString.trimEnd('.') + ":" - - return MaterialDialog.Builder(activity) - .title(R.string.restore_completed) - .content("$errorString\n$miniErrors") - .positiveText(R.string.action_close) - .negativeText(R.string.action_open_log) - .onNegative { _, _ -> - val context = applicationContext ?: return@onNegative - if (!path.isNullOrEmpty()) { - val destFile = File(path, file) - val uri = destFile.getUriCompat(context) - val sendIntent = Intent(Intent.ACTION_VIEW).apply { - setDataAndType(uri, "text/plain") - flags = Intent.FLAG_ACTIVITY_NEW_TASK or - Intent.FLAG_GRANT_READ_URI_PERMISSION - } - startActivity(sendIntent) - } else { - context.toast(context.getString(R.string.error_opening_log)) - } - } - .build() - } - - private companion object { - const val KEY_TIME = "RestoredBackupDialog.time" - const val KEY_ERROR_COUNT = "RestoredBackupDialog.errors" - const val KEY_PATH = "RestoredBackupDialog.path" - const val KEY_FILE = "RestoredBackupDialog.file" - const val KEY_MINI_ERRORS = "RestoredBackupDialog.miniErrors" - } - } - inner class BackupBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { when (intent.getStringExtra(BackupConst.ACTION)) { @@ -404,24 +286,6 @@ class SettingsBackupController : SettingsController() { val uri = Uri.parse(intent.getStringExtra(BackupConst.EXTRA_URI)) CreatedBackupDialog(uri).showDialog(router) } - BackupConst.ACTION_SET_PROGRESS_DIALOG -> { - val progress = intent.getIntExtra(BackupConst.EXTRA_PROGRESS, 0) - val amount = intent.getIntExtra(BackupConst.EXTRA_AMOUNT, 0) - val content = intent.getStringExtra(BackupConst.EXTRA_CONTENT) - (router.getControllerWithTag(TAG_RESTORING_BACKUP_DIALOG) - as? RestoringBackupDialog)?.updateProgress(content, progress, amount) - } - BackupConst.ACTION_RESTORE_COMPLETED_DIALOG -> { - router.popControllerWithTag(TAG_RESTORING_BACKUP_DIALOG) - val time = intent.getLongExtra(BackupConst.EXTRA_TIME, 0) - val errors = intent.getIntExtra(BackupConst.EXTRA_ERRORS, 0) - val path = intent.getStringExtra(BackupConst.EXTRA_ERROR_FILE_PATH) - val file = intent.getStringExtra(BackupConst.EXTRA_ERROR_FILE) - val miniErrors = intent.getStringExtra(BackupConst.EXTRA_MINI_ERROR) - if (errors > 0) { - RestoredBackupDialog(time, errors, path, file, miniErrors).showDialog(router) - } - } BackupConst.ACTION_ERROR_BACKUP_DIALOG -> { router.popControllerWithTag(TAG_CREATING_BACKUP_DIALOG) context.toast(intent.getStringExtra(BackupConst.EXTRA_ERROR_MESSAGE)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt index 51e313e3c9..41499ef175 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt @@ -10,6 +10,7 @@ import android.os.Environment import androidx.core.content.ContextCompat import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper @@ -147,18 +148,16 @@ class SettingsDownloadController : SettingsController() { val externalDirs = getExternalDirs() + File(activity.getString(R.string.custom_dir)) val selectedIndex = externalDirs.map(File::toString).indexOfFirst { it in currentDir } - return MaterialDialog.Builder(activity) - .items(externalDirs) - .itemsCallbackSingleChoice(selectedIndex) { _, _, which, text -> - val target = targetController as? SettingsDownloadController - if (which == externalDirs.lastIndex) { - target?.customDirectorySelected(currentDir) - } else { - target?.predefinedDirectorySelected(text.toString()) - } - true + return MaterialDialog(activity) + .listItemsSingleChoice(items = externalDirs.map { it.path }, initialSelection = selectedIndex) + { _, position, text -> + val target = targetController as? SettingsDownloadController + if (position == externalDirs.lastIndex) { + target?.customDirectorySelected(currentDir) + } else { + target?.predefinedDirectorySelected(text.toString()) } - .build() + } } private fun getExternalDirs(): List { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 21f2433119..539d1c03ed 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -7,6 +7,7 @@ import android.view.View import androidx.biometric.BiometricManager import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category @@ -186,16 +187,14 @@ class SettingsLibraryController : SettingsController() { private var landscape = preferences.landscapeColumns().getOrDefault() override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val dialog = MaterialDialog.Builder(activity!!) + val dialog = MaterialDialog(activity!!) .title(R.string.pref_library_columns) - .customView(R.layout.pref_library_columns, false) - .positiveText(android.R.string.ok) - .negativeText(android.R.string.cancel) - .onPositive { _, _ -> + .customView(viewRes = R.layout.pref_library_columns, scrollable = false) + .positiveButton(android.R.string.ok) { preferences.portraitColumns().set(portrait) preferences.landscapeColumns().set(landscape) } - .build() + .negativeButton(android.R.string.cancel) onViewCreated(dialog.view) return dialog diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt index 25e99ef286..986859f169 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.text.method.PasswordTransformationMethod import android.view.View import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.dd.processbutton.iml.ActionProcessButton @@ -26,10 +27,9 @@ abstract class LoginDialogPreference(bundle: Bundle? = null) : DialogController( var requestSubscription: Subscription? = null override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val dialog = MaterialDialog.Builder(activity!!) - .customView(R.layout.pref_account_login, false) - .negativeText(android.R.string.cancel) - .build() + val dialog = MaterialDialog(activity!!) + .customView(R.layout.pref_account_login, scrollable = false) + .negativeButton(android.R.string.cancel) onViewCreated(dialog.view) diff --git a/app/src/main/res/values-ca/strings.xml b/app/src/main/res/values-ca/strings.xml index f2b6152438..be0984350b 100644 --- a/app/src/main/res/values-ca/strings.xml +++ b/app/src/main/res/values-ca/strings.xml @@ -242,7 +242,7 @@ S\'està restaurant la còpia de seguretat S\'està creant la còpia de seguretat Buida la memòria cau de capítols - Ús: $1$s + Ús: %1$s S\'ha buidat la memòria cau. S\'han suprimit %1$d fitxers S\'ha produït un error en buidar la memòria cau Esborra les galetes diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index afb7b4195a..db6bf7ddb1 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -20,7 +20,6 @@ @style/ThemeOverlay.AppCompat.Dark.ActionBar @style/ThemeOverlay.AppCompat @style/PreferenceThemeOverlay.v14.Material - @color/dialogDark @style/Theme.AlertDialog.Dark @android:color/transparent @@ -35,6 +34,14 @@ @color/snackbarBackground @color/textColorPrimaryLight @color/oldNavBarBackground + + + + @color/textColorPrimaryDark + @color/textColorSecondaryDark + @color/colorAccentDark + @color/dialogDark + 16dp \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 7a0f5e0e6b..92a15d2dff 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -28,7 +28,6 @@ @style/Theme.ActionBar.Light @style/PreferenceThemeOverlay.v14.Material @style/Theme.AlertDialog.Light - @color/dialogLight @@ -43,6 +42,13 @@ @android:color/transparent #B3000000 + + + @color/textColorPrimaryLight + @color/textColorSecondaryLight + @color/colorAccent + @color/dialogLight + 16dp