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
@@ -27,15 +27,14 @@ class MigrationMangaDialog<T>(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)
}
}
@@ -419,13 +419,12 @@ class MigrationListController(bundle: Bundle? = null) : BaseController<Migration
override fun handleBack(): Boolean {
activity?.let {
MaterialDialog.Builder(it).title(R.string.stop_migrating)
.positiveText(R.string.action_stop)
.negativeText(android.R.string.cancel)
.onPositive { _, _ ->
MaterialDialog(it).title(R.string.stop_migrating)
.positiveButton(R.string.action_stop) {
router.popCurrentController()
migrationsJob?.cancel()
}
.negativeButton(android.R.string.cancel)
.show()
}
return true
@@ -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()
}
}
@@ -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)
@@ -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
}
}
@@ -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 {
@@ -143,13 +143,12 @@ class BatchAddController : NucleusController<EhFragmentBatchAddBinding, BatchAdd
private fun noGalleriesSpecified() {
activity?.let {
MaterialDialog.Builder(it)
.title("No galleries to add!")
.content("You must specify at least one gallery to add!")
.positiveText("Ok")
.onPositive { materialDialog, _ -> 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()
}
}
@@ -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()
}
}
@@ -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()
}
+10 -12
View File
@@ -52,13 +52,12 @@ class LockController : NucleusController<ActivityLockBinding, LockPresenter>() {
// 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<ActivityLockBinding, LockPresenter>() {
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)
}
+13 -14
View File
@@ -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()
}
}
+10 -13
View File
@@ -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