From 9a16ab1bd757a148de6874e4e867fd0af5ff88c0 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 16 Sep 2020 23:55:50 -0700 Subject: [PATCH] Always show install button Fix #3172 --- .../topjohnwu/magisk/ui/home/HomeFragment.kt | 4 +- .../topjohnwu/magisk/ui/home/HomeViewModel.kt | 9 +++- .../magisk/ui/module/ModuleViewModel.kt | 18 +++++-- app/src/main/res/layout/activity_main_md2.xml | 46 +++++------------ .../main/res/layout/include_home_magisk.xml | 50 +++++++++---------- .../main/res/layout/include_home_manager.xml | 50 +++++++++---------- 6 files changed, 83 insertions(+), 94 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt index 958863b15..99317268f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt @@ -31,11 +31,11 @@ class HomeFragment : BaseUIFragment() { // Set barrier reference IDs in code, since resource IDs will be stripped in release mode binding.homeMagiskWrapper.homeMagiskTitleBarrier.referencedIds = - intArrayOf(R.id.home_magisk_action, R.id.home_magisk_title, R.id.home_magisk_icon) + intArrayOf(R.id.home_magisk_button, R.id.home_magisk_title, R.id.home_magisk_icon) binding.homeMagiskWrapper.homeMagiskBarrier.referencedIds = intArrayOf(R.id.home_magisk_latest_version, R.id.home_magisk_installed_version) binding.homeManagerWrapper.homeManagerTitleBarrier.referencedIds = - intArrayOf(R.id.home_manager_action, R.id.home_manager_title, R.id.home_manager_icon) + intArrayOf(R.id.home_manager_button, R.id.home_manager_title, R.id.home_manager_icon) return binding.root } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index 6f7b9d149..0cbdf5b83 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -14,6 +14,7 @@ import com.topjohnwu.magisk.core.model.MagiskJson import com.topjohnwu.magisk.core.model.ManagerJson import com.topjohnwu.magisk.data.repository.MagiskRepository import com.topjohnwu.magisk.events.OpenInappLinkEvent +import com.topjohnwu.magisk.events.SnackbarEvent import com.topjohnwu.magisk.events.dialog.EnvFixDialog import com.topjohnwu.magisk.events.dialog.ManagerInstallDialog import com.topjohnwu.magisk.events.dialog.UninstallDialog @@ -126,10 +127,14 @@ class HomeViewModel( fun onDeletePressed() = UninstallDialog().publish() - fun onManagerPressed() = ManagerInstallDialog().publish() + fun onManagerPressed() = + if (isConnected.get()) ManagerInstallDialog().publish() + else SnackbarEvent(R.string.no_connection).publish() - fun onMagiskPressed() = withExternalRW { + fun onMagiskPressed() = if (isConnected.get()) withExternalRW { HomeFragmentDirections.actionHomeFragmentToInstallFragment().publish() + } else { + SnackbarEvent(R.string.no_connection).publish() } fun onSafetyNetPressed() = diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt index 430a28d2e..965ee602f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt @@ -15,6 +15,7 @@ import com.topjohnwu.magisk.data.database.RepoByUpdatedDao import com.topjohnwu.magisk.databinding.RvItem import com.topjohnwu.magisk.events.InstallExternalModuleEvent import com.topjohnwu.magisk.events.OpenChangelogEvent +import com.topjohnwu.magisk.events.SnackbarEvent import com.topjohnwu.magisk.events.dialog.ModuleInstallDialog import com.topjohnwu.magisk.ktx.addOnListChangedCallback import com.topjohnwu.magisk.ktx.reboot @@ -300,16 +301,27 @@ class ModuleViewModel( else -> Unit } - fun downloadPressed(item: RepoItem) = withExternalRW { + fun downloadPressed(item: RepoItem) = if (isConnected.get()) withExternalRW { ModuleInstallDialog(item.item).publish() + } else { + SnackbarEvent(R.string.no_connection).publish() } fun installPressed() = withExternalRW { InstallExternalModuleEvent().publish() } - fun infoPressed(item: RepoItem) = OpenChangelogEvent(item.item).publish() + fun infoPressed(item: RepoItem) = + if (isConnected.get()) OpenChangelogEvent(item.item).publish() + else SnackbarEvent(R.string.no_connection).publish() + + fun infoPressed(item: ModuleItem) { - OpenChangelogEvent(item.repo ?: return).publish() + item.repo?.also { + if (isConnected.get()) + OpenChangelogEvent(it).publish() + else + SnackbarEvent(R.string.no_connection).publish() + } ?: return } } diff --git a/app/src/main/res/layout/activity_main_md2.xml b/app/src/main/res/layout/activity_main_md2.xml index 09c2c0f8e..e0b5a72de 100644 --- a/app/src/main/res/layout/activity_main_md2.xml +++ b/app/src/main/res/layout/activity_main_md2.xml @@ -73,41 +73,21 @@ android:layout_marginBottom="@{(int) @dimen/l1 + viewModel.insets.bottom}" tools:layout_marginBottom="64dp"> - - - - - - - + android:background="@android:color/transparent" + android:textStyle="bold" + app:elevation="0dp" + app:itemHorizontalTranslationEnabled="false" + app:itemIconTint="@color/color_menu_tint" + app:itemRippleColor="?colorPrimary" + app:itemTextAppearanceActive="@style/AppearanceFoundation.Tiny.Bold" + app:itemTextAppearanceInactive="@style/AppearanceFoundation.Tiny.Bold" + app:itemTextColor="@color/color_menu_tint" + app:labelVisibilityMode="unlabeled" + app:menu="@menu/menu_bottom_nav" /> diff --git a/app/src/main/res/layout/include_home_magisk.xml b/app/src/main/res/layout/include_home_magisk.xml index 5b71ea5ad..0d7a613af 100644 --- a/app/src/main/res/layout/include_home_magisk.xml +++ b/app/src/main/res/layout/include_home_magisk.xml @@ -46,47 +46,43 @@ android:textAppearance="@style/AppearanceFoundation.Title" android:textColor="?colorPrimary" app:layout_constraintBottom_toBottomOf="@+id/home_magisk_icon" - app:layout_constraintEnd_toStartOf="@+id/home_magisk_action" + app:layout_constraintEnd_toStartOf="@+id/home_magisk_button" app:layout_constraintStart_toEndOf="@+id/home_magisk_icon" app:layout_constraintTop_toTopOf="@+id/home_magisk_icon" /> - + app:layout_constraintTop_toTopOf="@+id/home_magisk_title"/> -