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) { 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) {

View File

@@ -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)
} }

View File

@@ -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)
} }

View File

@@ -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