refactor: migrate resource handling to new data.resources module

This commit is contained in:
2026-07-02 16:55:14 +02:00
parent c307111ec1
commit 0c4dbff929
10 changed files with 102 additions and 19 deletions
+66
View File
@@ -0,0 +1,66 @@
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidMultiplatformLibrary)
alias(libs.plugins.composeMultiplatform)
alias(libs.plugins.composeCompiler)
}
kotlin {
iosArm64()
iosSimulatorArm64()
jvm()
js {
browser()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser()
}
androidLibrary {
namespace = "fr.ajaury.gwenedeg.resources"
compileSdk =
libs.versions.androidCompileSdk
.get()
.toInt()
minSdk =
libs.versions.androidMinSdk
.get()
.toInt()
compilerOptions {
jvmTarget = JvmTarget.JVM_11
}
androidResources {
enable = true
}
}
sourceSets {
commonMain.dependencies {
// Core modules
implementation(projects.core.coroutines)
// Compose resources
implementation(libs.compose.runtime)
implementation(libs.compose.components.resources)
// Coroutines
implementation(libs.kotlinx.coroutinesCore)
// DI
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)
}
}
}
compose.resources {
packageOfResClass = "fr.ajaury.gwenedeg.resources.generated.resources"
}
@@ -0,0 +1,44 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="450dp"
android:height="450dp"
android:viewportWidth="64"
android:viewportHeight="64">
<path
android:pathData="M56.25,18V46L32,60 7.75,46V18L32,4Z"
android:fillColor="#6075f2"/>
<path
android:pathData="m41.5,26.5v11L32,43V60L56.25,46V18Z"
android:fillColor="#6b57ff"/>
<path
android:pathData="m32,43 l-9.5,-5.5v-11L7.75,18V46L32,60Z">
<aapt:attr name="android:fillColor">
<gradient
android:centerX="23.131"
android:centerY="18.441"
android:gradientRadius="42.132"
android:type="radial">
<item android:offset="0" android:color="#FF5383EC"/>
<item android:offset="0.867" android:color="#FF7F52FF"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M22.5,26.5 L32,21 41.5,26.5 56.25,18 32,4 7.75,18Z">
<aapt:attr name="android:fillColor">
<gradient
android:startX="44.172"
android:startY="4.377"
android:endX="17.973"
android:endY="34.035"
android:type="linear">
<item android:offset="0" android:color="#FF33C3FF"/>
<item android:offset="0.878" android:color="#FF5383EC"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="m32,21 l9.526,5.5v11L32,43 22.474,37.5v-11z"
android:fillColor="#000000"/>
</vector>
@@ -0,0 +1,17 @@
package fr.ajaury.gwenedeg.resources.data
import fr.ajaury.gwenedeg.core.coroutines.domain.DispatcherProvider
import fr.ajaury.gwenedeg.resources.domain.ResourceReader
import fr.ajaury.gwenedeg.resources.generated.resources.Res
import kotlinx.coroutines.withContext
internal class ComposeResourceReader(
private val dispatcherProvider: DispatcherProvider,
) : ResourceReader {
override suspend fun read(resourcePath: String): String =
withContext(dispatcherProvider.io) {
Res.readBytes(resourcePath).decodeToString()
}
override fun uri(resourcePath: String): String = Res.getUri(resourcePath)
}
@@ -0,0 +1,12 @@
package fr.ajaury.gwenedeg.resources.di
import fr.ajaury.gwenedeg.resources.data.ComposeResourceReader
import fr.ajaury.gwenedeg.resources.domain.ResourceReader
import org.koin.core.module.Module
import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.factoryOf
import org.koin.dsl.module
val resourcesModule: Module = module {
factoryOf(::ComposeResourceReader) { bind<ResourceReader>() }
}
@@ -0,0 +1,13 @@
package fr.ajaury.gwenedeg.resources.domain
/**
* Provides access to the app's bundled resources. Implemented by this module, which owns the
* resource bundle, so consumer modules stay free of any platform/resource dependency.
*/
interface ResourceReader {
/** Reads the raw text content of the resource at [resourcePath]. */
suspend fun read(resourcePath: String): String
/** Returns a platform URI pointing to the resource at [resourcePath]. */
fun uri(resourcePath: String): String
}