Implement Android ContextWrapper

This commit is contained in:
Syer10
2022-06-06 21:47:22 -04:00
parent 7807372355
commit a88b57e797
4 changed files with 10 additions and 10 deletions

View File

@@ -21,7 +21,7 @@ class AppMigrations @Inject constructor(
if (oldVersion < BuildConfig.VERSION_CODE) {
migrationPreferences.appVersion().set(BuildConfig.VERSION_CODE)
UpdateCheckWorker.setupTask(contextWrapper.context)
UpdateCheckWorker.setupTask(contextWrapper)
// Fresh install
if (oldVersion == 0) {

View File

@@ -12,6 +12,6 @@ import io.kamel.image.config.resourcesFetcher
import io.kamel.image.config.resourcesIdMapper
actual fun KamelConfigBuilder.kamelPlatformHandler(contextWrapper: ContextWrapper) {
resourcesIdMapper(contextWrapper.context)
resourcesFetcher(contextWrapper.context)
resourcesIdMapper(contextWrapper)
resourcesFetcher(contextWrapper)
}

View File

@@ -17,12 +17,11 @@ internal actual fun startDownloadService(
downloadService: DownloadService,
actions: WebsocketService.Actions
) {
val context = contextWrapper.context
val intent = Intent(
context,
contextWrapper,
Class.forName("ca.gosyer.jui.android.data.download.AndroidDownloadService")
).apply {
action = actions.name
}
ContextCompat.startForegroundService(context, intent)
ContextCompat.startForegroundService(contextWrapper, intent)
}

View File

@@ -7,24 +7,25 @@
package ca.gosyer.jui.uicore.vm
import android.content.Context
import android.content.ContextWrapper
import android.widget.Toast
import dev.icerock.moko.resources.StringResource
import dev.icerock.moko.resources.desc.desc
import dev.icerock.moko.resources.format
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 {
return stringResource.desc().toString(context)
return stringResource.desc().toString(this)
}
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) {
Toast.makeText(
context,
this,
string,
when (length) {
Length.SHORT -> Toast.LENGTH_SHORT