Using new material dialog libraty

Co-Authored-By: Carlos <carlosesco@users.noreply.github.com>
This commit is contained in:
Jay 2020-01-11 16:23:30 -08:00
parent c8656526df
commit c143490f5a
37 changed files with 229 additions and 536 deletions

View File

@ -6,10 +6,8 @@ object BackupConst {
const val INTENT_FILTER = "SettingsBackupFragment" const val INTENT_FILTER = "SettingsBackupFragment"
const val ACTION_BACKUP_COMPLETED_DIALOG = "$ID.$INTENT_FILTER.ACTION_BACKUP_COMPLETED_DIALOG" 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_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_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 ACTION = "$ID.$INTENT_FILTER.ACTION"
const val EXTRA_PROGRESS = "$ID.$INTENT_FILTER.EXTRA_PROGRESS" const val EXTRA_PROGRESS = "$ID.$INTENT_FILTER.EXTRA_PROGRESS"
const val EXTRA_AMOUNT = "$ID.$INTENT_FILTER.EXTRA_AMOUNT" const val EXTRA_AMOUNT = "$ID.$INTENT_FILTER.EXTRA_AMOUNT"

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.category
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.input.input
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
@ -13,11 +14,6 @@ import eu.kanade.tachiyomi.ui.base.controller.DialogController
class CategoryCreateDialog<T>(bundle: Bundle? = null) : DialogController(bundle) class CategoryCreateDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
where T : Controller, T : CategoryCreateDialog.Listener { 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() { constructor(target: T) : this() {
targetController = target targetController = target
} }
@ -29,15 +25,13 @@ class CategoryCreateDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
* @return a new dialog instance. * @return a new dialog instance.
*/ */
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.title(R.string.action_add_category) .title(R.string.action_add_category)
.negativeText(android.R.string.cancel) .positiveButton(android.R.string.ok)
.alwaysCallInputCallback() .negativeButton(android.R.string.cancel)
.input(resources?.getString(R.string.name), currentName, false) { _, input -> .input(hintRes = R.string.name) { _, input ->
currentName = input.toString() (targetController as? Listener)?.createCategory(input.toString())
} }
.onPositive { _, _ -> (targetController as? Listener)?.createCategory(currentName) }
.build()
} }
interface Listener { interface Listener {

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.category
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.input.input
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Category
@ -34,15 +35,13 @@ class CategoryRenameDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
* @return a new dialog instance. * @return a new dialog instance.
*/ */
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.title(R.string.action_rename_category) .title(R.string.action_rename_category)
.negativeText(android.R.string.cancel) .negativeButton(android.R.string.cancel)
.alwaysCallInputCallback() .input(hintRes = R.string.name, prefill = currentName) { _, input ->
.input(resources!!.getString(R.string.name), currentName, false) { _, input ->
currentName = input.toString() currentName = input.toString()
} }
.onPositive { _, _ -> onPositive() } .positiveButton(android.R.string.ok)
.build()
} }
/** /**

View File

@ -18,18 +18,15 @@ class ExtensionTrustDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
} }
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.title(R.string.untrusted_extension) .title(R.string.untrusted_extension)
.content(R.string.untrusted_extension_message) .message(R.string.untrusted_extension_message)
.positiveText(R.string.ext_trust) .positiveButton(R.string.ext_trust) {
.negativeText(R.string.ext_uninstall)
.onPositive { _, _ ->
(targetController as? Listener)?.trustSignature(args.getString(SIGNATURE_KEY)!!) (targetController as? Listener)?.trustSignature(args.getString(SIGNATURE_KEY)!!)
} }
.onNegative { _, _ -> .negativeButton(R.string.ext_uninstall) {
(targetController as? Listener)?.uninstallExtension(args.getString(PKGNAME_KEY)!!) (targetController as? Listener)?.uninstallExtension(args.getString(PKGNAME_KEY)!!)
} }
.build()
} }
private companion object { private companion object {

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.library
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsMultiChoice
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Category
@ -28,17 +29,18 @@ class ChangeMangaCategoriesDialog<T>(bundle: Bundle? = null) :
} }
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.title(R.string.action_move_category) .title(R.string.action_move_category)
.items(categories.map { it.name }) .listItemsMultiChoice(
.itemsCallbackMultiChoice(preselected) { dialog, _, _ -> items = categories.map { it.name },
val newCategories = dialog.selectedIndices?.map { categories[it] }.orEmpty() initialSelection = preselected.toIntArray(),
(targetController as? Listener)?.updateCategoriesForMangas(mangas, newCategories) allowEmptySelection = true
true ) { _, selections, _ ->
} val newCategories = selections.map { categories[it] }
.positiveText(android.R.string.ok) (targetController as? Listener)?.updateCategoriesForMangas(mangas, newCategories)
.negativeText(android.R.string.cancel) }
.build() .positiveButton(android.R.string.ok)
.negativeButton(android.R.string.cancel)
} }
interface Listener { interface Listener {

View File

@ -5,6 +5,7 @@ import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.util.AttributeSet import android.util.AttributeSet
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
@ -15,11 +16,10 @@ class ChangelogDialogController : DialogController() {
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val activity = activity!! val activity = activity!!
val view = WhatsNewRecyclerView(activity) val view = WhatsNewRecyclerView(activity)
return MaterialDialog.Builder(activity) return MaterialDialog(activity)
.title(if (BuildConfig.DEBUG) "Notices" else "Changelog") .title(text = if (BuildConfig.DEBUG) "Notices" else "Changelog")
.customView(view, false) .customView(view = view, scrollable = false)
.positiveText(android.R.string.yes) .positiveButton(android.R.string.yes)
.build()
} }
class WhatsNewRecyclerView(context: Context) : ChangeLogRecyclerView(context) { class WhatsNewRecyclerView(context: Context) : ChangeLogRecyclerView(context) {

View File

@ -491,13 +491,10 @@ class ChaptersController() : NucleusController<ChaptersPresenter>(),
fun deleteChapters(chapters: List<ChapterItem>) { fun deleteChapters(chapters: List<ChapterItem>) {
destroyActionModeIfNeeded() destroyActionModeIfNeeded()
if (chapters.isEmpty()) return if (chapters.isEmpty()) return
DeletingChaptersDialog().showDialog(router)
presenter.deleteChapters(chapters) presenter.deleteChapters(chapters)
} }
fun onChaptersDeleted(chapters: List<ChapterItem>) { fun onChaptersDeleted(chapters: List<ChapterItem>) {
dismissDeletingDialog()
//this is needed so the downloaded text gets removed from the item //this is needed so the downloaded text gets removed from the item
chapters.forEach { chapters.forEach {
adapter?.updateItem(it) adapter?.updateItem(it)
@ -506,14 +503,9 @@ class ChaptersController() : NucleusController<ChaptersPresenter>(),
} }
fun onChaptersDeletedError(error: Throwable) { fun onChaptersDeletedError(error: Throwable) {
dismissDeletingDialog()
Timber.e(error) Timber.e(error)
} }
private fun dismissDeletingDialog() {
router.popControllerWithTag(DeletingChaptersDialog.TAG)
}
// OVERFLOW MENU DIALOGS // OVERFLOW MENU DIALOGS
private fun showDisplayModeDialog() { private fun showDisplayModeDialog() {

View File

@ -15,14 +15,13 @@ class DeleteChaptersDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
} }
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!).show {
.content(R.string.confirm_delete_chapters) message(R.string.confirm_delete_chapters)
.positiveText(android.R.string.yes) positiveButton(android.R.string.yes) {
.negativeText(android.R.string.no) (targetController as? Listener)?.deleteChapters()
.onPositive { _, _ -> }
(targetController as? Listener)?.deleteChapters() negativeButton(android.R.string.no)
} }
.show()
} }
interface Listener { interface Listener {

View File

@ -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)
}
}

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItems
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
@ -26,14 +27,13 @@ class DownloadChaptersDialog<T>(bundle: Bundle? = null) : DialogController(bundl
R.string.download_all R.string.download_all
).map { activity.getString(it) } ).map { activity.getString(it) }
return MaterialDialog.Builder(activity) return MaterialDialog(activity)
.title(R.string.manga_download) .title(R.string.manga_download)
.negativeText(android.R.string.cancel) .negativeButton(android.R.string.cancel)
.items(choices) .listItems(items = choices){dialog, position, _ ->
.itemsCallback { _, _, position, _ ->
(targetController as? Listener)?.downloadChapters(position) (targetController as? Listener)?.downloadChapters(position)
dialog.dismiss()
} }
.build()
} }
interface Listener { interface Listener {

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
@ -55,15 +56,13 @@ class DownloadCustomChaptersDialog<T> : DialogController
// Build dialog. // Build dialog.
// when positive dialog is pressed call custom listener. // when positive dialog is pressed call custom listener.
return MaterialDialog.Builder(activity) return MaterialDialog(activity)
.title(R.string.custom_download) .title(R.string.custom_download)
.customView(view, true) .customView(view = view, scrollable = true)
.positiveText(android.R.string.ok) .positiveButton(android.R.string.ok) {
.negativeText(android.R.string.cancel)
.onPositive { _, _ ->
(targetController as? Listener)?.downloadCustomChapters(view.amount) (targetController as? Listener)?.downloadCustomChapters(view.amount)
} }
.build() .negativeButton(android.R.string.cancel)
} }
interface Listener { interface Listener {

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
@ -25,15 +26,12 @@ class SetDisplayModeDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
val choices = intArrayOf(R.string.show_title, R.string.show_chapter_number) val choices = intArrayOf(R.string.show_title, R.string.show_chapter_number)
.map { activity.getString(it) } .map { activity.getString(it) }
return MaterialDialog.Builder(activity) return MaterialDialog(activity)
.title(R.string.action_display_mode) .title(R.string.action_display_mode)
.items(choices) .listItemsSingleChoice(items = choices, initialSelection = selectedIndex)
.itemsIds(ids) {_, position, _ ->
.itemsCallbackSingleChoice(selectedIndex) { _, itemView, _, _ -> (targetController as? Listener)?.setDisplayMode(ids[position])
(targetController as? Listener)?.setDisplayMode(itemView.id)
true
} }
.build()
} }
interface Listener { interface Listener {

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.chapter
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
@ -25,15 +26,12 @@ class SetSortingDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
val choices = intArrayOf(R.string.sort_by_source, R.string.sort_by_number) val choices = intArrayOf(R.string.sort_by_source, R.string.sort_by_number)
.map { activity.getString(it) } .map { activity.getString(it) }
return MaterialDialog.Builder(activity) return MaterialDialog(activity)
.title(R.string.sorting_mode) .title(R.string.sorting_mode)
.items(choices) .listItemsSingleChoice(items = choices, initialSelection = selectedIndex){
.itemsIds(ids) _, position, _ ->
.itemsCallbackSingleChoice(selectedIndex) { _, itemView, _, _ -> (targetController as? Listener)?.setSorting(ids[position])
(targetController as? Listener)?.setSorting(itemView.id)
true
} }
.build()
} }
interface Listener { interface Listener {

View File

@ -21,11 +21,9 @@ import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat import androidx.core.graphics.drawable.IconCompat
import com.afollestad.materialdialogs.MaterialDialog 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.DiskCacheStrategy
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.resource.bitmap.RoundedCorners 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.target.CustomTarget
import com.bumptech.glide.request.transition.Transition import com.bumptech.glide.request.transition.Transition
import com.bumptech.glide.signature.ObjectKey import com.bumptech.glide.signature.ObjectKey
@ -62,7 +60,6 @@ import eu.kanade.tachiyomi.util.updateLayoutParams
import eu.kanade.tachiyomi.util.updatePaddingRelative import eu.kanade.tachiyomi.util.updatePaddingRelative
import jp.wasabeef.glide.transformations.CropSquareTransformation import jp.wasabeef.glide.transformations.CropSquareTransformation
import jp.wasabeef.glide.transformations.MaskTransformation import jp.wasabeef.glide.transformations.MaskTransformation
import kotlinx.android.synthetic.main.catalogue_list_item.*
import kotlinx.android.synthetic.main.manga_info_controller.* import kotlinx.android.synthetic.main.manga_info_controller.*
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.io.File import java.io.File
@ -554,14 +551,14 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
R.string.square_icon, R.string.square_icon,
R.string.star_icon) R.string.star_icon)
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.title(R.string.icon_shape) .title(R.string.icon_shape)
.negativeText(android.R.string.cancel) .negativeButton(android.R.string.cancel)
.items(modes.map { activity?.getString(it) }) .listItemsSingleChoice (
.itemsCallback { _, _, i, _ -> items = modes.map { activity?.getString(it) as CharSequence })
{ _, i, _ ->
(targetController as? MangaInfoController)?.createShortcutForShape(i) (targetController as? MangaInfoController)?.createShortcutForShape(i)
} }
.build()
} }
} }

View File

@ -4,6 +4,8 @@ import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.widget.NumberPicker import android.widget.NumberPicker
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.customview.getCustomView
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
@ -34,31 +36,25 @@ class SetTrackChaptersDialog<T> : DialogController
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val item = item val item = item
val dialog = MaterialDialog.Builder(activity!!) val dialog = MaterialDialog(activity!!)
.title(R.string.chapters) .title(R.string.chapters)
.customView(R.layout.track_chapters_dialog, false) .customView(viewRes = R.layout.track_chapters_dialog, scrollable = false)
.positiveText(android.R.string.ok) .negativeButton(android.R.string.cancel)
.negativeText(android.R.string.cancel) .positiveButton(android.R.string.ok) { dialog ->
.onPositive { dialog, _ -> val view = dialog.getCustomView()
val view = dialog.customView // Remove focus to update selected number
if (view != null) { val np: NumberPicker = view.findViewById(R.id.chapters_picker)
// Remove focus to update selected number np.clearFocus()
val np: NumberPicker = view.findViewById(R.id.chapters_picker) (targetController as? Listener)?.setChaptersRead(item, np.value)
np.clearFocus() }
(targetController as? Listener)?.setChaptersRead(item, np.value) val view = dialog.getCustomView()
} val np: NumberPicker = view.findViewById(R.id.chapters_picker)
} // Set initial value
.build() 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 return dialog
} }

View File

@ -4,6 +4,8 @@ import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.widget.NumberPicker import android.widget.NumberPicker
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.customview.getCustomView
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
@ -34,36 +36,32 @@ class SetTrackScoreDialog<T> : DialogController
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val item = item val item = item
val dialog = MaterialDialog.Builder(activity!!) val dialog = MaterialDialog(activity!!)
.title(R.string.score) .title(R.string.score)
.customView(R.layout.track_score_dialog, false) .customView(R.layout.track_score_dialog, scrollable = false)
.positiveText(android.R.string.ok) .negativeButton(android.R.string.cancel)
.negativeText(android.R.string.cancel) .positiveButton(android.R.string.ok) { dialog ->
.onPositive { dialog, _ -> val view = dialog.getCustomView()
val view = dialog.customView // Remove focus to update selected number
if (view != null) { val np: NumberPicker = view.findViewById(R.id.score_picker)
// Remove focus to update selected number np.clearFocus()
val np: NumberPicker = view.findViewById(R.id.score_picker)
np.clearFocus()
(targetController as? Listener)?.setScore(item, np.value) (targetController as? Listener)?.setScore(item, np.value)
}
}
.show()
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 return dialog

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga.track
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
@ -36,15 +37,14 @@ class SetTrackStatusDialog<T> : DialogController
val statusString = statusList.mapNotNull { item.service.getStatus(it) } val statusString = statusList.mapNotNull { item.service.getStatus(it) }
val selectedIndex = statusList.indexOf(item.track?.status) val selectedIndex = statusList.indexOf(item.track?.status)
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.title(R.string.status) .title(R.string.status)
.negativeText(android.R.string.cancel) .negativeButton(android.R.string.cancel)
.items(statusString) .listItemsSingleChoice(items = statusString, initialSelection = selectedIndex)
.itemsCallbackSingleChoice(selectedIndex) { _, _, i, _ -> { dialog, position, _ ->
(targetController as? Listener)?.setStatus(item, i) (targetController as? Listener)?.setStatus(item, position)
true dialog.dismiss()
} }
.build()
} }
interface Listener { interface Listener {

View File

@ -4,6 +4,7 @@ import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.jakewharton.rxbinding.widget.itemClicks import com.jakewharton.rxbinding.widget.itemClicks
import com.jakewharton.rxbinding.widget.textChanges import com.jakewharton.rxbinding.widget.textChanges
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -51,12 +52,10 @@ class TrackSearchDialog : DialogController {
} }
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val dialog = MaterialDialog.Builder(activity!!) val dialog = MaterialDialog(activity!!)
.customView(R.layout.track_search_dialog, false) .customView(viewRes = R.layout.track_search_dialog, scrollable = false)
.positiveText(android.R.string.ok) .negativeButton(android.R.string.cancel)
.negativeText(android.R.string.cancel) .positiveButton(android.R.string.ok) { onPositiveButtonClick() }
.onPositive { _, _ -> onPositiveButtonClick() }
.build()
if (subscriptions.isUnsubscribed) { if (subscriptions.isUnsubscribed) {
subscriptions = CompositeSubscription() subscriptions = CompositeSubscription()

View File

@ -105,16 +105,6 @@ class MigrationController : NucleusController<MigrationPresenter>(),
} }
} }
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 { override fun onItemClick(view: View?, position: Int): Boolean {
val item = adapter?.getItem(position) ?: return false val item = adapter?.getItem(position) ?: return false
@ -157,22 +147,6 @@ class MigrationController : NucleusController<MigrationPresenter>(),
presenter.migrateManga(prevManga, manga, replace) presenter.migrateManga(prevManga, manga, replace)
return null 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 { interface MigrationInterface {

View File

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

View File

@ -56,8 +56,8 @@ class MigrationPresenter(
.distinctUntilChanged { t1, t2 -> t1.isReplacingManga != t2.isReplacingManga } .distinctUntilChanged { t1, t2 -> t1.isReplacingManga != t2.isReplacingManga }
.subscribeLatestCache(MigrationController::render) .subscribeLatestCache(MigrationController::render)
stateRelay.distinctUntilChanged { state -> state.isReplacingManga } /* stateRelay.distinctUntilChanged { state -> state.isReplacingManga }
.subscribeLatestCache(MigrationController::renderIsReplacingManga) .subscribeLatestCache(MigrationController::renderIsReplacingManga)*/
} }
fun setSelectedSource(source: Source) { fun setSelectedSource(source: Source) {

View File

@ -7,6 +7,7 @@ import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsMultiChoice
import com.jakewharton.rxbinding.support.v7.widget.queryTextChangeEvents import com.jakewharton.rxbinding.support.v7.widget.queryTextChangeEvents
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
@ -137,27 +138,20 @@ class SearchController(
val preselected = MigrationFlags.getEnabledFlagsPositions(prefValue) val preselected = MigrationFlags.getEnabledFlagsPositions(prefValue)
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.content(R.string.migration_dialog_what_to_include) .message(R.string.migration_dialog_what_to_include)
.items(MigrationFlags.titles.map { resources?.getString(it) }) .listItemsMultiChoice(items = MigrationFlags.titles.map
.alwaysCallMultiChoiceCallback() { resources?.getString(it) as CharSequence },
.itemsCallbackMultiChoice(preselected.toTypedArray()) { _, positions, _ -> initialSelection = preselected.toIntArray()) { _, positions, _ ->
// Save current settings for the next time val newValue = MigrationFlags.getFlagsFromPositions(positions.toTypedArray())
val newValue = MigrationFlags.getFlagsFromPositions(positions)
preferences.migrateFlags().set(newValue) preferences.migrateFlags().set(newValue)
true
} }
.positiveText(R.string.migrate) .positiveButton(R.string.migrate) {
.negativeText(R.string.copy)
.neutralText(android.R.string.cancel)
.onPositive { _, _ ->
(targetController as? SearchController)?.migrateManga() (targetController as? SearchController)?.migrateManga()
} }
.onNegative { _, _ -> .negativeButton(R.string.copy) {
(targetController as? SearchController)?.copyManga() (targetController as? SearchController)?.copyManga()
} }
.build()
} }
} }

