|
|
|
@ -3,67 +3,42 @@ package org.koitharu.kotatsu.settings
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.View
|
|
|
|
import android.view.View
|
|
|
|
import androidx.preference.ListPreference
|
|
|
|
|
|
|
|
import androidx.preference.Preference
|
|
|
|
import androidx.preference.Preference
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
|
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.network.DoHProvider
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
|
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
|
|
import org.koitharu.kotatsu.core.ui.BasePreferenceFragment
|
|
|
|
import org.koitharu.kotatsu.core.ui.BasePreferenceFragment
|
|
|
|
import org.koitharu.kotatsu.core.ui.dialog.StorageSelectDialog
|
|
|
|
import org.koitharu.kotatsu.core.ui.dialog.StorageSelectDialog
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.getStorageName
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.getStorageName
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.setDefaultValueCompat
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.viewLifecycleScope
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.viewLifecycleScope
|
|
|
|
import org.koitharu.kotatsu.download.ui.worker.DownloadWorker
|
|
|
|
import org.koitharu.kotatsu.download.ui.worker.DownloadWorker
|
|
|
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
|
|
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
|
|
|
import org.koitharu.kotatsu.parsers.util.names
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.util.ext.printStackTraceDebug
|
|
|
|
import org.koitharu.kotatsu.util.ext.printStackTraceDebug
|
|
|
|
import java.io.File
|
|
|
|
import java.io.File
|
|
|
|
import java.net.Proxy
|
|
|
|
|
|
|
|
import javax.inject.Inject
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
|
|
|
|
@AndroidEntryPoint
|
|
|
|
@AndroidEntryPoint
|
|
|
|
class ContentSettingsFragment :
|
|
|
|
class DownloadsSettingsFragment :
|
|
|
|
BasePreferenceFragment(R.string.content),
|
|
|
|
BasePreferenceFragment(R.string.downloads),
|
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener,
|
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener,
|
|
|
|
StorageSelectDialog.OnStorageSelectListener {
|
|
|
|
StorageSelectDialog.OnStorageSelectListener {
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
@Inject
|
|
|
|
lateinit var storageManager: LocalStorageManager
|
|
|
|
lateinit var storageManager: LocalStorageManager
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
|
|
|
lateinit var contentCache: ContentCache
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
@Inject
|
|
|
|
lateinit var downloadsScheduler: DownloadWorker.Scheduler
|
|
|
|
lateinit var downloadsScheduler: DownloadWorker.Scheduler
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_content)
|
|
|
|
addPreferencesFromResource(R.xml.pref_downloads)
|
|
|
|
findPreference<Preference>(AppSettings.KEY_PREFETCH_CONTENT)?.isVisible = contentCache.isCachingEnabled
|
|
|
|
|
|
|
|
findPreference<ListPreference>(AppSettings.KEY_DOH)?.run {
|
|
|
|
|
|
|
|
entryValues = arrayOf(
|
|
|
|
|
|
|
|
DoHProvider.NONE,
|
|
|
|
|
|
|
|
DoHProvider.GOOGLE,
|
|
|
|
|
|
|
|
DoHProvider.CLOUDFLARE,
|
|
|
|
|
|
|
|
DoHProvider.ADGUARD,
|
|
|
|
|
|
|
|
).names()
|
|
|
|
|
|
|
|
setDefaultValueCompat(DoHProvider.NONE.name)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
findPreference<Preference>(AppSettings.KEY_LOCAL_STORAGE)?.bindStorageName()
|
|
|
|
findPreference<Preference>(AppSettings.KEY_LOCAL_STORAGE)?.bindStorageName()
|
|
|
|
findPreference<Preference>(AppSettings.KEY_SUGGESTIONS)?.setSummary(
|
|
|
|
|
|
|
|
if (settings.isSuggestionsEnabled) R.string.enabled else R.string.disabled,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
bindRemoteSourcesSummary()
|
|
|
|
|
|
|
|
bindProxySummary()
|
|
|
|
|
|
|
|
settings.subscribe(this)
|
|
|
|
settings.subscribe(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -78,29 +53,9 @@ class ContentSettingsFragment :
|
|
|
|
findPreference<Preference>(key)?.bindStorageName()
|
|
|
|
findPreference<Preference>(key)?.bindStorageName()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AppSettings.KEY_SUGGESTIONS -> {
|
|
|
|
|
|
|
|
findPreference<Preference>(AppSettings.KEY_SUGGESTIONS)?.setSummary(
|
|
|
|
|
|
|
|
if (settings.isSuggestionsEnabled) R.string.enabled else R.string.disabled,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AppSettings.KEY_SOURCES_HIDDEN -> {
|
|
|
|
|
|
|
|
bindRemoteSourcesSummary()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AppSettings.KEY_DOWNLOADS_WIFI -> {
|
|
|
|
AppSettings.KEY_DOWNLOADS_WIFI -> {
|
|
|
|
updateDownloadsConstraints()
|
|
|
|
updateDownloadsConstraints()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AppSettings.KEY_SSL_BYPASS -> {
|
|
|
|
|
|
|
|
Snackbar.make(listView, R.string.settings_apply_restart_required, Snackbar.LENGTH_INDEFINITE).show()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AppSettings.KEY_PROXY_TYPE,
|
|
|
|
|
|
|
|
AppSettings.KEY_PROXY_ADDRESS,
|
|
|
|
|
|
|
|
AppSettings.KEY_PROXY_PORT -> {
|
|
|
|
|
|
|
|
bindProxySummary()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -131,26 +86,6 @@ class ContentSettingsFragment :
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun bindRemoteSourcesSummary() {
|
|
|
|
|
|
|
|
findPreference<Preference>(AppSettings.KEY_REMOTE_SOURCES)?.run {
|
|
|
|
|
|
|
|
val total = settings.remoteMangaSources.size
|
|
|
|
|
|
|
|
summary = getString(R.string.enabled_d_of_d, total - settings.hiddenSources.size, total)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun bindProxySummary() {
|
|
|
|
|
|
|
|
findPreference<Preference>(AppSettings.KEY_PROXY)?.run {
|
|
|
|
|
|
|
|
val type = settings.proxyType
|
|
|
|
|
|
|
|
val address = settings.proxyAddress
|
|
|
|
|
|
|
|
val port = settings.proxyPort
|
|
|
|
|
|
|
|
summary = if (type == Proxy.Type.DIRECT || address.isNullOrEmpty() || port == 0) {
|
|
|
|
|
|
|
|
context.getString(R.string.disabled)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
"$address:$port"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun updateDownloadsConstraints() {
|
|
|
|
private fun updateDownloadsConstraints() {
|
|
|
|
val preference = findPreference<Preference>(AppSettings.KEY_DOWNLOADS_WIFI)
|
|
|
|
val preference = findPreference<Preference>(AppSettings.KEY_DOWNLOADS_WIFI)
|
|
|
|
viewLifecycleScope.launch {
|
|
|
|
viewLifecycleScope.launch {
|