Refactor preferences module
This commit is contained in:
@@ -45,5 +45,6 @@ dependencies {
|
||||
implementation(libs.koin.android)
|
||||
|
||||
implementation(project(":core:base"))
|
||||
implementation(project(":core:preferences"))
|
||||
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package de.mm20.launcher2.calculator
|
||||
|
||||
import de.mm20.launcher2.preferences.search.CalculatorSearchSettings
|
||||
import de.mm20.launcher2.search.data.Calculator
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.mariuszgromada.math.mxparser.Expression
|
||||
@@ -12,16 +14,19 @@ interface CalculatorRepository {
|
||||
fun search(query: String): Flow<Calculator?>
|
||||
}
|
||||
|
||||
class CalculatorRepositoryImpl : CalculatorRepository, KoinComponent {
|
||||
class CalculatorRepositoryImpl(
|
||||
private val settings: CalculatorSearchSettings
|
||||
) : CalculatorRepository, KoinComponent {
|
||||
|
||||
|
||||
override fun search(query: String): Flow<Calculator?> = channelFlow {
|
||||
if (query.isBlank()) {
|
||||
send(null)
|
||||
return@channelFlow
|
||||
override fun search(query: String): Flow<Calculator?> {
|
||||
return settings.enabled.map {
|
||||
if (it && query.isNotBlank()) {
|
||||
queryCalculator(query)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
send(queryCalculator(query))
|
||||
}
|
||||
|
||||
private suspend fun queryCalculator(query: String): Calculator? {
|
||||
|
||||
@@ -3,5 +3,5 @@ package de.mm20.launcher2.calculator
|
||||
import org.koin.dsl.module
|
||||
|
||||
val calculatorModule = module {
|
||||
single<CalculatorRepository> { CalculatorRepositoryImpl() }
|
||||
single<CalculatorRepository> { CalculatorRepositoryImpl(get()) }
|
||||
}
|
||||
Reference in New Issue
Block a user