Show hidden app count in preference
This commit is contained in:
@@ -77,4 +77,8 @@
|
||||
<string name="product">Product</string>
|
||||
<string name="app_drawer_section_apps">Apps</string>
|
||||
<string name="hidden_apps_label">Hidden apps</string>
|
||||
<plurals name="hidden_apps_count">
|
||||
<item quantity="one">%1$d app hidden</item>
|
||||
<item quantity="other">%1$d apps hidden</item>
|
||||
</plurals>
|
||||
</resources>
|
||||
|
||||
@@ -86,6 +86,7 @@ fun AppDrawerPreferences() {
|
||||
PreferenceGroup(heading = stringResource(id = R.string.app_drawer_section_apps)) {
|
||||
NavigationActionPreference(
|
||||
label = stringResource(id = R.string.hidden_apps_label),
|
||||
subtitle = hiddenAppsCount(),
|
||||
destination = subRoute(name = AppDrawerRoutes.HIDDEN_APPS),
|
||||
showDivider = false
|
||||
)
|
||||
|
||||
@@ -4,11 +4,12 @@ import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import app.lawnchair.ui.preferences.components.*
|
||||
import app.lawnchair.util.*
|
||||
import app.lawnchair.util.preferences.getAdapter
|
||||
import app.lawnchair.util.preferences.getState
|
||||
import app.lawnchair.util.preferences.preferenceManager
|
||||
import com.android.launcher3.R
|
||||
import java.util.*
|
||||
@@ -22,7 +23,7 @@ fun NavGraphBuilder.hiddenAppsGraph(route: String) {
|
||||
@ExperimentalAnimationApi
|
||||
@Composable
|
||||
fun HiddenAppsPreferences() {
|
||||
pageMeta.provide(Meta(title = stringResource(id = R.string.hidden_apps_label)))
|
||||
pageMeta.provide(Meta(title = hiddenAppsCount()))
|
||||
var hiddenApps by preferenceManager().hiddenAppSet.getAdapter()
|
||||
val optionalApps by appsList(
|
||||
filter = defaultAppFilter(),
|
||||
@@ -52,6 +53,15 @@ fun HiddenAppsPreferences() {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun hiddenAppsCount(): String {
|
||||
val resources = LocalContext.current.resources
|
||||
val count = preferenceManager().hiddenAppSet.getState().value.size
|
||||
return remember(count) {
|
||||
resources.getQuantityString(R.plurals.hidden_apps_count, count, count)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun hiddenAppsComparator(hiddenApps: Set<String>): Comparator<App> {
|
||||
return remember {
|
||||
|
||||
@@ -10,18 +10,19 @@ class PreferenceAdapter<T>(
|
||||
private val get: () -> T,
|
||||
private val set: (T) -> Unit
|
||||
) : BasePreferenceManager.PreferenceChangeListener {
|
||||
val state = mutableStateOf(get())
|
||||
private val stateInternal = mutableStateOf(get())
|
||||
val state: State<T> get() = stateInternal
|
||||
|
||||
fun onChange(newValue: T) {
|
||||
set(newValue)
|
||||
state.value = newValue
|
||||
stateInternal.value = newValue
|
||||
}
|
||||
|
||||
override fun onPreferenceChange(pref: BasePreferenceManager.PrefEntry<*>) {
|
||||
state.value = get()
|
||||
stateInternal.value = get()
|
||||
}
|
||||
|
||||
operator fun getValue(thisObj: Any?, property: KProperty<*>): T = state.value
|
||||
operator fun getValue(thisObj: Any?, property: KProperty<*>): T = stateInternal.value
|
||||
operator fun setValue(thisObj: Any?, property: KProperty<*>, newValue: T) {
|
||||
onChange(newValue)
|
||||
}
|
||||
@@ -39,6 +40,9 @@ fun <T> BasePreferenceManager.PrefEntry<T>.getAdapter(): PreferenceAdapter<T> {
|
||||
return getAdapter(this, ::get, ::set)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> BasePreferenceManager.PrefEntry<T>.getState() = getAdapter().state
|
||||
|
||||
@Composable
|
||||
fun <T> BasePreferenceManager.PrefEntry<T>.observeAsState(): State<T> {
|
||||
return getAdapter().state
|
||||
|
||||
Reference in New Issue
Block a user