mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-22 20:42:34 +01:00
Implement Android ContextWrapper
This commit is contained in:
@@ -21,7 +21,7 @@ class AppMigrations @Inject constructor(
|
|||||||
if (oldVersion < BuildConfig.VERSION_CODE) {
|
if (oldVersion < BuildConfig.VERSION_CODE) {
|
||||||
migrationPreferences.appVersion().set(BuildConfig.VERSION_CODE)
|
migrationPreferences.appVersion().set(BuildConfig.VERSION_CODE)
|
||||||
|
|
||||||
UpdateCheckWorker.setupTask(contextWrapper.context)
|
UpdateCheckWorker.setupTask(contextWrapper)
|
||||||
|
|
||||||
// Fresh install
|
// Fresh install
|
||||||
if (oldVersion == 0) {
|
if (oldVersion == 0) {
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ import io.kamel.image.config.resourcesFetcher
|
|||||||
import io.kamel.image.config.resourcesIdMapper
|
import io.kamel.image.config.resourcesIdMapper
|
||||||
|
|
||||||
actual fun KamelConfigBuilder.kamelPlatformHandler(contextWrapper: ContextWrapper) {
|
actual fun KamelConfigBuilder.kamelPlatformHandler(contextWrapper: ContextWrapper) {
|
||||||
resourcesIdMapper(contextWrapper.context)
|
resourcesIdMapper(contextWrapper)
|
||||||
resourcesFetcher(contextWrapper.context)
|
resourcesFetcher(contextWrapper)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,11 @@ internal actual fun startDownloadService(
|
|||||||
downloadService: DownloadService,
|
downloadService: DownloadService,
|
||||||
actions: WebsocketService.Actions
|
actions: WebsocketService.Actions
|
||||||
) {
|
) {
|
||||||
val context = contextWrapper.context
|
|
||||||
val intent = Intent(
|
val intent = Intent(
|
||||||
context,
|
contextWrapper,
|
||||||
Class.forName("ca.gosyer.jui.android.data.download.AndroidDownloadService")
|
Class.forName("ca.gosyer.jui.android.data.download.AndroidDownloadService")
|
||||||
).apply {
|
).apply {
|
||||||
action = actions.name
|
action = actions.name
|
||||||
}
|
}
|
||||||
ContextCompat.startForegroundService(context, intent)
|
ContextCompat.startForegroundService(contextWrapper, intent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,24 +7,25 @@
|
|||||||
package ca.gosyer.jui.uicore.vm
|
package ca.gosyer.jui.uicore.vm
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.ContextWrapper
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import dev.icerock.moko.resources.StringResource
|
import dev.icerock.moko.resources.StringResource
|
||||||
import dev.icerock.moko.resources.desc.desc
|
import dev.icerock.moko.resources.desc.desc
|
||||||
import dev.icerock.moko.resources.format
|
import dev.icerock.moko.resources.format
|
||||||
import me.tatarka.inject.annotations.Inject
|
import me.tatarka.inject.annotations.Inject
|
||||||
|
|
||||||
actual class ContextWrapper @Inject constructor(val context: Context) {
|
actual class ContextWrapper @Inject constructor(context: Context) : ContextWrapper(context) {
|
||||||
actual fun toPlatformString(stringResource: StringResource): String {
|
actual fun toPlatformString(stringResource: StringResource): String {
|
||||||
return stringResource.desc().toString(context)
|
return stringResource.desc().toString(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun toPlatformString(stringResource: StringResource, vararg args: Any): String {
|
actual fun toPlatformString(stringResource: StringResource, vararg args: Any): String {
|
||||||
return stringResource.format(*args).toString(context)
|
return stringResource.format(*args).toString(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun toast(string: String, length: Length) {
|
actual fun toast(string: String, length: Length) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
this,
|
||||||
string,
|
string,
|
||||||
when (length) {
|
when (length) {
|
||||||
Length.SHORT -> Toast.LENGTH_SHORT
|
Length.SHORT -> Toast.LENGTH_SHORT
|
||||||
|
|||||||
Reference in New Issue
Block a user