Refactor search, favorites and calendar widget
This commit is contained in:
@@ -7,6 +7,5 @@ import org.koin.dsl.module
|
||||
|
||||
val unitConverterModule = module {
|
||||
single { CurrencyRepository(androidContext()) }
|
||||
single { UnitConverterRepository(androidContext()) }
|
||||
viewModel { UnitConverterViewModel(get()) }
|
||||
single<UnitConverterRepository> { UnitConverterRepositoryImpl(androidContext()) }
|
||||
}
|
||||
+9
-5
@@ -2,15 +2,19 @@ package de.mm20.launcher2.unitconverter
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import de.mm20.launcher2.currencies.CurrencyRepository
|
||||
import de.mm20.launcher2.search.BaseSearchableRepository
|
||||
import de.mm20.launcher2.search.data.UnitConverter
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
|
||||
class UnitConverterRepository(val context: Context) : BaseSearchableRepository() {
|
||||
interface UnitConverterRepository {
|
||||
fun search(query:String): Flow<UnitConverter?>
|
||||
}
|
||||
|
||||
class UnitConverterRepositoryImpl(val context: Context) : UnitConverterRepository {
|
||||
|
||||
val unitConverter = MutableLiveData<UnitConverter?>()
|
||||
|
||||
override suspend fun search(query: String) {
|
||||
unitConverter.value = UnitConverter.search(context, query)
|
||||
override fun search(query: String): Flow<UnitConverter?> = channelFlow {
|
||||
send(UnitConverter.search(context, query))
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package de.mm20.launcher2.unitconverter
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class UnitConverterViewModel(
|
||||
unitConverterRepository: UnitConverterRepository
|
||||
): ViewModel() {
|
||||
val unitConverter = unitConverterRepository.unitConverter
|
||||
}
|
||||
Reference in New Issue
Block a user