new: modularize data.preferences

This commit is contained in:
2026-07-03 09:39:04 +02:00
parent ddab9b642d
commit 0d7503f029
8 changed files with 36 additions and 3 deletions
+20
View File
@@ -0,0 +1,20 @@
plugins {
id("gwenedeg.kmp.library")
}
kotlin {
androidLibrary {
namespace = "fr.ajaury.gwenedeg.preferences"
}
sourceSets {
commonMain.dependencies {
// Coroutines
implementation(libs.kotlinx.coroutinesCore)
// DI
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)
}
}
}
@@ -0,0 +1,21 @@
package fr.ajaury.gwenedeg.preferences.data
import fr.ajaury.gwenedeg.preferences.domain.PreferencesRepository
import fr.ajaury.gwenedeg.preferences.model.SubtitlePreferences
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
internal class PreferencesRepositoryImpl : PreferencesRepository {
private val state = MutableStateFlow(SubtitlePreferences())
override val subtitlePreferences: StateFlow<SubtitlePreferences> = state.asStateFlow()
override fun setShowTranscription(enabled: Boolean) {
state.update { it.copy(showTranscription = enabled) }
}
override fun setShowTranslation(enabled: Boolean) {
state.update { it.copy(showTranslation = enabled) }
}
}
@@ -0,0 +1,12 @@
package fr.ajaury.gwenedeg.preferences.di
import fr.ajaury.gwenedeg.preferences.data.PreferencesRepositoryImpl
import fr.ajaury.gwenedeg.preferences.domain.PreferencesRepository
import org.koin.core.module.Module
import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
val preferencesModule: Module = module {
singleOf(::PreferencesRepositoryImpl) { bind<PreferencesRepository>() }
}
@@ -0,0 +1,12 @@
package fr.ajaury.gwenedeg.preferences.domain
import fr.ajaury.gwenedeg.preferences.model.SubtitlePreferences
import kotlinx.coroutines.flow.StateFlow
interface PreferencesRepository {
val subtitlePreferences: StateFlow<SubtitlePreferences>
fun setShowTranscription(enabled: Boolean)
fun setShowTranslation(enabled: Boolean)
}
@@ -0,0 +1,12 @@
package fr.ajaury.gwenedeg.preferences.model
/**
* User preferences controlling which subtitle lines are displayed on the player.
*
* @property showTranscription whether the Breton (BZH) transcription line is shown.
* @property showTranslation whether the French (FR) translation line is shown.
*/
data class SubtitlePreferences(
val showTranscription: Boolean = true,
val showTranslation: Boolean = true,
)