forked from tachiyomiorg/extensions-lib
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Reduce a bit of overhead (#11)
* chore(json-extensions): Remove unnecessary use {} blocks * chore(coroutines-extensions): Replace runCatching with try-catch * fix(ConfigurableAnimeSource): Remove crash-inducing exposed function
- Loading branch information
1 parent
a6a259f
commit 32eb20c
Showing
3 changed files
with
16 additions
and
32 deletions.
There are no files selected for viewing
29 changes: 6 additions & 23 deletions
29
library/src/main/java/eu/kanade/tachiyomi/animesource/ConfigurableAnimeSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,32 @@ | ||
package eu.kanade.tachiyomi.animesource | ||
|
||
import android.content.SharedPreferences | ||
import androidx.preference.PreferenceScreen | ||
|
||
/** | ||
* A interface to add user preferences to the source. | ||
*/ | ||
interface ConfigurableAnimeSource { | ||
|
||
/** | ||
* Gets instance of [SharedPreferences] scoped to the specific source. | ||
* | ||
* @since extensions-lib 14 | ||
*/ | ||
fun getSourcePreferences(): SharedPreferences = throw Exception("stub!") | ||
|
||
/** | ||
* Implementations must override this method to add the user preferences. | ||
* | ||
* | ||
* You can use some stubbed inheritors of [androidx.preference.Preference] here. | ||
* | ||
* | ||
* **Common usage example:** | ||
* ``` | ||
* // ============================== Settings ============================== | ||
* override fun setupPreferenceScreen(screen: PreferenceScreen) { | ||
* val videoQualityPref = ListPreference(screen.context).apply { | ||
* ListPreference(screen.context).apply { | ||
* key = PREF_QUALITY_KEY // String, like "pref_quality" | ||
* title = PREF_QUALITY_TITLE // String, like "Preferred quality:" | ||
* title = PREF_QUALITY_TITLE // String, like "Preferred quality:" | ||
* entries = PREF_QUALITY_ENTRIES // Array<String>, like arrayOf("240p", "720p"...) | ||
* // Another Array<String>. Can be different from the property above, as long it have the same size | ||
* // and equivalent values per index. | ||
* entryValues = PREF_QUALITY_VALUES | ||
* entryValues = PREF_QUALITY_VALUES | ||
* setDefaultValue(PREF_QUALITY_DEFAULT) | ||
* summary = "%s" | ||
* setOnPreferenceChangeListener { _, newValue -> | ||
* val selected = newValue as String | ||
* val index = findIndexOfValue(selected) | ||
* val entry = entryValues[index] as String | ||
* preferences.edit().putString(key, entry).commit() | ||
* } | ||
* } | ||
* screen.addPreference(videoQualityPref) | ||
* }.also(screen::addPreference) | ||
* } | ||
* ``` | ||
*/ | ||
fun setupPreferenceScreen(screen: PreferenceScreen) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters