Removed other sources

This commit is contained in:
Mio.
2025-06-28 00:06:48 +02:00
parent 965c2a4f43
commit 8ddfe82fd6
5479 changed files with 789 additions and 22912 deletions

View File

@@ -0,0 +1,13 @@
package keiyoushi.utils
/**
* Returns the first element that is an instances of specified type parameter T.
*
* @throws [NoSuchElementException] if no such element is found.
*/
inline fun <reified T> Iterable<*>.firstInstance(): T = first { it is T } as T
/**
* Returns the first element that is an instances of specified type parameter T, or `null` if element was not found.
*/
inline fun <reified T> Iterable<*>.firstInstanceOrNull(): T? = firstOrNull { it is T } as? T

View File

@@ -0,0 +1,15 @@
package keiyoushi.utils
import java.text.ParseException
import java.text.SimpleDateFormat
@Suppress("NOTHING_TO_INLINE")
inline fun SimpleDateFormat.tryParse(date: String?): Long {
date ?: return 0L
return try {
parse(date)?.time ?: 0L
} catch (_: ParseException) {
0L
}
}

View File

@@ -0,0 +1,28 @@
package keiyoushi.utils
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import okhttp3.Response
import uy.kohesive.injekt.injectLazy
val jsonInstance: Json by injectLazy()
/**
* Parses and serializes the String as the type <T>.
*/
inline fun <reified T> String.parseAs(json: Json = jsonInstance): T =
json.decodeFromString(this)
/**
* Parse and serialize the response body as the type <T>.
*/
inline fun <reified T> Response.parseAs(json: Json = jsonInstance): T =
json.decodeFromStream(body.byteStream())
/**
* Serializes the object to a JSON String.
*/
inline fun <reified T> T.toJsonString(json: Json = jsonInstance): String =
json.encodeToString(this)

View File

@@ -0,0 +1,28 @@
package keiyoushi.utils
import android.app.Application
import android.content.SharedPreferences
import eu.kanade.tachiyomi.source.online.HttpSource
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
/**
* Returns the [SharedPreferences] associated with current source id
*/
inline fun HttpSource.getPreferences(
migration: SharedPreferences.() -> Unit = { },
): SharedPreferences = getPreferences(id).also(migration)
/**
* Lazily returns the [SharedPreferences] associated with current source id
*/
inline fun HttpSource.getPreferencesLazy(
crossinline migration: SharedPreferences.() -> Unit = { }
) = lazy { getPreferences(migration) }
/**
* Returns the [SharedPreferences] associated with passed source id
*/
@Suppress("NOTHING_TO_INLINE")
inline fun getPreferences(sourceId: Long): SharedPreferences =
Injekt.get<Application>().getSharedPreferences("source_$sourceId", 0x0000)