Option to disable link handling #1149
This commit is contained in:
@@ -402,7 +402,7 @@
|
||||
android:value="@bool/com_samsung_android_icon_container_has_icon_container" />
|
||||
|
||||
<activity-alias
|
||||
android:name="org.koitharu.kotatsu.details.ui.DetailsBYLinkActivity"
|
||||
android:name="org.koitharu.kotatsu.details.ui.DetailsByLinkActivity"
|
||||
android:exported="true"
|
||||
android:targetActivity="org.koitharu.kotatsu.details.ui.DetailsActivity">
|
||||
|
||||
|
||||
@@ -727,6 +727,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||
const val KEY_LINK_MANUAL = "about_help"
|
||||
const val KEY_PROXY_TEST = "proxy_test"
|
||||
const val KEY_OPEN_BROWSER = "open_browser"
|
||||
const val KEY_HANDLE_LINKS = "handle_links"
|
||||
|
||||
// old keys are for migration only
|
||||
private const val KEY_IMAGES_PROXY_OLD = "images_proxy"
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.view.View
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.TwoStatePreference
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
@@ -50,6 +51,11 @@ class SourcesSettingsFragment : BasePreferenceFragment(R.string.remote_sources)
|
||||
}
|
||||
}
|
||||
}
|
||||
findPreference<TwoStatePreference>(AppSettings.KEY_HANDLE_LINKS)?.let { pref ->
|
||||
viewModel.isLinksEnabled.observe(viewLifecycleOwner) {
|
||||
pref.isChecked = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPreferenceTreeClick(preference: Preference): Boolean = when (preference.key) {
|
||||
@@ -58,6 +64,11 @@ class SourcesSettingsFragment : BasePreferenceFragment(R.string.remote_sources)
|
||||
true
|
||||
}
|
||||
|
||||
AppSettings.KEY_HANDLE_LINKS -> {
|
||||
viewModel.setLinksEnabled((preference as TwoStatePreference).isChecked)
|
||||
true
|
||||
}
|
||||
|
||||
else -> super.onPreferenceTreeClick(preference)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
package org.koitharu.kotatsu.settings.sources
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|
||||
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
||||
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.plus
|
||||
@@ -13,8 +21,11 @@ import javax.inject.Inject
|
||||
@HiltViewModel
|
||||
class SourcesSettingsViewModel @Inject constructor(
|
||||
sourcesRepository: MangaSourcesRepository,
|
||||
@ApplicationContext private val context: Context,
|
||||
) : BaseViewModel() {
|
||||
|
||||
private val linksHandlerActivity = ComponentName(context, "org.koitharu.kotatsu.details.ui.DetailsByLinkActivity")
|
||||
|
||||
val enabledSourcesCount = sourcesRepository.observeEnabledSourcesCount()
|
||||
.withErrorHandling()
|
||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, -1)
|
||||
@@ -22,4 +33,20 @@ class SourcesSettingsViewModel @Inject constructor(
|
||||
val availableSourcesCount = sourcesRepository.observeAvailableSourcesCount()
|
||||
.withErrorHandling()
|
||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, -1)
|
||||
|
||||
val isLinksEnabled = MutableStateFlow(isLinksEnabled())
|
||||
|
||||
fun setLinksEnabled(isEnabled: Boolean) {
|
||||
context.packageManager.setComponentEnabledSetting(
|
||||
linksHandlerActivity,
|
||||
if (isEnabled) COMPONENT_ENABLED_STATE_ENABLED else COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP,
|
||||
)
|
||||
isLinksEnabled.value = isLinksEnabled()
|
||||
}
|
||||
|
||||
private fun isLinksEnabled(): Boolean {
|
||||
val state = context.packageManager.getComponentEnabledSetting(linksHandlerActivity)
|
||||
return state == COMPONENT_ENABLED_STATE_ENABLED || state == COMPONENT_ENABLED_STATE_DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
@@ -765,4 +765,6 @@
|
||||
<string name="max_backups_count">Max number of backups</string>
|
||||
<string name="delete_old_backups">Delete old backups</string>
|
||||
<string name="delete_old_backups_summary">Automatically delete old backup files to save storage space</string>
|
||||
<string name="handle_links">Handle links</string>
|
||||
<string name="handle_links_summary">Handle manga links from external applications (e.g. web browser). You may also need to enable it manually in the application\'s system settings</string>
|
||||
</resources>
|
||||
|
||||
@@ -32,4 +32,11 @@
|
||||
android:summary="@string/disable_nsfw_summary"
|
||||
android:title="@string/disable_nsfw" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="handle_links"
|
||||
android:persistent="false"
|
||||
android:summary="@string/handle_links_summary"
|
||||
android:title="@string/handle_links"
|
||||
app:allowDividerAbove="true" />
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
||||
|
||||
Reference in New Issue
Block a user