@@ -9,15 +9,27 @@ import com.bintianqi.owndroid.PrivilegeHelper
99import com.bintianqi.owndroid.utils.getInstalledAppsFlags
1010import kotlinx.coroutines.Dispatchers
1111import kotlinx.coroutines.flow.MutableStateFlow
12+ import kotlinx.coroutines.flow.SharingStarted
13+ import kotlinx.coroutines.flow.WhileSubscribed
14+ import kotlinx.coroutines.flow.distinctUntilChanged
15+ import kotlinx.coroutines.flow.sample
16+ import kotlinx.coroutines.flow.stateIn
1217import kotlinx.coroutines.flow.update
1318import kotlinx.coroutines.launch
1419import kotlin.concurrent.atomics.AtomicInt
1520import kotlin.concurrent.atomics.ExperimentalAtomicApi
1621import kotlin.concurrent.atomics.update
1722
1823class AppChooserViewModel (val application : MyApplication , val ph : PrivilegeHelper ) : ViewModel() {
19- val packagesState = MutableStateFlow (emptyList<AppChooserEntry >())
20- val progressState = MutableStateFlow (0F )
24+ private val packagesState = MutableStateFlow (emptyList<AppChooserEntry >())
25+ val displayPackagesState = packagesState
26+ .sample(10 )
27+ .stateIn(viewModelScope, SharingStarted .WhileSubscribed (1000 ), emptyList())
28+
29+ private val progressState = MutableStateFlow (0F )
30+ val displayedProgressState = progressState
31+ .sample(10 )
32+ .stateIn(viewModelScope, SharingStarted .WhileSubscribed (1000 ), 0F )
2133
2234 @OptIn(ExperimentalAtomicApi ::class )
2335 fun refreshPackageList () {
0 commit comments