Hello guys)
I using ROOM request-function inside my ViewModel class(like a “ClearData”). Help me please transfer my function “ClearData” to another class/interface and just call it from ViewModel class.
class TitleViewModel( val databasedao: CountDataBaseDao, application: Application): AndroidViewModel(application) {
//here different code
//This function i need to call from another place, i should manage this function at another place and here just call it
fun clearData(){
viewModelScope.launch {
databasedao.clear()
}
_count.value=0
}
}
what i want - something like that :
class TitleViewModel( val databasedao: CountDataBaseDao, application: Application): AndroidViewModel(application), WorkWithDataBase {
fun clear(){
clearDataWork()} //but i cant just call this function - interface want make me override this fun
}
My interface which contains function clearDataWork()
interface WorkWithDataBase {
fun clearDataWork(count: MutableLiveData<Int>,dataSource: CountDataBaseDao){
GlobalScope.launch {
dataSource.clear()
}
count.value=0
}
}
Totally i want recode my project GitHub - bboykot/myRepo to more SOLID (transfer dataBase functions to one place and call it in my ViewModels classes).
Help please.