From ddf0357c5cb1c7490babf695bcb14eb52b35ac23 Mon Sep 17 00:00:00 2001 From: Jobobby04 Date: Sun, 26 Apr 2020 14:59:28 -0400 Subject: [PATCH] Material Dialogs Eh Part 1 --- .../ui/migration/MigrationMangaDialog.kt | 11 ++++--- .../manga/process/MigrationListController.kt | 7 ++--- .../ui/setting/SettingsEhController.kt | 30 +++++++++---------- .../exh/favorites/FavoritesIntroDialog.kt | 9 +++--- .../uconfig/ConfiguringDialogController.kt | 17 +++++------ .../uconfig/WarnConfigureDialogController.kt | 12 ++++---- .../exh/ui/batchadd/BatchAddController.kt | 11 ++++--- .../exh/ui/captcha/BrowserActionActivity.kt | 10 +++---- .../java/exh/ui/lock/FingerLockPreference.kt | 26 ++++++++-------- .../main/java/exh/ui/lock/LockController.kt | 22 +++++++------- .../main/java/exh/ui/lock/LockPreference.kt | 27 ++++++++--------- app/src/main/java/exh/ui/lock/LockUtils.kt | 23 +++++++------- app/src/main/res/values/strings.xml | 10 ++++++- 13 files changed, 104 insertions(+), 111 deletions(-) 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 6bb8d0854..0dc900673 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,14 @@ class MigrationMangaDialog(bundle: Bundle? = null) : DialogController(bundle) mangaSet, ( if (mangaSkipped > 0) " " + applicationContext?.getString(R.string.skipping_, mangaSkipped) else "")) ?: "" - return MaterialDialog.Builder(activity!!) - .content(confirmString) - .positiveText(if (copy) R.string.copy else R.string.migrate) - .negativeText(android.R.string.no) - .onPositive { _, _ -> + return MaterialDialog(activity!!) + .message(text = confirmString) + .positiveButton(if (copy) R.string.copy else R.string.migrate) { if (copy) (targetController as? MigrationListController)?.copyMangas() else (targetController as? MigrationListController)?.migrateMangas() - }.show() + } + .negativeButton(android.R.string.no) } } 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 2bfdce489..1f8ee6d57 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 @@ -419,13 +419,12 @@ class MigrationListController(bundle: Bundle? = null) : BaseController + MaterialDialog(it).title(R.string.stop_migrating) + .positiveButton(R.string.action_stop) { router.popCurrentController() migrationsJob?.cancel() } + .negativeButton(android.R.string.cancel) .show() } return true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsEhController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsEhController.kt index 51ce67c65..ead03de67 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsEhController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsEhController.kt @@ -200,12 +200,11 @@ class SettingsEhController : SettingsController() { summary = "Performs a full resynchronization on the next sync. Removals will not be synced. All favorites in the app will be re-uploaded to ExHentai and all favorites on ExHentai will be re-downloaded into the app. Useful for repairing sync after sync has been interrupted." onClick { - activity?.let { - MaterialDialog.Builder(it) - .title("Are you sure?") - .content("Resetting the sync state can cause your next sync to be extremely slow.") - .positiveText("Yes") - .onPositive { _, _ -> + activity?.let { activity -> + MaterialDialog(activity) + .title(R.string.eh_force_sync_reset_title) + .message(R.string.eh_force_sync_reset_message) + .positiveButton(android.R.string.yes) { LocalFavoritesStorage().apply { getRealm().use { it.trans { @@ -213,9 +212,9 @@ class SettingsEhController : SettingsController() { } } } - it.toast("Sync state reset", Toast.LENGTH_LONG) + activity.toast("Sync state reset", Toast.LENGTH_LONG) } - .negativeText("No") + .negativeButton(android.R.string.no) .cancelable(false) .show() } @@ -281,11 +280,10 @@ class SettingsEhController : SettingsController() { title = "Show updater statistics" onClick { - val progress = MaterialDialog.Builder(context) - .progress(true, 0) - .content("Collecting statistics...") + val progress = MaterialDialog(context) + .message(R.string.eh_show_update_statistics_dialog) .cancelable(false) - .show() + progress.show() GlobalScope.launch(Dispatchers.IO) { val updateInfo = try { @@ -330,10 +328,10 @@ class SettingsEhController : SettingsController() { } withContext(Dispatchers.Main) { - MaterialDialog.Builder(context) - .title("Gallery updater statistics") - .content(updateInfo) - .positiveText("Ok") + MaterialDialog(context) + .title(text = "Gallery updater statistics") + .message(text = updateInfo) + .positiveButton(android.R.string.ok) .show() } } diff --git a/app/src/main/java/exh/favorites/FavoritesIntroDialog.kt b/app/src/main/java/exh/favorites/FavoritesIntroDialog.kt index ebc3fef36..c63cfa4e8 100644 --- a/app/src/main/java/exh/favorites/FavoritesIntroDialog.kt +++ b/app/src/main/java/exh/favorites/FavoritesIntroDialog.kt @@ -9,11 +9,10 @@ import uy.kohesive.injekt.injectLazy class FavoritesIntroDialog { private val prefs: PreferencesHelper by injectLazy() - fun show(context: Context) = MaterialDialog.Builder(context) - .title("IMPORTANT FAVORITES SYNC NOTES") - .content(HtmlCompat.fromHtml(FAVORITES_INTRO_TEXT, HtmlCompat.FROM_HTML_MODE_LEGACY)) - .positiveText("Ok") - .onPositive { _, _ -> + fun show(context: Context) = MaterialDialog(context) + .title(text = "IMPORTANT FAVORITES SYNC NOTES") + .message(text = HtmlCompat.fromHtml(FAVORITES_INTRO_TEXT, HtmlCompat.FROM_HTML_MODE_LEGACY)) + .positiveButton(android.R.string.ok) { prefs.eh_showSyncIntro().set(false) } .cancelable(false) diff --git a/app/src/main/java/exh/uconfig/ConfiguringDialogController.kt b/app/src/main/java/exh/uconfig/ConfiguringDialogController.kt index 61922b59b..3eec944e8 100644 --- a/app/src/main/java/exh/uconfig/ConfiguringDialogController.kt +++ b/app/src/main/java/exh/uconfig/ConfiguringDialogController.kt @@ -24,10 +24,10 @@ class ConfiguringDialogController : DialogController() { } catch (e: Exception) { activity?.let { it.runOnUiThread { - MaterialDialog.Builder(it) - .title("Configuration failed!") - .content("An error occurred during the configuration process: " + e.message) - .positiveText("Ok") + MaterialDialog(it) + .title(text = "Configuration failed!") + .message(text = "An error occurred during the configuration process: " + e.message) + .positiveButton(android.R.string.ok) .show() } } @@ -38,12 +38,11 @@ class ConfiguringDialogController : DialogController() { } } - return MaterialDialog.Builder(activity!!) - .title("Uploading settings to server") - .content("Please wait, this may take some time...") - .progress(true, 0) + return MaterialDialog(activity!!) + .title(text = "Uploading settings to server") + .message(text = "Please wait, this may take some time...") .cancelable(false) - .build().also { + .also { materialDialog = it } } diff --git a/app/src/main/java/exh/uconfig/WarnConfigureDialogController.kt b/app/src/main/java/exh/uconfig/WarnConfigureDialogController.kt index 0bf116d75..7029e0c90 100644 --- a/app/src/main/java/exh/uconfig/WarnConfigureDialogController.kt +++ b/app/src/main/java/exh/uconfig/WarnConfigureDialogController.kt @@ -12,21 +12,19 @@ import uy.kohesive.injekt.injectLazy class WarnConfigureDialogController : DialogController() { private val prefs: PreferencesHelper by injectLazy() - override fun onCreateDialog(savedState: Bundle?): Dialog { - return MaterialDialog.Builder(activity!!) - .title("Settings profile note") - .content(""" + override fun onCreateDialog(savedViewState: Bundle?): Dialog { + return MaterialDialog(activity!!) + .title(text = "Settings profile note") + .message(text = """ The app will now add a new settings profile on E-Hentai and ExHentai to optimize app performance. Please ensure that you have less than three profiles on both sites. If you have no idea what settings profiles are, then it probably doesn't matter, just hit 'OK'. """.trimIndent()) - .positiveText(android.R.string.ok) - .onPositive { _, _ -> + .positiveButton(android.R.string.ok) { prefs.eh_showSettingsUploadWarning().set(false) ConfiguringDialogController().showDialog(router) } .cancelable(false) - .build() } companion object { diff --git a/app/src/main/java/exh/ui/batchadd/BatchAddController.kt b/app/src/main/java/exh/ui/batchadd/BatchAddController.kt index adca4eade..d2b9aeeb0 100755 --- a/app/src/main/java/exh/ui/batchadd/BatchAddController.kt +++ b/app/src/main/java/exh/ui/batchadd/BatchAddController.kt @@ -143,13 +143,12 @@ class BatchAddController : NucleusController materialDialog.dismiss() } + MaterialDialog(it) + .title(text = "No galleries to add!") + .message(text = "You must specify at least one gallery to add!") + .positiveButton(android.R.string.ok) { materialDialog -> materialDialog.dismiss() } .cancelable(true) - .canceledOnTouchOutside(true) + .cancelOnTouchOutside(true) .show() } } diff --git a/app/src/main/java/exh/ui/captcha/BrowserActionActivity.kt b/app/src/main/java/exh/ui/captcha/BrowserActionActivity.kt index acb292576..006ae249e 100644 --- a/app/src/main/java/exh/ui/captcha/BrowserActionActivity.kt +++ b/app/src/main/java/exh/ui/captcha/BrowserActionActivity.kt @@ -175,12 +175,12 @@ class BrowserActionActivity : AppCompatActivity() { Timber.e(IllegalStateException("Captcha solve failure!")) runOnUiThread { webview.evaluateJavascript(SOLVE_UI_SCRIPT_HIDE, null) - MaterialDialog.Builder(this) - .title("Captcha solve failure") - .content("Failed to auto-solve the captcha!") + MaterialDialog(this) + .title(text = "Captcha solve failure") + .message(text = "Failed to auto-solve the captcha!") .cancelable(true) - .canceledOnTouchOutside(true) - .positiveText("Ok") + .cancelOnTouchOutside(true) + .positiveButton(android.R.string.ok) .show() } } diff --git a/app/src/main/java/exh/ui/lock/FingerLockPreference.kt b/app/src/main/java/exh/ui/lock/FingerLockPreference.kt index 6abba875b..9885d0f4a 100644 --- a/app/src/main/java/exh/ui/lock/FingerLockPreference.kt +++ b/app/src/main/java/exh/ui/lock/FingerLockPreference.kt @@ -11,10 +11,12 @@ import android.widget.TextView import androidx.appcompat.widget.LinearLayoutCompat import androidx.preference.SwitchPreferenceCompat import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView import com.github.ajalt.reprint.core.AuthenticationResult import com.github.ajalt.reprint.core.Reprint import com.github.ajalt.reprint.rxjava.RxReprint import com.mattprecious.swirl.SwirlView +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.preference.onChange @@ -106,14 +108,13 @@ class FingerLockPreference @JvmOverloads constructor(context: Context, attrs: At addView(statusTextView) addView(iconView) } - val dialog = MaterialDialog.Builder(context) - .title("Fingerprint verification") - .customView(linearLayout, false) - .negativeText("Cancel") - .autoDismiss(true) + val dialog = MaterialDialog(context) + .title(text = "Fingerprint verification") + .customView(view = linearLayout) + .negativeButton(R.string.action_cancel) .cancelable(true) - .canceledOnTouchOutside(true) - .show() + .cancelOnTouchOutside(true) + dialog.show() iconView.setState(SwirlView.State.ON) val subscription = RxReprint.authenticate() .observeOn(AndroidSchedulers.mainThread()) @@ -130,13 +131,12 @@ class FingerLockPreference @JvmOverloads constructor(context: Context, attrs: At statusTextView.text = result.errorMessage } AuthenticationResult.Status.FATAL_FAILURE, null -> { - MaterialDialog.Builder(context) - .title("Fingerprint verification failed!") - .content(result.errorMessage) - .positiveText("Ok") - .autoDismiss(true) + MaterialDialog(context) + .title(text = "Fingerprint verification failed!") + .message(text = result.errorMessage) + .positiveButton(android.R.string.ok) .cancelable(true) - .canceledOnTouchOutside(false) + .cancelOnTouchOutside(false) .show() dialog.dismiss() } diff --git a/app/src/main/java/exh/ui/lock/LockController.kt b/app/src/main/java/exh/ui/lock/LockController.kt index ea5b8b72e..6641ef5d0 100755 --- a/app/src/main/java/exh/ui/lock/LockController.kt +++ b/app/src/main/java/exh/ui/lock/LockController.kt @@ -52,13 +52,12 @@ class LockController : NucleusController() { // Yay! closeLock() } else { - MaterialDialog.Builder(context) - .title("PIN code incorrect") - .content("The PIN code you entered is incorrect. Please try again.") + MaterialDialog(context) + .title(text = "PIN code incorrect") + .message(text = "The PIN code you entered is incorrect. Please try again.") .cancelable(true) - .canceledOnTouchOutside(true) - .positiveText("Ok") - .autoDismiss(true) + .cancelOnTouchOutside(true) + .positiveButton(android.R.string.ok) .show() binding.pinLockView.resetPinLockView() } @@ -105,13 +104,12 @@ class LockController : NucleusController() { AuthenticationResult.Status.SUCCESS -> closeLock() AuthenticationResult.Status.NONFATAL_FAILURE -> icon.setState(SwirlView.State.ERROR) AuthenticationResult.Status.FATAL_FAILURE, null -> { - MaterialDialog.Builder(context) - .title("Fingerprint error!") - .content(it.errorMessage) + MaterialDialog(context) + .title(text = "Fingerprint error!") + .message(text = it.errorMessage) .cancelable(false) - .canceledOnTouchOutside(false) - .positiveText("Ok") - .autoDismiss(true) + .cancelOnTouchOutside(false) + .positiveButton(android.R.string.ok) .show() icon.setState(SwirlView.State.OFF) } diff --git a/app/src/main/java/exh/ui/lock/LockPreference.kt b/app/src/main/java/exh/ui/lock/LockPreference.kt index b75562093..d8c299441 100755 --- a/app/src/main/java/exh/ui/lock/LockPreference.kt +++ b/app/src/main/java/exh/ui/lock/LockPreference.kt @@ -5,6 +5,7 @@ import android.text.InputType import android.util.AttributeSet import androidx.preference.SwitchPreferenceCompat import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.input.input import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.preference.onChange @@ -44,17 +45,16 @@ class LockPreference @JvmOverloads constructor(context: Context, attrs: Attribut fun tryChange() { if (!notifyLockSecurity(context)) { - MaterialDialog.Builder(context) - .title("Lock application") - .content("Enter a pin to lock the application. Enter nothing to disable the pin lock.") - .inputRangeRes(0, 10, R.color.material_red_500) - .inputType(InputType.TYPE_CLASS_NUMBER) - .input("", "", { _, c -> - val progressDialog = MaterialDialog.Builder(context) - .title("Saving password") - .progress(true, 0) + MaterialDialog(context) + .title(text = "Lock application") + .message(text = "Enter a pin to lock the application. Enter nothing to disable the pin lock.") + // .inputRangeRes(0, 10, R.color.material_red_500) + // .inputType(InputType.TYPE_CLASS_NUMBER) + .input(maxLength = 10, inputType = InputType.TYPE_CLASS_NUMBER, allowEmpty = true) { _, c -> + val progressDialog = MaterialDialog(context) + .title(text = "Saving password") .cancelable(false) - .show() + progressDialog.show() Observable.fromCallable { savePassword(c.toString()) }.subscribeOn(Schedulers.computation()) @@ -63,11 +63,10 @@ class LockPreference @JvmOverloads constructor(context: Context, attrs: Attribut progressDialog.dismiss() updateSummary() } - }) - .negativeText("Cancel") - .autoDismiss(true) + } + .negativeButton(R.string.action_cancel) .cancelable(true) - .canceledOnTouchOutside(true) + .cancelOnTouchOutside(true) .show() } } diff --git a/app/src/main/java/exh/ui/lock/LockUtils.kt b/app/src/main/java/exh/ui/lock/LockUtils.kt index dcfc1dd45..e17f2a0e6 100755 --- a/app/src/main/java/exh/ui/lock/LockUtils.kt +++ b/app/src/main/java/exh/ui/lock/LockUtils.kt @@ -54,30 +54,27 @@ fun notifyLockSecurity( return false if (!prefs.eh_lockManually().getOrDefault() && !hasAccessToUsageStats(context)) { - MaterialDialog.Builder(context) - .title("Permission required") - .content("${context.getString(R.string.app_name)} requires the usage stats permission to detect when you leave the app. " + + MaterialDialog(context) + .title(text = "Permission required") + .message(text = "${context.getString(R.string.app_name)} requires the usage stats permission to detect when you leave the app. " + "This is required for the application lock to function properly. " + "Press OK to grant this permission now.") - .negativeText("Cancel") - .positiveText("Ok") - .onPositive { _, _ -> + .negativeButton(R.string.action_cancel) + .positiveButton(android.R.string.ok) { try { context.startActivity(Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)) } catch (e: ActivityNotFoundException) { XLog.e("Device does not support USAGE_ACCESS_SETTINGS shortcut!") - MaterialDialog.Builder(context) - .title("Grant permission manually") - .content("Failed to launch the window used to grant the usage stats permission. " + + MaterialDialog(context) + .title(text = "Grant permission manually") + .message(text = "Failed to launch the window used to grant the usage stats permission. " + "You can still grant this permission manually: go to your phone's settings and search for 'usage access'.") - .positiveText("Ok") - .onPositive { dialog, _ -> dialog.dismiss() } + .positiveButton(android.R.string.ok) { it.dismiss() } .cancelable(true) - .canceledOnTouchOutside(false) + .cancelOnTouchOutside(false) .show() } } - .autoDismiss(true) .cancelable(false) .show() return true diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4bd73fdbe..ea6454c1e 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -710,6 +710,14 @@ The level of radius that the corners are rounded to. Current value is: %s Merge with current Merge With Another - + Autoscroll help + Automatically scroll to the next page in the specified interval. Interval is specified in seconds. + Retry all help + Re-add all failed pages to the download queue. + Boost page help + Normally the downloader can only download a specific amount of pages at the same time. This means you can be waiting for a page to download but the downloader will not start downloading the page until it has a free download slot. Pressing \'Boost page\' will force the downloader to begin downloading the current page, regardless of whether or not there is an available slot. + Are you sure? + Resetting the sync state can cause your next sync to be extremely slow. + Collecting statistics…