2024-04-07 16:56:24 -03:00
|
|
|
package com.geeksville.mesh.model
|
|
|
|
|
|
|
|
|
|
import androidx.lifecycle.ViewModel
|
|
|
|
|
import androidx.lifecycle.viewModelScope
|
|
|
|
|
import com.geeksville.mesh.android.Logging
|
|
|
|
|
import com.geeksville.mesh.database.MeshLogRepository
|
|
|
|
|
import com.geeksville.mesh.database.entity.MeshLog
|
|
|
|
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
2024-11-19 16:50:42 -03:00
|
|
|
import kotlinx.coroutines.flow.SharingStarted
|
2024-04-07 16:56:24 -03:00
|
|
|
import kotlinx.coroutines.flow.StateFlow
|
2024-11-19 16:50:42 -03:00
|
|
|
import kotlinx.coroutines.flow.stateIn
|
2024-04-07 16:56:24 -03:00
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
|
|
@HiltViewModel
|
|
|
|
|
class DebugViewModel @Inject constructor(
|
|
|
|
|
private val meshLogRepository: MeshLogRepository,
|
|
|
|
|
) : ViewModel(), Logging {
|
2024-11-19 16:50:42 -03:00
|
|
|
val meshLog: StateFlow<List<MeshLog>> = meshLogRepository.getAllLogs()
|
|
|
|
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())
|
2024-04-07 16:56:24 -03:00
|
|
|
|
|
|
|
|
init {
|
|
|
|
|
debug("DebugViewModel created")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onCleared() {
|
|
|
|
|
super.onCleared()
|
|
|
|
|
debug("DebugViewModel cleared")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun deleteAllLogs() = viewModelScope.launch(Dispatchers.IO) {
|
|
|
|
|
meshLogRepository.deleteAll()
|
|
|
|
|
}
|
|
|
|
|
}
|