diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt index a465ffa4d..591616b49 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt @@ -706,7 +706,8 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) { const val KEY_LINK_TELEGRAM = "about_telegram" const val KEY_LINK_GITHUB = "about_github" const val KEY_LINK_MANUAL = "about_help" - const val PROXY_TEST = "proxy_test" + const val KEY_PROXY_TEST = "proxy_test" + const val KEY_OPEN_BROWSER = "open_browser" // old keys are for migration only private const val KEY_IMAGES_PROXY_OLD = "images_proxy" diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListFragment.kt index d07dedd78..0caec63bb 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListFragment.kt @@ -73,7 +73,7 @@ class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner { if (filterCoordinator.isFilterApplied) { filterCoordinator.reset() } else { - openInBrowser(null) + openInBrowser(null) // should never be called } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt index b397f429a..6ee783c4c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt @@ -166,7 +166,7 @@ open class RemoteListViewModel @Inject constructor( icon = R.drawable.ic_empty_common, textPrimary = R.string.nothing_found, textSecondary = 0, - actionStringRes = if (canResetFilter) R.string.reset_filter else R.string.open_in_browser, + actionStringRes = if (canResetFilter) R.string.reset_filter else 0, ) protected open suspend fun onBuildList(list: MutableList) = Unit diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/ProxySettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/ProxySettingsFragment.kt index 188b9f28c..c0203869f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/ProxySettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/ProxySettingsFragment.kt @@ -81,7 +81,7 @@ class ProxySettingsFragment : BasePreferenceFragment(R.string.proxy), } override fun onPreferenceTreeClick(preference: Preference): Boolean = when (preference.key) { - AppSettings.PROXY_TEST -> { + AppSettings.KEY_PROXY_TEST -> { testConnection() true } @@ -102,13 +102,13 @@ class ProxySettingsFragment : BasePreferenceFragment(R.string.proxy), findPreference(AppSettings.KEY_PROXY_AUTH)?.isEnabled = isProxyEnabled findPreference(AppSettings.KEY_PROXY_LOGIN)?.isEnabled = isProxyEnabled findPreference(AppSettings.KEY_PROXY_PASSWORD)?.isEnabled = isProxyEnabled - findPreference(AppSettings.PROXY_TEST)?.isEnabled = isProxyEnabled && testJob?.isActive != true + findPreference(AppSettings.KEY_PROXY_TEST)?.isEnabled = isProxyEnabled && testJob?.isActive != true } private fun testConnection() { testJob?.cancel() testJob = viewLifecycleScope.launch { - val pref = findPreference(AppSettings.PROXY_TEST) + val pref = findPreference(AppSettings.KEY_PROXY_TEST) pref?.run { setSummary(R.string.loading_) isEnabled = false diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsFragment.kt index ba9645bf6..88d62e1b5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsFragment.kt @@ -7,6 +7,7 @@ import androidx.preference.Preference import androidx.preference.SwitchPreferenceCompat import dagger.hilt.android.AndroidEntryPoint import org.koitharu.kotatsu.R +import org.koitharu.kotatsu.browser.BrowserActivity import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver import org.koitharu.kotatsu.core.model.getTitle import org.koitharu.kotatsu.core.parser.EmptyMangaRepository @@ -74,6 +75,12 @@ class SourceSettingsFragment : BasePreferenceFragment(0), Preference.OnPreferenc viewModel.isEnabled.observe(viewLifecycleOwner) { enabled -> findPreference(KEY_ENABLE)?.isChecked = enabled } + viewModel.browserUrl.observe(viewLifecycleOwner) { + findPreference(AppSettings.KEY_OPEN_BROWSER)?.run { + isVisible = it != null + summary = it + } + } viewModel.onActionDone.observeEvent(viewLifecycleOwner, ReversibleActionObserver(listView)) } @@ -84,6 +91,18 @@ class SourceSettingsFragment : BasePreferenceFragment(0), Preference.OnPreferenc true } + AppSettings.KEY_OPEN_BROWSER -> { + startActivity( + BrowserActivity.newIntent( + context = preference.context, + url = viewModel.browserUrl.value ?: return false, + source = viewModel.source, + title = viewModel.source.getTitle(preference.context), + ), + ) + true + } + AppSettings.KEY_COOKIES_CLEAR -> { viewModel.clearCookies() true diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsViewModel.kt index b241030a0..6d23b430d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsViewModel.kt @@ -13,6 +13,7 @@ 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 @@ -36,12 +37,14 @@ class SourceSettingsViewModel @Inject constructor( val onActionDone = MutableEventFlow() val username = MutableStateFlow(null) + val browserUrl = MutableStateFlow(null) val isEnabled = mangaSourcesRepository.observeIsEnabled(source) private var usernameLoadJob: Job? = null init { when (repository) { is ParserMangaRepository -> { + browserUrl.value = "https://${repository.domain}" repository.getConfig().subscribe(this) loadUsername(repository.getAuthProvider()) } @@ -58,11 +61,14 @@ class SourceSettingsViewModel @Inject constructor( } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { - when (repository) { - is CachingMangaRepository -> { - if (key != SourceSettings.KEY_SLOWDOWN && key != SourceSettings.KEY_SORT_ORDER) { - repository.invalidateCache() - } + if (repository is CachingMangaRepository) { + if (key != SourceSettings.KEY_SLOWDOWN && key != SourceSettings.KEY_SORT_ORDER) { + repository.invalidateCache() + } + } + if (repository is ParserMangaRepository) { + if (key == AppSettings.KEY_OPEN_BROWSER) { + browserUrl.value = "https://${repository.domain}" } } } diff --git a/app/src/main/res/xml/pref_downloads.xml b/app/src/main/res/xml/pref_downloads.xml index 7f7b7075d..386390436 100644 --- a/app/src/main/res/xml/pref_downloads.xml +++ b/app/src/main/res/xml/pref_downloads.xml @@ -25,6 +25,13 @@ android:title="@string/download_over_cellular" app:useSimpleSummaryProvider="true" /> + + - - + +