Improve sources settings
This commit is contained in:
@@ -66,8 +66,9 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig
|
||||
|
||||
companion object {
|
||||
|
||||
const val KEY_SORT_ORDER = "sort_order"
|
||||
const val KEY_SLOWDOWN = "slowdown"
|
||||
const val KEY_DOMAIN = "domain"
|
||||
const val KEY_NO_CAPTCHA = "no_captcha"
|
||||
const val KEY_SLOWDOWN = "slowdown"
|
||||
const val KEY_SORT_ORDER = "sort_order"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class ReadButtonDelegate(
|
||||
}
|
||||
|
||||
private fun openReader(isIncognitoMode: Boolean) {
|
||||
val manga = viewModel.manga.value ?: return
|
||||
val manga = viewModel.getMangaOrNull() ?: return
|
||||
if (viewModel.historyInfo.value.isChapterMissing) {
|
||||
Snackbar.make(buttonRead, R.string.chapter_is_missing, Snackbar.LENGTH_SHORT)
|
||||
.show() // TODO
|
||||
|
||||
@@ -2,7 +2,10 @@ package org.koitharu.kotatsu.settings.sources
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.EditTextPreferenceDialogFragmentCompat
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
@@ -112,6 +115,20 @@ class SourceSettingsFragment : BasePreferenceFragment(0), Preference.OnPreferenc
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDisplayPreferenceDialog(preference: Preference) {
|
||||
if (preference.key == SourceSettings.KEY_DOMAIN) {
|
||||
if (parentFragmentManager.findFragmentByTag(DomainDialogFragment.DIALOG_FRAGMENT_TAG) != null) {
|
||||
return
|
||||
}
|
||||
val f = DomainDialogFragment.newInstance(preference.key)
|
||||
@Suppress("DEPRECATION")
|
||||
f.setTargetFragment(this, 0)
|
||||
f.show(parentFragmentManager, DomainDialogFragment.DIALOG_FRAGMENT_TAG)
|
||||
return
|
||||
}
|
||||
super.onDisplayPreferenceDialog(preference)
|
||||
}
|
||||
|
||||
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
|
||||
when (preference.key) {
|
||||
KEY_ENABLE -> viewModel.setEnabled(newValue == true)
|
||||
@@ -120,6 +137,32 @@ class SourceSettingsFragment : BasePreferenceFragment(0), Preference.OnPreferenc
|
||||
return true
|
||||
}
|
||||
|
||||
class DomainDialogFragment : EditTextPreferenceDialogFragmentCompat() {
|
||||
|
||||
override fun onPrepareDialogBuilder(builder: AlertDialog.Builder) {
|
||||
super.onPrepareDialogBuilder(builder)
|
||||
builder.setNeutralButton(R.string.reset) { _, _ ->
|
||||
resetValue()
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetValue() {
|
||||
val editTextPreference = preference as EditTextPreference
|
||||
if (editTextPreference.callChangeListener("")) {
|
||||
editTextPreference.text = ""
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val DIALOG_FRAGMENT_TAG: String = "androidx.preference.PreferenceFragment.DIALOG"
|
||||
|
||||
fun newInstance(key: String) = DomainDialogFragment().withArgs(1) {
|
||||
putString(ARG_KEY, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val KEY_AUTH = "auth"
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||
import org.koitharu.kotatsu.core.parser.CachingMangaRepository
|
||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||
import org.koitharu.kotatsu.core.parser.ParserMangaRepository
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
||||
import org.koitharu.kotatsu.core.ui.util.ReversibleAction
|
||||
@@ -69,7 +68,7 @@ class SourceSettingsViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
if (repository is ParserMangaRepository) {
|
||||
if (key == AppSettings.KEY_OPEN_BROWSER) {
|
||||
if (key == SourceSettings.KEY_DOMAIN) {
|
||||
browserUrl.value = "https://${repository.domain}"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user