From 904948dc7dab54ad3a6082345b44ced532dd1cf2 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Mon, 6 Jan 2020 19:03:36 +0100 Subject: [PATCH] Added empty states for all remaining screens Fixed some issues in the process as the MergeObservableList doesn't support additions or deletions, duh... --- .../magisk/redesign/log/LogViewModel.kt | 6 +++ .../magisk/redesign/module/ModuleViewModel.kt | 20 ++++++-- .../redesign/superuser/SuperuserViewModel.kt | 42 +++++++++++----- app/src/main/res/layout/fragment_log_md2.xml | 14 ++++++ .../res/layout/fragment_superuser_md2.xml | 3 +- .../main/res/layout/include_log_magisk.xml | 50 +++++++++++++------ app/src/main/res/values/strings_md2.xml | 4 ++ 7 files changed, 107 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/log/LogViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/log/LogViewModel.kt index 36d3df982..5993c161c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/log/LogViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/log/LogViewModel.kt @@ -10,6 +10,7 @@ import com.topjohnwu.magisk.extensions.subscribeK import com.topjohnwu.magisk.model.binding.BindingAdapter import com.topjohnwu.magisk.model.entity.recycler.ConsoleItem import com.topjohnwu.magisk.model.entity.recycler.LogItem +import com.topjohnwu.magisk.model.entity.recycler.TextItem import com.topjohnwu.magisk.model.events.SnackbarEvent import com.topjohnwu.magisk.redesign.compat.CompatViewModel import com.topjohnwu.magisk.redesign.compat.diffListOf @@ -27,6 +28,11 @@ class LogViewModel( private val repo: LogRepository ) : CompatViewModel() { + // --- empty view + + val itemEmpty = TextItem(R.string.log_data_none) + val itemMagiskEmpty = TextItem(R.string.log_data_magisk_none) + // --- main view val items = diffListOf() diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt index 25c50cc80..0c01db6f9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt @@ -2,6 +2,7 @@ package com.topjohnwu.magisk.redesign.module import androidx.annotation.WorkerThread import androidx.databinding.Bindable +import androidx.databinding.ObservableArrayList import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.R @@ -61,6 +62,13 @@ class ModuleViewModel( private val itemNoneInstalled = TextItem(R.string.module_install_none) private val itemNoneUpdatable = TextItem(R.string.module_update_none) + private val itemsInstalledHelpers = ObservableArrayList().also { + it.add(itemNoneInstalled) + } + private val itemsUpdatableHelpers = ObservableArrayList().also { + it.add(itemNoneUpdatable) + } + private val itemsInstalled = diffListOf() private val itemsUpdatable = diffListOf() private val itemsRemote = diffListOf() @@ -68,11 +76,11 @@ class ModuleViewModel( val adapter = adapterOf>() val items = MergeObservableList>() .insertItem(sectionActive) - .insertItem(itemNoneInstalled) + .insertList(itemsInstalledHelpers) .insertList(itemsInstalled) .insertItem(InstallModule) .insertItem(sectionUpdate) - .insertItem(itemNoneUpdatable) + .insertList(itemsUpdatableHelpers) .insertList(itemsUpdatable) .insertItem(sectionRemote) .insertList(itemsRemote)!! @@ -155,13 +163,17 @@ class ModuleViewModel( .applyViewModel(this) .observeOn(AndroidSchedulers.mainThread()) .doOnSuccess { itemsInstalled.update(it.first, it.second) } - .doOnSuccess { if (itemsInstalled.isNotEmpty()) items.remove(itemNoneInstalled) } + .doOnSuccess { + if (itemsInstalled.isNotEmpty()) itemsInstalledHelpers.remove(itemNoneInstalled) + } .observeOn(Schedulers.io()) .map { loadUpdates(it.first) } .observeOn(AndroidSchedulers.mainThread()) .map { it to itemsUpdatable.calculateDiff(it) } .doOnSuccess { itemsUpdatable.update(it.first, it.second) } - .doOnSuccess { if (itemsUpdatable.isNotEmpty()) items.remove(itemNoneUpdatable) } + .doOnSuccess { + if (itemsUpdatable.isNotEmpty()) itemsUpdatableHelpers.remove(itemNoneUpdatable) + } .ignoreElement()!! fun loadRemoteImplicit() = let { itemsRemote.clear(); itemsSearch.clear() } diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserViewModel.kt index 7a22b1e2a..2a994df2e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/superuser/SuperuserViewModel.kt @@ -2,6 +2,7 @@ package com.topjohnwu.magisk.redesign.superuser import android.content.pm.PackageManager import android.content.res.Resources +import androidx.databinding.ObservableArrayList import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R import com.topjohnwu.magisk.data.database.PolicyDao @@ -12,17 +13,20 @@ import com.topjohnwu.magisk.extensions.toggle import com.topjohnwu.magisk.model.entity.MagiskPolicy import com.topjohnwu.magisk.model.entity.recycler.PolicyItem import com.topjohnwu.magisk.model.entity.recycler.TappableHeadlineItem +import com.topjohnwu.magisk.model.entity.recycler.TextItem import com.topjohnwu.magisk.model.events.PolicyUpdateEvent import com.topjohnwu.magisk.model.events.SnackbarEvent import com.topjohnwu.magisk.model.events.dialog.BiometricDialog import com.topjohnwu.magisk.model.events.dialog.SuperuserRevokeDialog import com.topjohnwu.magisk.model.navigation.Navigation import com.topjohnwu.magisk.redesign.compat.CompatViewModel +import com.topjohnwu.magisk.redesign.compat.adapterOf import com.topjohnwu.magisk.redesign.compat.diffListOf import com.topjohnwu.magisk.redesign.compat.itemBindingOf import com.topjohnwu.magisk.utils.BiometricHelper import com.topjohnwu.magisk.utils.currentLocale import io.reactivex.Single +import me.tatarka.bindingcollectionadapter2.collections.MergeObservableList class SuperuserViewModel( private val db: PolicyDao, @@ -30,19 +34,24 @@ class SuperuserViewModel( private val resources: Resources ) : CompatViewModel(), TappableHeadlineItem.Listener { - val items = diffListOf>() + private val itemNoData = TextItem(R.string.superuser_policy_none) + + private val itemsPolicies = diffListOf() + private val itemsHelpers = ObservableArrayList().also { + it.add(itemNoData) + } + + val adapter = adapterOf>() + val items = MergeObservableList>() + .insertItem(TappableHeadlineItem.Hide) + .insertItem(TappableHeadlineItem.Safetynet) + .insertList(itemsHelpers) + .insertList(itemsPolicies) val itemBinding = itemBindingOf> { it.bindExtra(BR.viewModel, this) it.bindExtra(BR.listener, this) } - companion object { - private val menuOptions = listOf( - TappableHeadlineItem.Hide, - TappableHeadlineItem.Safetynet - ) - } - // --- override fun refresh() = db.fetchAll() @@ -57,11 +66,15 @@ class SuperuserViewModel( ).compare(o1, o2) } .toList() - .map { menuOptions + it } - .map { it to items.calculateDiff(it) } + .map { it to itemsPolicies.calculateDiff(it) } .applySchedulers() .applyViewModel(this) - .subscribeK { items.update(it.first, it.second) } + .subscribeK { + itemsPolicies.update(it.first, it.second) + if (itemsPolicies.isNotEmpty()) { + itemsHelpers.remove(itemNoData) + } + } // --- @@ -77,7 +90,12 @@ class SuperuserViewModel( fun deletePressed(item: PolicyItem) { fun updateState() = deletePolicy(item.item) - .subscribeK { items.removeAll { it.genericItemSameAs(item) } } + .subscribeK { + itemsPolicies.removeAll { it.genericItemSameAs(item) } + if (itemsPolicies.isEmpty() && itemsHelpers.isEmpty()) { + itemsHelpers.add(itemNoData) + } + } .add() if (BiometricHelper.isEnabled) { diff --git a/app/src/main/res/layout/fragment_log_md2.xml b/app/src/main/res/layout/fragment_log_md2.xml index acfe2264c..4fa3d9c4e 100644 --- a/app/src/main/res/layout/fragment_log_md2.xml +++ b/app/src/main/res/layout/fragment_log_md2.xml @@ -61,6 +61,20 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_superuser_md2.xml b/app/src/main/res/layout/fragment_superuser_md2.xml index 44cb4c2e8..08eecdd8e 100644 --- a/app/src/main/res/layout/fragment_superuser_md2.xml +++ b/app/src/main/res/layout/fragment_superuser_md2.xml @@ -18,6 +18,8 @@ android:layout_height="match_parent"> - - + - + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings_md2.xml b/app/src/main/res/values/strings_md2.xml index a49909a1a..9ac599291 100644 --- a/app/src/main/res/values/strings_md2.xml +++ b/app/src/main/res/values/strings_md2.xml @@ -91,10 +91,14 @@ Logs Notifications Revoke + No app has asked for superuser permission yet. Filter by name Scroll up Filters Search + You\'re log-free, try using your SU enabled apps more. + Magisk logs are empty, that\'s weird. + \ No newline at end of file