View File

@ -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<MigratingManga>) { suspend fun runMigrations(mangas: List<MigratingManga>) {
val useSourceWithMost = preferences.useSourceWithMost().getOrDefault() val useSourceWithMost = preferences.useSourceWithMost().getOrDefault()
@ -381,14 +371,14 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle),
override fun handleBack(): Boolean { override fun handleBack(): Boolean {
activity?.let { activity?.let {
MaterialDialog.Builder(it).title(R.string.stop_migration) MaterialDialog(it).show {
.positiveText(R.string.yes) title(R.string.stop_migration)
.negativeText(R.string.no) positiveButton (R.string.yes) {
.onPositive { _, _ ->
router.popCurrentController() router.popCurrentController()
migrationsJob?.cancel() migrationsJob?.cancel()
} }
.show() negativeButton(R.string.no)
}
} }
return true return true
} }

View File

@ -44,14 +44,13 @@ class ReaderPageSheet(
private fun setAsCover() { private fun setAsCover() {
if (page.status != Page.READY) return if (page.status != Page.READY) return
MaterialDialog.Builder(activity) MaterialDialog(activity)
.content(activity.getString(R.string.confirm_set_image_as_cover)) .title(R.string.confirm_set_image_as_cover)
.positiveText(android.R.string.yes) .positiveButton(android.R.string.yes) {
.negativeText(android.R.string.no)
.onPositive { _, _ ->
activity.setAsCover(page) activity.setAsCover(page)
dismiss() dismiss()
} }
.negativeButton(android.R.string.no)
.show() .show()
} }

View File

@ -18,14 +18,12 @@ class ConfirmDeleteChaptersDialog<T>(bundle: Bundle? = null) : DialogController(
} }
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.content(R.string.confirm_delete_chapters) .message(R.string.confirm_delete_chapters)
.positiveText(android.R.string.yes) .positiveButton(android.R.string.yes) {
.negativeText(android.R.string.no)
.onPositive { _, _ ->
(targetController as? Listener)?.deleteChapters(chaptersToDelete) (targetController as? Listener)?.deleteChapters(chaptersToDelete)
} }
.build() .negativeButton(android.R.string.no)
} }
interface Listener { interface Listener {

View File

@ -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)
}
}

