Rename new method in ConfigurableSource to get preferences
Maybe fixes #9969
This commit is contained in:
parent
66a938779d
commit
afb1ee2200
4 changed files with 13 additions and 11 deletions
|
@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.data.track.Tracker
|
||||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
|
import eu.kanade.tachiyomi.source.sourcePreferences
|
||||||
import tachiyomi.domain.manga.model.Manga
|
import tachiyomi.domain.manga.model.Manga
|
||||||
import tachiyomi.domain.source.service.SourceManager
|
import tachiyomi.domain.source.service.SourceManager
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
@ -121,7 +122,7 @@ class Kavita(id: Long) : Tracker(id, "Kavita"), EnhancedTracker {
|
||||||
(0..7).map { bytes[it].toLong() and 0xff shl 8 * (7 - it) }
|
(0..7).map { bytes[it].toLong() and 0xff shl 8 * (7 - it) }
|
||||||
.reduce(Long::or) and Long.MAX_VALUE
|
.reduce(Long::or) and Long.MAX_VALUE
|
||||||
}
|
}
|
||||||
val preferences = (sourceManager.get(sourceId) as ConfigurableSource).getPreferences()
|
val preferences = (sourceManager.get(sourceId) as ConfigurableSource).sourcePreferences()
|
||||||
|
|
||||||
val prefApiUrl = preferences.getString("APIURL", "")
|
val prefApiUrl = preferences.getString("APIURL", "")
|
||||||
val prefApiKey = preferences.getString("APIKEY", "")
|
val prefApiKey = preferences.getString("APIKEY", "")
|
||||||
|
|
|
@ -10,8 +10,6 @@ import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
fun Source.icon(): Drawable? = Injekt.get<ExtensionManager>().getAppIconForSource(this.id)
|
fun Source.icon(): Drawable? = Injekt.get<ExtensionManager>().getAppIconForSource(this.id)
|
||||||
|
|
||||||
fun Source.getPreferenceKey(): String = "source_$id"
|
|
||||||
|
|
||||||
fun Source.toStubSource(): StubSource = StubSource(id = id, lang = lang, name = name)
|
fun Source.toStubSource(): StubSource = StubSource(id = id, lang = lang, name = name)
|
||||||
|
|
||||||
fun Source.getNameForMangaInfo(): String {
|
fun Source.getNameForMangaInfo(): String {
|
||||||
|
|
|
@ -39,7 +39,7 @@ import eu.kanade.presentation.util.Screen
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore
|
import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore
|
||||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
import eu.kanade.tachiyomi.source.getPreferenceKey
|
import eu.kanade.tachiyomi.source.sourcePreferences
|
||||||
import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito
|
import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito
|
||||||
import tachiyomi.domain.source.service.SourceManager
|
import tachiyomi.domain.source.service.SourceManager
|
||||||
import tachiyomi.presentation.core.components.material.Scaffold
|
import tachiyomi.presentation.core.components.material.Scaffold
|
||||||
|
@ -134,12 +134,9 @@ class SourcePreferencesFragment : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
private fun populateScreen(): PreferenceScreen {
|
private fun populateScreen(): PreferenceScreen {
|
||||||
val sourceId = requireArguments().getLong(SOURCE_ID)
|
val sourceId = requireArguments().getLong(SOURCE_ID)
|
||||||
val source = Injekt.get<SourceManager>().get(sourceId)!!
|
val source = Injekt.get<SourceManager>().get(sourceId)!! as ConfigurableSource
|
||||||
|
|
||||||
check(source is ConfigurableSource)
|
val dataStore = SharedPreferencesDataStore(source.sourcePreferences())
|
||||||
|
|
||||||
val sharedPreferences = requireContext().getSharedPreferences(source.getPreferenceKey(), Context.MODE_PRIVATE)
|
|
||||||
val dataStore = SharedPreferencesDataStore(sharedPreferences)
|
|
||||||
preferenceManager.preferenceDataStore = dataStore
|
preferenceManager.preferenceDataStore = dataStore
|
||||||
|
|
||||||
val sourceScreen = preferenceManager.createPreferenceScreen(requireContext())
|
val sourceScreen = preferenceManager.createPreferenceScreen(requireContext())
|
||||||
|
|
|
@ -13,8 +13,14 @@ interface ConfigurableSource : Source {
|
||||||
*
|
*
|
||||||
* @since extensions-lib 1.5
|
* @since extensions-lib 1.5
|
||||||
*/
|
*/
|
||||||
fun getPreferences(): SharedPreferences =
|
fun getSourcePreferences(): SharedPreferences =
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", Context.MODE_PRIVATE)
|
Injekt.get<Application>().getSharedPreferences(preferenceKey(), Context.MODE_PRIVATE)
|
||||||
|
|
||||||
fun setupPreferenceScreen(screen: PreferenceScreen)
|
fun setupPreferenceScreen(screen: PreferenceScreen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun ConfigurableSource.preferenceKey(): String = "source_$id"
|
||||||
|
|
||||||
|
// TODO: use getSourcePreferences once all extensions are on ext-lib 1.5
|
||||||
|
fun ConfigurableSource.sourcePreferences(): SharedPreferences =
|
||||||
|
Injekt.get<Application>().getSharedPreferences(preferenceKey(), Context.MODE_PRIVATE)
|
||||||
|
|
Reference in a new issue