может кто-нибудь мне помочь, пожалуйста?
Код: Выделить всё
val viewModel= getNavViewModel(
parameters = {
parametersOf(
NetworkChecker(context).isInternetConnected
)
}
)
Код: Выделить всё
class MainViewModel(
private val productRepository: ProductRepository,
isInternetConnected: Boolean
) : ViewModel() {
val dataProduct = mutableStateOf(listOf())
val showProgressBar = mutableStateOf(false)
init {
refreshAllDataFromNet(isInternetConnected)
}
fun refreshAllDataFromNet(isInternetConnected: Boolean) {
viewModelScope.launch {
if (isInternetConnected) {
showProgressBar.value = true
}
val newDataProducts = async {
productRepository.getProducts(isInternetConnected)
}
updateData(newDataProducts.await())
showProgressBar.value = false
}
}
private fun updateData(products: List) {
dataProduct.value = products
}
}
Код: Выделить всё
val myModules = module {
single { androidContext().getSharedPreferences("data", Context.MODE_PRIVATE) }
single { createApiService() }
single
{ ProductRepositoryImpl(get()) }
viewModel { (isNetConnected: Boolean) -> MainViewModel(get(), isNetConnected) }
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... -injection