new: modularize data.preferences
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -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) }
|
||||
}
|
||||
}
|
||||
+12
@@ -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>() }
|
||||
}
|
||||
+12
@@ -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)
|
||||
}
|
||||
+12
@@ -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,
|
||||
)
|
||||
Reference in New Issue
Block a user