-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/animesource/utils/Preferences.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package eu.kanade.tachiyomi.animesource.utils | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import eu.kanade.tachiyomi.animesource.AnimeSource | ||
import uy.kohesive.injekt.Injekt | ||
import uy.kohesive.injekt.api.get | ||
|
||
/** | ||
* Gets preference key for source with [id]. | ||
*/ | ||
fun preferencesKey(id: Long) = "source_$id" | ||
|
||
/** | ||
* Gets preference key for source. | ||
*/ | ||
fun AnimeSource.preferencesKey(): String = preferencesKey(id) | ||
|
||
/** | ||
* Gets instance of [SharedPreferences] scoped to the specific source key. | ||
*/ | ||
fun sourcePreferences(key: String): SharedPreferences = | ||
Injekt.get<Application>().getSharedPreferences(key, Context.MODE_PRIVATE) | ||
|
||
/** | ||
* Gets instance of [SharedPreferences] scoped to the specific source. | ||
* | ||
* @since extensions-lib 16 | ||
*/ | ||
fun AnimeSource.sourcePreferences(): SharedPreferences = sourcePreferences(preferencesKey()) | ||
|
||
/** | ||
* Gets instance of [SharedPreferences] scoped to the specific source id. | ||
* | ||
* @since extensions-lib 16 | ||
* | ||
* @param id source id which the [SharedPreferences] is scoped to. | ||
*/ | ||
fun sourcePreferences(id: Long): SharedPreferences = sourcePreferences(preferencesKey(id)) |
18 changes: 18 additions & 0 deletions
18
source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/util/JsonExtensions.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package eu.kanade.tachiyomi.util | ||
|
||
import kotlinx.serialization.json.Json | ||
import uy.kohesive.injekt.Injekt | ||
import uy.kohesive.injekt.api.get | ||
|
||
/** | ||
* App provided default [Json] instance. Configured as | ||
* ``` | ||
* Json { | ||
* ignoreUnknownKeys = true | ||
* explicitNulls = false | ||
* } | ||
* ``` | ||
* | ||
* @since extensions-lib 16 | ||
*/ | ||
val defaultJson: Json = Injekt.get<Json>() |