Option to open manga source in browser

master
Koitharu 2 years ago
parent af5df32fbe
commit 688a9fe4d5
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -706,7 +706,8 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
const val KEY_LINK_TELEGRAM = "about_telegram" const val KEY_LINK_TELEGRAM = "about_telegram"
const val KEY_LINK_GITHUB = "about_github" const val KEY_LINK_GITHUB = "about_github"
const val KEY_LINK_MANUAL = "about_help" 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 // old keys are for migration only
private const val KEY_IMAGES_PROXY_OLD = "images_proxy" private const val KEY_IMAGES_PROXY_OLD = "images_proxy"

@ -73,7 +73,7 @@ class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner {
if (filterCoordinator.isFilterApplied) { if (filterCoordinator.isFilterApplied) {
filterCoordinator.reset() filterCoordinator.reset()
} else { } else {
openInBrowser(null) openInBrowser(null) // should never be called
} }
} }

@ -166,7 +166,7 @@ open class RemoteListViewModel @Inject constructor(
icon = R.drawable.ic_empty_common, icon = R.drawable.ic_empty_common,
textPrimary = R.string.nothing_found, textPrimary = R.string.nothing_found,
textSecondary = 0, 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<ListModel>) = Unit protected open suspend fun onBuildList(list: MutableList<ListModel>) = Unit

@ -81,7 +81,7 @@ class ProxySettingsFragment : BasePreferenceFragment(R.string.proxy),
} }
override fun onPreferenceTreeClick(preference: Preference): Boolean = when (preference.key) { override fun onPreferenceTreeClick(preference: Preference): Boolean = when (preference.key) {
AppSettings.PROXY_TEST -> { AppSettings.KEY_PROXY_TEST -> {
testConnection() testConnection()
true true
} }
@ -102,13 +102,13 @@ class ProxySettingsFragment : BasePreferenceFragment(R.string.proxy),
findPreference<PreferenceCategory>(AppSettings.KEY_PROXY_AUTH)?.isEnabled = isProxyEnabled findPreference<PreferenceCategory>(AppSettings.KEY_PROXY_AUTH)?.isEnabled = isProxyEnabled
findPreference<Preference>(AppSettings.KEY_PROXY_LOGIN)?.isEnabled = isProxyEnabled findPreference<Preference>(AppSettings.KEY_PROXY_LOGIN)?.isEnabled = isProxyEnabled
findPreference<Preference>(AppSettings.KEY_PROXY_PASSWORD)?.isEnabled = isProxyEnabled findPreference<Preference>(AppSettings.KEY_PROXY_PASSWORD)?.isEnabled = isProxyEnabled
findPreference<Preference>(AppSettings.PROXY_TEST)?.isEnabled = isProxyEnabled && testJob?.isActive != true findPreference<Preference>(AppSettings.KEY_PROXY_TEST)?.isEnabled = isProxyEnabled && testJob?.isActive != true
} }
private fun testConnection() { private fun testConnection() {
testJob?.cancel() testJob?.cancel()
testJob = viewLifecycleScope.launch { testJob = viewLifecycleScope.launch {
val pref = findPreference<Preference>(AppSettings.PROXY_TEST) val pref = findPreference<Preference>(AppSettings.KEY_PROXY_TEST)
pref?.run { pref?.run {
setSummary(R.string.loading_) setSummary(R.string.loading_)
isEnabled = false isEnabled = false

@ -7,6 +7,7 @@ import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.browser.BrowserActivity
import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver
import org.koitharu.kotatsu.core.model.getTitle import org.koitharu.kotatsu.core.model.getTitle
import org.koitharu.kotatsu.core.parser.EmptyMangaRepository import org.koitharu.kotatsu.core.parser.EmptyMangaRepository
@ -74,6 +75,12 @@ class SourceSettingsFragment : BasePreferenceFragment(0), Preference.OnPreferenc
viewModel.isEnabled.observe(viewLifecycleOwner) { enabled -> viewModel.isEnabled.observe(viewLifecycleOwner) { enabled ->
findPreference<SwitchPreferenceCompat>(KEY_ENABLE)?.isChecked = enabled findPreference<SwitchPreferenceCompat>(KEY_ENABLE)?.isChecked = enabled
} }
viewModel.browserUrl.observe(viewLifecycleOwner) {
findPreference<Preference>(AppSettings.KEY_OPEN_BROWSER)?.run {
isVisible = it != null
summary = it
}
}
viewModel.onActionDone.observeEvent(viewLifecycleOwner, ReversibleActionObserver(listView)) viewModel.onActionDone.observeEvent(viewLifecycleOwner, ReversibleActionObserver(listView))
} }
@ -84,6 +91,18 @@ class SourceSettingsFragment : BasePreferenceFragment(0), Preference.OnPreferenc
true 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 -> { AppSettings.KEY_COOKIES_CLEAR -> {
viewModel.clearCookies() viewModel.clearCookies()
true true

@ -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.CachingMangaRepository
import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.parser.ParserMangaRepository 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.prefs.SourceSettings
import org.koitharu.kotatsu.core.ui.BaseViewModel import org.koitharu.kotatsu.core.ui.BaseViewModel
import org.koitharu.kotatsu.core.ui.util.ReversibleAction import org.koitharu.kotatsu.core.ui.util.ReversibleAction
@ -36,12 +37,14 @@ class SourceSettingsViewModel @Inject constructor(
val onActionDone = MutableEventFlow<ReversibleAction>() val onActionDone = MutableEventFlow<ReversibleAction>()
val username = MutableStateFlow<String?>(null) val username = MutableStateFlow<String?>(null)
val browserUrl = MutableStateFlow<String?>(null)
val isEnabled = mangaSourcesRepository.observeIsEnabled(source) val isEnabled = mangaSourcesRepository.observeIsEnabled(source)
private var usernameLoadJob: Job? = null private var usernameLoadJob: Job? = null
init { init {
when (repository) { when (repository) {
is ParserMangaRepository -> { is ParserMangaRepository -> {
browserUrl.value = "https://${repository.domain}"
repository.getConfig().subscribe(this) repository.getConfig().subscribe(this)
loadUsername(repository.getAuthProvider()) loadUsername(repository.getAuthProvider())
} }
@ -58,11 +61,14 @@ class SourceSettingsViewModel @Inject constructor(
} }
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (repository) { if (repository is CachingMangaRepository) {
is CachingMangaRepository -> { if (key != SourceSettings.KEY_SLOWDOWN && key != SourceSettings.KEY_SORT_ORDER) {
if (key != SourceSettings.KEY_SLOWDOWN && key != SourceSettings.KEY_SORT_ORDER) { repository.invalidateCache()
repository.invalidateCache() }
} }
if (repository is ParserMangaRepository) {
if (key == AppSettings.KEY_OPEN_BROWSER) {
browserUrl.value = "https://${repository.domain}"
} }
} }
} }

@ -25,6 +25,13 @@
android:title="@string/download_over_cellular" android:title="@string/download_over_cellular"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
<Preference
android:icon="@drawable/ic_info_outline"
android:key="tracker_notifications_info"
android:persistent="false"
android:selectable="false"
android:summary="@string/downloads_settings_info" />
<Preference <Preference
android:key="ignore_dose" android:key="ignore_dose"
android:persistent="false" android:persistent="false"
@ -33,14 +40,6 @@
app:allowDividerAbove="true" app:allowDividerAbove="true"
app:isPreferenceVisible="false" /> app:isPreferenceVisible="false" />
<Preference
android:icon="@drawable/ic_info_outline"
android:key="tracker_notifications_info"
android:persistent="false"
android:selectable="false"
android:summary="@string/downloads_settings_info"
app:allowDividerAbove="true" />
<PreferenceCategory android:title="@string/pages_saving"> <PreferenceCategory android:title="@string/pages_saving">
<Preference <Preference

@ -18,4 +18,13 @@
android:summary="@string/download_slowdown_summary" android:summary="@string/download_slowdown_summary"
android:title="@string/download_slowdown" /> android:title="@string/download_slowdown" />
<Preference
android:icon="@drawable/ic_open_external"
android:key="open_browser"
android:order="500"
android:persistent="false"
android:title="@string/open_in_browser"
app:allowDividerAbove="true"
app:isPreferenceVisible="false" />
</PreferenceScreen> </PreferenceScreen>

Loading…
Cancel
Save