Skip to content

Commit 06b47f6

Browse files
committed
Add missing string
Limit app list recomposing frequency (#334)
1 parent d55a3a6 commit 06b47f6

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

app/src/main/java/com/bintianqi/owndroid/feature/applications/AppChooserScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ fun AppChooserScreen(
7373
params: Destination.ApplicationsList, vm: AppChooserViewModel,
7474
onChoosePackage: (String?) -> Unit,
7575
) {
76-
val packages by vm.packagesState.collectAsStateWithLifecycle()
76+
val packages by vm.displayPackagesState.collectAsStateWithLifecycle()
7777
val hf = LocalHapticFeedback.current
78-
val progress by vm.progressState.collectAsStateWithLifecycle()
78+
val progress by vm.displayedProgressState.collectAsStateWithLifecycle()
7979
var query by rememberSaveable { mutableStateOf("") }
8080
var searchMode by rememberSaveable { mutableStateOf(false) }
8181
var filter by rememberSaveable(stateSaver = SerializableSaver(AppChooserFilter.serializer())) {

app/src/main/java/com/bintianqi/owndroid/feature/applications/AppChooserViewModel.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,27 @@ import com.bintianqi.owndroid.PrivilegeHelper
99
import com.bintianqi.owndroid.utils.getInstalledAppsFlags
1010
import kotlinx.coroutines.Dispatchers
1111
import 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
1217
import kotlinx.coroutines.flow.update
1318
import kotlinx.coroutines.launch
1419
import kotlin.concurrent.atomics.AtomicInt
1520
import kotlin.concurrent.atomics.ExperimentalAtomicApi
1621
import kotlin.concurrent.atomics.update
1722

1823
class 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() {

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@
375375
<string name="no_matching_apps">没有符合条件的应用</string>
376376
<string name="suspend">挂起</string>
377377
<string name="hide">隐藏</string>
378+
<string name="unhide">取消隐藏</string>
378379
<string name="always_on_vpn">VPN保持打开</string>
379380
<string name="enable_lockdown">启用锁定</string>
380381
<string name="clear_current_config">清除当前配置</string>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@
409409
<string name="no_matching_apps">No matching apps</string>
410410
<string name="suspend">Suspend</string>
411411
<string name="hide">Hide</string>
412+
<string name="unhide">Unhide</string>
412413
<string name="always_on_vpn">Always-on VPN</string>
413414
<string name="enable_lockdown">Enable lockdown</string>
414415
<string name="clear_current_config">Clear current config</string>

0 commit comments

Comments
 (0)