Material Dialogs Eh Part 1

This commit is contained in:
Jobobby04 2020-04-26 14:59:28 -04:00
parent 800c01ea42
commit ddf0357c5c
13 changed files with 104 additions and 111 deletions

View File

@ -27,15 +27,14 @@ class MigrationMangaDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
mangaSet, ( mangaSet, (
if (mangaSkipped > 0) " " + applicationContext?.getString(R.string.skipping_, mangaSkipped) if (mangaSkipped > 0) " " + applicationContext?.getString(R.string.skipping_, mangaSkipped)
else "")) ?: "" else "")) ?: ""
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.content(confirmString) .message(text = confirmString)
.positiveText(if (copy) R.string.copy else R.string.migrate) .positiveButton(if (copy) R.string.copy else R.string.migrate) {
.negativeText(android.R.string.no)
.onPositive { _, _ ->
if (copy) if (copy)
(targetController as? MigrationListController)?.copyMangas() (targetController as? MigrationListController)?.copyMangas()
else else
(targetController as? MigrationListController)?.migrateMangas() (targetController as? MigrationListController)?.migrateMangas()
}.show() }
.negativeButton(android.R.string.no)
} }
} }

View File

@ -419,13 +419,12 @@ class MigrationListController(bundle: Bundle? = null) : BaseController<Migration
override fun handleBack(): Boolean { override fun handleBack(): Boolean {
activity?.let { activity?.let {
MaterialDialog.Builder(it).title(R.string.stop_migrating) MaterialDialog(it).title(R.string.stop_migrating)
.positiveText(R.string.action_stop) .positiveButton(R.string.action_stop) {
.negativeText(android.R.string.cancel)
.onPositive { _, _ ->
router.popCurrentController() router.popCurrentController()
migrationsJob?.cancel() migrationsJob?.cancel()
} }
.negativeButton(android.R.string.cancel)
.show() .show()
} }
return true return true

View File

@ -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." 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 { onClick {
activity?.let { activity?.let { activity ->
MaterialDialog.Builder(it) MaterialDialog(activity)
.title("Are you sure?") .title(R.string.eh_force_sync_reset_title)
.content("Resetting the sync state can cause your next sync to be extremely slow.") .message(R.string.eh_force_sync_reset_message)
.positiveText("Yes") .positiveButton(android.R.string.yes) {
.onPositive { _, _ ->
LocalFavoritesStorage().apply { LocalFavoritesStorage().apply {
getRealm().use { getRealm().use {
it.trans { 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) .cancelable(false)
.show() .show()
} }
@ -281,11 +280,10 @@ class SettingsEhController : SettingsController() {
title = "Show updater statistics" title = "Show updater statistics"
onClick { onClick {
val progress = MaterialDialog.Builder(context) val progress = MaterialDialog(context)
.progress(true, 0) .message(R.string.eh_show_update_statistics_dialog)
.content("Collecting statistics...")
.cancelable(false) .cancelable(false)
.show() progress.show()
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
val updateInfo = try { val updateInfo = try {
@ -330,10 +328,10 @@ class SettingsEhController : SettingsController() {
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
MaterialDialog.Builder(context) MaterialDialog(context)
.title("Gallery updater statistics") .title(text = "Gallery updater statistics")
.content(updateInfo) .message(text = updateInfo)
.positiveText("Ok") .positiveButton(android.R.string.ok)
.show() .show()
} }
} }

View File

@ -9,11 +9,10 @@ import uy.kohesive.injekt.injectLazy
class FavoritesIntroDialog { class FavoritesIntroDialog {
private val prefs: PreferencesHelper by injectLazy() private val prefs: PreferencesHelper by injectLazy()
fun show(context: Context) = MaterialDialog.Builder(context) fun show(context: Context) = MaterialDialog(context)
.title("IMPORTANT FAVORITES SYNC NOTES") .title(text = "IMPORTANT FAVORITES SYNC NOTES")
.content(HtmlCompat.fromHtml(FAVORITES_INTRO_TEXT, HtmlCompat.FROM_HTML_MODE_LEGACY)) .message(text = HtmlCompat.fromHtml(FAVORITES_INTRO_TEXT, HtmlCompat.FROM_HTML_MODE_LEGACY))
.positiveText("Ok") .positiveButton(android.R.string.ok) {
.onPositive { _, _ ->
prefs.eh_showSyncIntro().set(false) prefs.eh_showSyncIntro().set(false)
} }
.cancelable(false) .cancelable(false)

View File

@ -24,10 +24,10 @@ class ConfiguringDialogController : DialogController() {
} catch (e: Exception) { } catch (e: Exception) {
activity?.let { activity?.let {
it.runOnUiThread { it.runOnUiThread {
MaterialDialog.Builder(it) MaterialDialog(it)
.title("Configuration failed!") .title(text = "Configuration failed!")
.content("An error occurred during the configuration process: " + e.message) .message(text = "An error occurred during the configuration process: " + e.message)
.positiveText("Ok") .positiveButton(android.R.string.ok)
.show() .show()
} }
} }
@ -38,12 +38,11 @@ class ConfiguringDialogController : DialogController() {
} }
} }
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.title("Uploading settings to server") .title(text = "Uploading settings to server")
.content("Please wait, this may take some time...") .message(text = "Please wait, this may take some time...")
.progress(true, 0)
.cancelable(false) .cancelable(false)
.build().also { .also {
materialDialog = it materialDialog = it
} }
} }

View File

@ -12,21 +12,19 @@ import uy.kohesive.injekt.injectLazy
class WarnConfigureDialogController : DialogController() { class WarnConfigureDialogController : DialogController() {
private val prefs: PreferencesHelper by injectLazy() private val prefs: PreferencesHelper by injectLazy()
override fun onCreateDialog(savedState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.title("Settings profile note") .title(text = "Settings profile note")
.content(""" .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. 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'. If you have no idea what settings profiles are, then it probably doesn't matter, just hit 'OK'.
""".trimIndent()) """.trimIndent())
.positiveText(android.R.string.ok) .positiveButton(android.R.string.ok) {
.onPositive { _, _ ->
prefs.eh_showSettingsUploadWarning().set(false) prefs.eh_showSettingsUploadWarning().set(false)
ConfiguringDialogController().showDialog(router) ConfiguringDialogController().showDialog(router)
} }
.cancelable(false) .cancelable(false)
.build()
} }
companion object { companion object {

View File

@ -143,13 +143,12 @@ class BatchAddController : NucleusController<EhFragmentBatchAddBinding, BatchAdd
private fun noGalleriesSpecified() { private fun noGalleriesSpecified() {
activity?.let { activity?.let {
MaterialDialog.Builder(it) MaterialDialog(it)
.title("No galleries to add!") .title(text = "No galleries to add!")
.content("You must specify at least one gallery to add!") .message(text = "You must specify at least one gallery to add!")
.positiveText("Ok") .positiveButton(android.R.string.ok) { materialDialog -> materialDialog.dismiss() }
.onPositive { materialDialog, _ -> materialDialog.dismiss() }
.cancelable(true) .cancelable(true)
.canceledOnTouchOutside(true) .cancelOnTouchOutside(true)
.show() .show()
} }
} }

View File

@ -175,12 +175,12 @@ class BrowserActionActivity : AppCompatActivity() {
Timber.e(IllegalStateException("Captcha solve failure!")) Timber.e(IllegalStateException("Captcha solve failure!"))
runOnUiThread { runOnUiThread {
webview.evaluateJavascript(SOLVE_UI_SCRIPT_HIDE, null) webview.evaluateJavascript(SOLVE_UI_SCRIPT_HIDE, null)
MaterialDialog.Builder(this) MaterialDialog(this)
.title("Captcha solve failure") .title(text = "Captcha solve failure")
.content("Failed to auto-solve the captcha!") .message(text = "Failed to auto-solve the captcha!")
.cancelable(true) .cancelable(true)
.canceledOnTouchOutside(true) .cancelOnTouchOutside(true)
.positiveText("Ok") .positiveButton(android.R.string.ok)
.show() .show()
} }
} }

View File

@ -11,10 +11,12 @@ import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat import androidx.appcompat.widget.LinearLayoutCompat
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.github.ajalt.reprint.core.AuthenticationResult import com.github.ajalt.reprint.core.AuthenticationResult
import com.github.ajalt.reprint.core.Reprint import com.github.ajalt.reprint.core.Reprint
import com.github.ajalt.reprint.rxjava.RxReprint import com.github.ajalt.reprint.rxjava.RxReprint
import com.mattprecious.swirl.SwirlView import com.mattprecious.swirl.SwirlView
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.util.preference.onChange import eu.kanade.tachiyomi.util.preference.onChange
@ -106,14 +108,13 @@ class FingerLockPreference @JvmOverloads constructor(context: Context, attrs: At
addView(statusTextView) addView(statusTextView)
addView(iconView) addView(iconView)
} }
val dialog = MaterialDialog.Builder(context) val dialog = MaterialDialog(context)
.title("Fingerprint verification") .title(text = "Fingerprint verification")
.customView(linearLayout, false) .customView(view = linearLayout)
.negativeText("Cancel") .negativeButton(R.string.action_cancel)
.autoDismiss(true)
.cancelable(true) .cancelable(true)
.canceledOnTouchOutside(true) .cancelOnTouchOutside(true)
.show() dialog.show()
iconView.setState(SwirlView.State.ON) iconView.setState(SwirlView.State.ON)
val subscription = RxReprint.authenticate() val subscription = RxReprint.authenticate()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -130,13 +131,12 @@ class FingerLockPreference @JvmOverloads constructor(context: Context, attrs: At
statusTextView.text = result.errorMessage statusTextView.text = result.errorMessage
} }
AuthenticationResult.Status.FATAL_FAILURE, null -> { AuthenticationResult.Status.FATAL_FAILURE, null -> {
MaterialDialog.Builder(context) MaterialDialog(context)
.title("Fingerprint verification failed!") .title(text = "Fingerprint verification failed!")
.content(result.errorMessage) .message(text = result.errorMessage)
.positiveText("Ok") .positiveButton(android.R.string.ok)
.autoDismiss(true)
.cancelable(true) .cancelable(true)
.canceledOnTouchOutside(false) .cancelOnTouchOutside(false)
.show() .show()
dialog.dismiss() dialog.dismiss()
} }

View File

@ -52,13 +52,12 @@ class LockController : NucleusController<ActivityLockBinding, LockPresenter>() {
// Yay! // Yay!
closeLock() closeLock()
} else { } else {
MaterialDialog.Builder(context) MaterialDialog(context)
.title("PIN code incorrect") .title(text = "PIN code incorrect")
.content("The PIN code you entered is incorrect. Please try again.") .message(text = "The PIN code you entered is incorrect. Please try again.")
.cancelable(true) .cancelable(true)
.canceledOnTouchOutside(true) .cancelOnTouchOutside(true)
.positiveText("Ok") .positiveButton(android.R.string.ok)
.autoDismiss(true)
.show() .show()
binding.pinLockView.resetPinLockView() binding.pinLockView.resetPinLockView()
} }
@ -105,13 +104,12 @@ class LockController : NucleusController<ActivityLockBinding, LockPresenter>() {
AuthenticationResult.Status.SUCCESS -> closeLock() AuthenticationResult.Status.SUCCESS -> closeLock()
AuthenticationResult.Status.NONFATAL_FAILURE -> icon.setState(SwirlView.State.ERROR) AuthenticationResult.Status.NONFATAL_FAILURE -> icon.setState(SwirlView.State.ERROR)
AuthenticationResult.Status.FATAL_FAILURE, null -> { AuthenticationResult.Status.FATAL_FAILURE, null -> {
MaterialDialog.Builder(context) MaterialDialog(context)
.title("Fingerprint error!") .title(text = "Fingerprint error!")
.content(it.errorMessage) .message(text = it.errorMessage)
.cancelable(false) .cancelable(false)
.canceledOnTouchOutside(false) .cancelOnTouchOutside(false)
.positiveText("Ok") .positiveButton(android.R.string.ok)
.autoDismiss(true)
.show() .show()
icon.setState(SwirlView.State.OFF) icon.setState(SwirlView.State.OFF)
} }

View File

@ -5,6 +5,7 @@ import android.text.InputType
import android.util.AttributeSet import android.util.AttributeSet
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.input.input
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.preference.onChange import eu.kanade.tachiyomi.util.preference.onChange
@ -44,17 +45,16 @@ class LockPreference @JvmOverloads constructor(context: Context, attrs: Attribut
fun tryChange() { fun tryChange() {
if (!notifyLockSecurity(context)) { if (!notifyLockSecurity(context)) {
MaterialDialog.Builder(context) MaterialDialog(context)
.title("Lock application") .title(text = "Lock application")
.content("Enter a pin to lock the application. Enter nothing to disable the pin lock.") .message(text = "Enter a pin to lock the application. Enter nothing to disable the pin lock.")
.inputRangeRes(0, 10, R.color.material_red_500) // .inputRangeRes(0, 10, R.color.material_red_500)
.inputType(InputType.TYPE_CLASS_NUMBER) // .inputType(InputType.TYPE_CLASS_NUMBER)
.input("", "", { _, c -> .input(maxLength = 10, inputType = InputType.TYPE_CLASS_NUMBER, allowEmpty = true) { _, c ->
val progressDialog = MaterialDialog.Builder(context) val progressDialog = MaterialDialog(context)
.title("Saving password") .title(text = "Saving password")
.progress(true, 0)
.cancelable(false) .cancelable(false)
.show() progressDialog.show()
Observable.fromCallable { Observable.fromCallable {
savePassword(c.toString()) savePassword(c.toString())
}.subscribeOn(Schedulers.computation()) }.subscribeOn(Schedulers.computation())
@ -63,11 +63,10 @@ class LockPreference @JvmOverloads constructor(context: Context, attrs: Attribut
progressDialog.dismiss() progressDialog.dismiss()
updateSummary() updateSummary()
} }
}) }
.negativeText("Cancel") .negativeButton(R.string.action_cancel)
.autoDismiss(true)
.cancelable(true) .cancelable(true)
.canceledOnTouchOutside(true) .cancelOnTouchOutside(true)
.show() .show()
} }
} }

View File

@ -54,30 +54,27 @@ fun notifyLockSecurity(
return false return false
if (!prefs.eh_lockManually().getOrDefault() && if (!prefs.eh_lockManually().getOrDefault() &&
!hasAccessToUsageStats(context)) { !hasAccessToUsageStats(context)) {
MaterialDialog.Builder(context) MaterialDialog(context)
.title("Permission required") .title(text = "Permission required")
.content("${context.getString(R.string.app_name)} requires the usage stats permission to detect when you leave the app. " + .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. " + "This is required for the application lock to function properly. " +
"Press OK to grant this permission now.") "Press OK to grant this permission now.")
.negativeText("Cancel") .negativeButton(R.string.action_cancel)
.positiveText("Ok") .positiveButton(android.R.string.ok) {
.onPositive { _, _ ->
try { try {
context.startActivity(Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)) context.startActivity(Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS))
} catch (e: ActivityNotFoundException) { } catch (e: ActivityNotFoundException) {
XLog.e("Device does not support USAGE_ACCESS_SETTINGS shortcut!") XLog.e("Device does not support USAGE_ACCESS_SETTINGS shortcut!")
MaterialDialog.Builder(context) MaterialDialog(context)
.title("Grant permission manually") .title(text = "Grant permission manually")
.content("Failed to launch the window used to grant the usage stats permission. " + .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'.") "You can still grant this permission manually: go to your phone's settings and search for 'usage access'.")
.positiveText("Ok") .positiveButton(android.R.string.ok) { it.dismiss() }
.onPositive { dialog, _ -> dialog.dismiss() }
.cancelable(true) .cancelable(true)
.canceledOnTouchOutside(false) .cancelOnTouchOutside(false)
.show() .show()
} }
} }
.autoDismiss(true)
.cancelable(false) .cancelable(false)
.show() .show()
return true return true

View File

@ -710,6 +710,14 @@
<string name="eh_rounded_corners_desc">The level of radius that the corners are rounded to. Current value is: %s</string> <string name="eh_rounded_corners_desc">The level of radius that the corners are rounded to. Current value is: %s</string>
<string name="merge">Merge with current</string> <string name="merge">Merge with current</string>
<string name="eh_merge_with_another_source">Merge With Another</string> <string name="eh_merge_with_another_source">Merge With Another</string>
<string name="eh_autoscroll_help">Autoscroll help</string>
<string name="eh_autoscroll_help_message">Automatically scroll to the next page in the specified interval. Interval is specified in seconds.</string>
<string name="eh_retry_all_help">Retry all help</string>
<string name="eh_retry_all_help_message">Re-add all failed pages to the download queue.</string>
<string name="eh_boost_page_help">Boost page help</string>
<string name="eh_boost_page_help_message">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.</string>
<string name="eh_force_sync_reset_title">Are you sure?</string>
<string name="eh_force_sync_reset_message">Resetting the sync state can cause your next sync to be extremely slow.</string>
<string name="eh_show_update_statistics_dialog">Collecting statistics…</string>
</resources> </resources>