Option to open manga source in browser

This commit is contained in:
Koitharu
2024-10-13 18:00:05 +03:00
parent af5df32fbe
commit 688a9fe4d5
8 changed files with 53 additions and 19 deletions

View File

@@ -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"

View File

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

View File

@@ -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<ListModel>) = Unit

View File

@@ -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<PreferenceCategory>(AppSettings.KEY_PROXY_AUTH)?.isEnabled = isProxyEnabled
findPreference<Preference>(AppSettings.KEY_PROXY_LOGIN)?.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() {
testJob?.cancel()
testJob = viewLifecycleScope.launch {
val pref = findPreference<Preference>(AppSettings.PROXY_TEST)
val pref = findPreference<Preference>(AppSettings.KEY_PROXY_TEST)
pref?.run {
setSummary(R.string.loading_)
isEnabled = false

View File

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

View File

@@ -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<ReversibleAction>()
val username = MutableStateFlow<String?>(null)
val browserUrl = MutableStateFlow<String?>(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}"
}
}
}

View File

@@ -25,6 +25,13 @@
android:title="@string/download_over_cellular"
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
android:key="ignore_dose"
android:persistent="false"
@@ -33,14 +40,6 @@
app:allowDividerAbove="true"
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">
<Preference

View File

@@ -18,4 +18,13 @@
android:summary="@string/download_slowdown_summary"
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>