View File

@ -216,14 +216,13 @@ class RecentChaptersController : NucleusController<RecentChaptersPresenter>(),
override fun deleteChapters(chaptersToDelete: List<RecentChapterItem>) { override fun deleteChapters(chaptersToDelete: List<RecentChapterItem>) {
destroyActionModeIfNeeded() destroyActionModeIfNeeded()
DeletingChaptersDialog().showDialog(router)
presenter.deleteChapters(chaptersToDelete) presenter.deleteChapters(chaptersToDelete)
} }
/** /**
* Destory [ActionMode] if it's shown * Destory [ActionMode] if it's shown
*/ */
fun destroyActionModeIfNeeded() { private fun destroyActionModeIfNeeded() {
actionMode?.finish() actionMode?.finish()
} }
@ -248,7 +247,6 @@ class RecentChaptersController : NucleusController<RecentChaptersPresenter>(),
* @param chapter selected chapter with manga * @param chapter selected chapter with manga
*/ */
fun deleteChapter(chapter: RecentChapterItem) { fun deleteChapter(chapter: RecentChapterItem) {
DeletingChaptersDialog().showDialog(router)
presenter.deleteChapters(listOf(chapter)) presenter.deleteChapters(listOf(chapter))
} }
@ -266,7 +264,6 @@ class RecentChaptersController : NucleusController<RecentChaptersPresenter>(),
* Called when chapters are deleted * Called when chapters are deleted
*/ */
fun onChaptersDeleted() { fun onChaptersDeleted() {
dismissDeletingDialog()
adapter?.notifyDataSetChanged() adapter?.notifyDataSetChanged()
} }
@ -275,17 +272,9 @@ class RecentChaptersController : NucleusController<RecentChaptersPresenter>(),
* @param error error message * @param error error message
*/ */
fun onChaptersDeletedError(error: Throwable) { fun onChaptersDeletedError(error: Throwable) {
dismissDeletingDialog()
Timber.e(error) Timber.e(error)
} }
/**
* Called to dismiss deleting dialog
*/
fun dismissDeletingDialog() {
router.popControllerWithTag(DeletingChaptersDialog.TAG)
}
/** /**
* Called when ActionMode created. * Called when ActionMode created.
* @param mode the ActionMode object * @param mode the ActionMode object

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.recently_read
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.History
@ -32,13 +33,12 @@ class RemoveHistoryDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
setOptionDescription(R.string.dialog_with_checkbox_reset) setOptionDescription(R.string.dialog_with_checkbox_reset)
} }
return MaterialDialog.Builder(activity) return MaterialDialog(activity)
.title(R.string.action_remove) .title(R.string.action_remove)
.customView(dialogCheckboxView, true) .customView(view = dialogCheckboxView, scrollable = true)
.positiveText(R.string.action_remove) .positiveButton(R.string.action_remove) { onPositive(dialogCheckboxView.isChecked
.negativeText(android.R.string.cancel) ()) }
.onPositive { _, _ -> onPositive(dialogCheckboxView.isChecked()) } .negativeButton(android.R.string.cancel)
.build()
} }
private fun onPositive(checked: Boolean) { private fun onPositive(checked: Boolean) {

View File

@ -128,12 +128,10 @@ class SettingsAboutController : SettingsController() {
}) })
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.title(R.string.update_check_title) .title(R.string.update_check_title)
.content(args.getString(BODY_KEY) ?: "") .message(text = args.getString(BODY_KEY) ?: "")
.positiveText(R.string.update_check_confirm) .positiveButton(R.string.update_check_confirm) {
.negativeText(R.string.update_check_ignore)
.onPositive { _, _ ->
val appContext = applicationContext val appContext = applicationContext
if (appContext != null) { if (appContext != null) {
// Start download // Start download
@ -141,7 +139,7 @@ class SettingsAboutController : SettingsController() {
UpdaterService.downloadUpdate(appContext, url) UpdaterService.downloadUpdate(appContext, url)
} }
} }
.build() .negativeButton(R.string.update_check_ignore)
} }
private companion object { private companion object {

View File

@ -84,10 +84,6 @@ class SettingsAdvancedController : SettingsController() {
var deletedFiles = 0 var deletedFiles = 0
val ctrl = DeletingFilesDialogController()
ctrl.total = files.size
ctrl.showDialog(router)
Observable.defer { Observable.from(files) } Observable.defer { Observable.from(files) }
.doOnNext { file -> .doOnNext { file ->
if (chapterCache.removeFileFromCache(file.name)) { if (chapterCache.removeFileFromCache(file.name)) {
@ -97,61 +93,23 @@ class SettingsAdvancedController : SettingsController() {
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
ctrl.setProgress(deletedFiles)
}, { }, {
activity?.toast(R.string.cache_delete_error) activity?.toast(R.string.cache_delete_error)
}, { }, {
ctrl.finish()
activity?.toast(resources?.getString(R.string.cache_deleted, deletedFiles)) activity?.toast(resources?.getString(R.string.cache_deleted, deletedFiles))
findPreference(CLEAR_CACHE_KEY)?.summary = findPreference(CLEAR_CACHE_KEY)?.summary =
resources?.getString(R.string.used_cache, chapterCache.readableSize) 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() { class ClearDatabaseDialogController : DialogController() {
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.content(R.string.clear_database_confirmation) .message(R.string.clear_database_confirmation)
.positiveText(android.R.string.yes) .positiveButton(android.R.string.yes) {
.negativeText(android.R.string.no)
.onPositive { _, _ ->
(targetController as? SettingsAdvancedController)?.clearDatabase() (targetController as? SettingsAdvancedController)?.clearDatabase()
} }
.build() .negativeButton(android.R.string.no)
} }
} }

View File

@ -9,6 +9,7 @@ import android.os.Bundle
import android.view.View import android.view.View
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsMultiChoice
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.backup.BackupConst import eu.kanade.tachiyomi.data.backup.BackupConst
@ -168,7 +169,6 @@ class SettingsBackupController : SettingsController() {
val file = UniFile.fromUri(activity, uri) val file = UniFile.fromUri(activity, uri)
CreatingBackupDialog().showDialog(router, TAG_CREATING_BACKUP_DIALOG)
BackupCreateService.makeBackup(activity, file.uri, backupFlags) BackupCreateService.makeBackup(activity, file.uri, backupFlags)
} }
CODE_BACKUP_RESTORE -> if (data != null && resultCode == Activity.RESULT_OK) { CODE_BACKUP_RESTORE -> if (data != null && resultCode == Activity.RESULT_OK) {
@ -207,12 +207,12 @@ class SettingsBackupController : SettingsController() {
R.string.track, R.string.history) R.string.track, R.string.history)
.map { activity.getString(it) } .map { activity.getString(it) }
return MaterialDialog.Builder(activity) return MaterialDialog(activity)
.title(R.string.pref_create_backup) .title(R.string.pref_create_backup)
.content(R.string.backup_choice) .message(R.string.backup_choice)
.items(options) .listItemsMultiChoice(items = options, disabledIndices = intArrayOf(0),
.itemsDisabledIndices(0) initialSelection = intArrayOf(0))
.itemsCallbackMultiChoice(arrayOf(0, 1, 2, 3, 4)) { _, positions, _ -> { _, positions, _ ->
var flags = 0 var flags = 0
for (i in 1 until positions.size) { for (i in 1 until positions.size) {
when (positions[i]) { when (positions[i]) {
@ -224,27 +224,9 @@ class SettingsBackupController : SettingsController() {
} }
(targetController as? SettingsBackupController)?.createBackup(flags) (targetController as? SettingsBackupController)?.createBackup(flags)
true
} }
.positiveText(R.string.action_create) .positiveButton(R.string.action_create)
.negativeText(android.R.string.cancel) .negativeButton(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)
} }
} }
@ -256,18 +238,16 @@ class SettingsBackupController : SettingsController() {
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val activity = activity!! val activity = activity!!
val unifile = UniFile.fromUri(activity, args.getParcelable(KEY_URI)) val unifile = UniFile.fromUri(activity, args.getParcelable(KEY_URI))
return MaterialDialog.Builder(activity) return MaterialDialog(activity)
.title(R.string.backup_created) .title(R.string.backup_created)
.content(activity.getString(R.string.file_saved, unifile.filePath)) .message(R.string.file_saved, unifile.filePath)
.positiveText(R.string.action_close) .positiveButton(R.string.action_close)
.negativeText(R.string.action_export) .negativeButton(R.string.action_export) {
.onNegative { _, _ ->
val sendIntent = Intent(Intent.ACTION_SEND) val sendIntent = Intent(Intent.ACTION_SEND)
sendIntent.type = "application/json" sendIntent.type = "application/json"
sendIntent.putExtra(Intent.EXTRA_STREAM, unifile.uri) sendIntent.putExtra(Intent.EXTRA_STREAM, unifile.uri)
startActivity(Intent.createChooser(sendIntent, "")) startActivity(Intent.createChooser(sendIntent, ""))
} }
.build()
} }
private companion object { private companion object {
@ -281,18 +261,16 @@ class SettingsBackupController : SettingsController() {
}) })
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!) return MaterialDialog(activity!!)
.title(R.string.pref_restore_backup) .title(R.string.pref_restore_backup)
.content(R.string.backup_restore_content) .message(R.string.backup_restore_content)
.positiveText(R.string.action_restore) .positiveButton(R.string.action_restore) {
.onPositive { _, _ ->
val context = applicationContext val context = applicationContext
if (context != null) { if (context != null) {
activity?.toast(R.string.restoring_backup) activity?.toast(R.string.restoring_backup)
BackupRestoreService.start(context, args.getParcelable(KEY_URI)!!) BackupRestoreService.start(context, args.getParcelable(KEY_URI)!!)
} }
} }
.build()
} }
private companion object { 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() { inner class BackupBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
when (intent.getStringExtra(BackupConst.ACTION)) { when (intent.getStringExtra(BackupConst.ACTION)) {
@ -404,24 +286,6 @@ class SettingsBackupController : SettingsController() {
val uri = Uri.parse(intent.getStringExtra(BackupConst.EXTRA_URI)) val uri = Uri.parse(intent.getStringExtra(BackupConst.EXTRA_URI))
CreatedBackupDialog(uri).showDialog(router) 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 -> { BackupConst.ACTION_ERROR_BACKUP_DIALOG -> {
router.popControllerWithTag(TAG_CREATING_BACKUP_DIALOG) router.popControllerWithTag(TAG_CREATING_BACKUP_DIALOG)
context.toast(intent.getStringExtra(BackupConst.EXTRA_ERROR_MESSAGE)) context.toast(intent.getStringExtra(BackupConst.EXTRA_ERROR_MESSAGE))

View File

@ -10,6 +10,7 @@ import android.os.Environment
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper 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 externalDirs = getExternalDirs() + File(activity.getString(R.string.custom_dir))
val selectedIndex = externalDirs.map(File::toString).indexOfFirst { it in currentDir } val selectedIndex = externalDirs.map(File::toString).indexOfFirst { it in currentDir }
return MaterialDialog.Builder(activity) return MaterialDialog(activity)
.items(externalDirs) .listItemsSingleChoice(items = externalDirs.map { it.path }, initialSelection = selectedIndex)
.itemsCallbackSingleChoice(selectedIndex) { _, _, which, text -> { _, position, text ->
val target = targetController as? SettingsDownloadController val target = targetController as? SettingsDownloadController
if (which == externalDirs.lastIndex) { if (position == externalDirs.lastIndex) {
target?.customDirectorySelected(currentDir) target?.customDirectorySelected(currentDir)
} else { } else {
target?.predefinedDirectorySelected(text.toString()) target?.predefinedDirectorySelected(text.toString())
}
true
} }
.build() }
} }
private fun getExternalDirs(): List<File> { private fun getExternalDirs(): List<File> {

View File

@ -7,6 +7,7 @@ import android.view.View
import androidx.biometric.BiometricManager import androidx.biometric.BiometricManager
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Category
@ -186,16 +187,14 @@ class SettingsLibraryController : SettingsController() {
private var landscape = preferences.landscapeColumns().getOrDefault() private var landscape = preferences.landscapeColumns().getOrDefault()
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val dialog = MaterialDialog.Builder(activity!!) val dialog = MaterialDialog(activity!!)
.title(R.string.pref_library_columns) .title(R.string.pref_library_columns)
.customView(R.layout.pref_library_columns, false) .customView(viewRes = R.layout.pref_library_columns, scrollable = false)
.positiveText(android.R.string.ok) .positiveButton(android.R.string.ok) {
.negativeText(android.R.string.cancel)
.onPositive { _, _ ->
preferences.portraitColumns().set(portrait) preferences.portraitColumns().set(portrait)
preferences.landscapeColumns().set(landscape) preferences.landscapeColumns().set(landscape)
} }
.build() .negativeButton(android.R.string.cancel)
onViewCreated(dialog.view) onViewCreated(dialog.view)
return dialog return dialog

View File

@ -5,6 +5,7 @@ import android.os.Bundle
import android.text.method.PasswordTransformationMethod import android.text.method.PasswordTransformationMethod
import android.view.View import android.view.View
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.ControllerChangeType
import com.dd.processbutton.iml.ActionProcessButton import com.dd.processbutton.iml.ActionProcessButton
@ -26,10 +27,9 @@ abstract class LoginDialogPreference(bundle: Bundle? = null) : DialogController(
var requestSubscription: Subscription? = null var requestSubscription: Subscription? = null
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val dialog = MaterialDialog.Builder(activity!!) val dialog = MaterialDialog(activity!!)
.customView(R.layout.pref_account_login, false) .customView(R.layout.pref_account_login, scrollable = false)
.negativeText(android.R.string.cancel) .negativeButton(android.R.string.cancel)
.build()
onViewCreated(dialog.view) onViewCreated(dialog.view)

View File

@ -242,7 +242,7 @@
<string name="restoring_backup">S\'està restaurant la còpia de seguretat</string> <string name="restoring_backup">S\'està restaurant la còpia de seguretat</string>
<string name="creating_backup">S\'està creant la còpia de seguretat</string> <string name="creating_backup">S\'està creant la còpia de seguretat</string>
<string name="pref_clear_chapter_cache">Buida la memòria cau de capítols</string> <string name="pref_clear_chapter_cache">Buida la memòria cau de capítols</string>
<string name="used_cache">Ús: $1$s</string> <string name="used_cache">Ús: %1$s</string>
<string name="cache_deleted">S\'ha buidat la memòria cau. S\'han suprimit %1$d fitxers</string> <string name="cache_deleted">S\'ha buidat la memòria cau. S\'han suprimit %1$d fitxers</string>
<string name="cache_delete_error">S\'ha produït un error en buidar la memòria cau</string> <string name="cache_delete_error">S\'ha produït un error en buidar la memòria cau</string>
<string name="pref_clear_cookies">Esborra les galetes</string> <string name="pref_clear_cookies">Esborra les galetes</string>

View File

@ -20,7 +20,6 @@
<item name="actionBarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item> <item name="actionBarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat</item> <item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item> <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
<item name="md_background_color">@color/dialogDark</item>
<item name="alertDialogTheme">@style/Theme.AlertDialog.Dark</item> <item name="alertDialogTheme">@style/Theme.AlertDialog.Dark</item>
<item name="android:statusBarColor">@android:color/transparent</item> <item name="android:statusBarColor">@android:color/transparent</item>
@ -35,6 +34,14 @@
<item name="snackbar_background">@color/snackbarBackground</item> <item name="snackbar_background">@color/snackbarBackground</item>
<item name="snackbar_text">@color/textColorPrimaryLight</item> <item name="snackbar_text">@color/textColorPrimaryLight</item>
<item name="android:navigationBarColor">@color/oldNavBarBackground</item> <item name="android:navigationBarColor">@color/oldNavBarBackground</item>
<!-- Material Dialog colors -->
<item name="md_color_title">@color/textColorPrimaryDark</item>
<item name="md_color_content">@color/textColorSecondaryDark</item>
<item name="md_color_button_text">@color/colorAccentDark</item>
<item name="md_background_color">@color/dialogDark</item>
<item name="md_corner_radius">16dp</item>
</style> </style>
<style name="Theme.Base.Reader" parent="Theme.Base"> <style name="Theme.Base.Reader" parent="Theme.Base">
@ -64,5 +71,13 @@
<item name="selectable_list_drawable">@drawable/list_item_selector_amoled</item> <item name="selectable_list_drawable">@drawable/list_item_selector_amoled</item>
<item name="selectable_library_drawable">@drawable/library_item_selector_amoled</item> <item name="selectable_library_drawable">@drawable/library_item_selector_amoled</item>
<item name="background_card">@color/dialog_amoled</item> <item name="background_card">@color/dialog_amoled</item>
<!-- Material Dialog colors -->
<item name="md_color_title">@color/textColorPrimaryDark</item>
<item name="md_color_content">@color/textColorSecondaryDark</item>
<item name="md_color_button_text">@color/colorAccentDark</item>
<item name="md_background_color">@color/dialog_amoled</item>
<item name="md_corner_radius">16dp</item>
</style> </style>
</resources> </resources>

View File

@ -28,7 +28,6 @@
<item name="actionBarTheme">@style/Theme.ActionBar.Light</item> <item name="actionBarTheme">@style/Theme.ActionBar.Light</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item> <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
<item name="alertDialogTheme">@style/Theme.AlertDialog.Light</item> <item name="alertDialogTheme">@style/Theme.AlertDialog.Light</item>
<item name="md_background_color">@color/dialogLight</item>
<!-- Custom Attributes--> <!-- Custom Attributes-->
@ -43,6 +42,13 @@
<item name="android:statusBarColor">@android:color/transparent</item> <item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">#B3000000</item> <item name="android:navigationBarColor">#B3000000</item>
<!-- Material Dialog colors -->
<item name="md_color_title">@color/textColorPrimaryLight</item>
<item name="md_color_content">@color/textColorSecondaryLight</item>
<item name="md_color_button_text">@color/colorAccent</item>
<item name="md_background_color">@color/dialogLight</item>
<item name="md_corner_radius">16dp</item>
</style> </style>
<style name="Theme.Tachiyomi" parent="Theme.Base"/> <style name="Theme.Tachiyomi" parent="Theme.Base"/>