Skip to content

Commit

Permalink
chore: align to ext lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Secozzi committed Feb 3, 2025
1 parent cbb627a commit ce5dd5c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
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))
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>()

0 comments on commit ce5dd5c

Please sign in to comment.