From e4eb305cf7865a367e2b8c68581bda32deb998aa Mon Sep 17 00:00:00 2001 From: tornaco Date: Wed, 2 Nov 2022 18:32:24 +0800 Subject: [PATCH] [app] filter features --- .../tornaco/android/thanos/main/NavViewModel2.kt | 11 ++++++++++- .../tornaco/android/thanos/main/PrebuiltFeatures.kt | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/github/tornaco/android/thanos/main/NavViewModel2.kt b/android/app/src/main/java/github/tornaco/android/thanos/main/NavViewModel2.kt index f1f7a6133..4a20ca28c 100644 --- a/android/app/src/main/java/github/tornaco/android/thanos/main/NavViewModel2.kt +++ b/android/app/src/main/java/github/tornaco/android/thanos/main/NavViewModel2.kt @@ -85,7 +85,16 @@ class NavViewModel2 @Inject constructor(@ApplicationContext private val context: } fun loadFeatures() { - + viewModelScope.launch { + thanox.ifServiceInstalled { thanox -> + val feats = PrebuiltFeatures.all { + it.requiredFeature == null || thanox.hasFeature(it.requiredFeature) + } + _state.value = _state.value.copy( + features = feats + ) + } + } } fun loadCoreStatus() { diff --git a/android/app/src/main/java/github/tornaco/android/thanos/main/PrebuiltFeatures.kt b/android/app/src/main/java/github/tornaco/android/thanos/main/PrebuiltFeatures.kt index a92bd813f..608df3ff6 100644 --- a/android/app/src/main/java/github/tornaco/android/thanos/main/PrebuiltFeatures.kt +++ b/android/app/src/main/java/github/tornaco/android/thanos/main/PrebuiltFeatures.kt @@ -180,9 +180,11 @@ object PrebuiltFeatures { ) - fun all(): List { + fun all(filter: (FeatureItem) -> Boolean = { true }): List { return listOf( boost, secure, ext, notification, guide - ) + ).map { + it.copy(items = it.items.filter(filter)) + } } } \ No newline at end of file