Always show install button

Fix #3172
This commit is contained in:
topjohnwu 2020-09-16 23:55:50 -07:00
parent 9e5cb6cb91
commit 9a16ab1bd7
6 changed files with 83 additions and 94 deletions

View File

@ -31,11 +31,11 @@ class HomeFragment : BaseUIFragment<HomeViewModel, FragmentHomeMd2Binding>() {
// Set barrier reference IDs in code, since resource IDs will be stripped in release mode // Set barrier reference IDs in code, since resource IDs will be stripped in release mode
binding.homeMagiskWrapper.homeMagiskTitleBarrier.referencedIds = 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 = binding.homeMagiskWrapper.homeMagiskBarrier.referencedIds =
intArrayOf(R.id.home_magisk_latest_version, R.id.home_magisk_installed_version) intArrayOf(R.id.home_magisk_latest_version, R.id.home_magisk_installed_version)
binding.homeManagerWrapper.homeManagerTitleBarrier.referencedIds = 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 return binding.root
} }

View File

@ -14,6 +14,7 @@ import com.topjohnwu.magisk.core.model.MagiskJson
import com.topjohnwu.magisk.core.model.ManagerJson import com.topjohnwu.magisk.core.model.ManagerJson
import com.topjohnwu.magisk.data.repository.MagiskRepository import com.topjohnwu.magisk.data.repository.MagiskRepository
import com.topjohnwu.magisk.events.OpenInappLinkEvent 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.EnvFixDialog
import com.topjohnwu.magisk.events.dialog.ManagerInstallDialog import com.topjohnwu.magisk.events.dialog.ManagerInstallDialog
import com.topjohnwu.magisk.events.dialog.UninstallDialog import com.topjohnwu.magisk.events.dialog.UninstallDialog
@ -126,10 +127,14 @@ class HomeViewModel(
fun onDeletePressed() = UninstallDialog().publish() 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() HomeFragmentDirections.actionHomeFragmentToInstallFragment().publish()
} else {
SnackbarEvent(R.string.no_connection).publish()
} }
fun onSafetyNetPressed() = fun onSafetyNetPressed() =

View File

@ -15,6 +15,7 @@ import com.topjohnwu.magisk.data.database.RepoByUpdatedDao
import com.topjohnwu.magisk.databinding.RvItem import com.topjohnwu.magisk.databinding.RvItem
import com.topjohnwu.magisk.events.InstallExternalModuleEvent import com.topjohnwu.magisk.events.InstallExternalModuleEvent
import com.topjohnwu.magisk.events.OpenChangelogEvent import com.topjohnwu.magisk.events.OpenChangelogEvent
import com.topjohnwu.magisk.events.SnackbarEvent
import com.topjohnwu.magisk.events.dialog.ModuleInstallDialog import com.topjohnwu.magisk.events.dialog.ModuleInstallDialog
import com.topjohnwu.magisk.ktx.addOnListChangedCallback import com.topjohnwu.magisk.ktx.addOnListChangedCallback
import com.topjohnwu.magisk.ktx.reboot import com.topjohnwu.magisk.ktx.reboot
@ -300,16 +301,27 @@ class ModuleViewModel(
else -> Unit else -> Unit
} }
fun downloadPressed(item: RepoItem) = withExternalRW { fun downloadPressed(item: RepoItem) = if (isConnected.get()) withExternalRW {
ModuleInstallDialog(item.item).publish() ModuleInstallDialog(item.item).publish()
} else {
SnackbarEvent(R.string.no_connection).publish()
} }
fun installPressed() = withExternalRW { fun installPressed() = withExternalRW {
InstallExternalModuleEvent().publish() 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) { 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
} }
} }

View File

@ -73,41 +73,21 @@
android:layout_marginBottom="@{(int) @dimen/l1 + viewModel.insets.bottom}" android:layout_marginBottom="@{(int) @dimen/l1 + viewModel.insets.bottom}"
tools:layout_marginBottom="64dp"> tools:layout_marginBottom="64dp">
<LinearLayout <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/main_navigation"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:animateLayoutChanges="true" android:background="@android:color/transparent"
android:orientation="vertical"> android:textStyle="bold"
app:elevation="0dp"
<com.google.android.material.bottomnavigation.BottomNavigationView app:itemHorizontalTranslationEnabled="false"
android:id="@+id/main_navigation" app:itemIconTint="@color/color_menu_tint"
android:layout_width="match_parent" app:itemRippleColor="?colorPrimary"
android:layout_height="wrap_content" app:itemTextAppearanceActive="@style/AppearanceFoundation.Tiny.Bold"
android:background="@android:color/transparent" app:itemTextAppearanceInactive="@style/AppearanceFoundation.Tiny.Bold"
android:textStyle="bold" app:itemTextColor="@color/color_menu_tint"
app:elevation="0dp" app:labelVisibilityMode="unlabeled"
app:itemHorizontalTranslationEnabled="false" app:menu="@menu/menu_bottom_nav" />
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" />
<TextView
gone="@{viewModel.isConnected}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="@dimen/l_50"
android:text="@string/no_connection"
android:textAppearance="@style/AppearanceFoundation.Caption"
android:textColor="?colorError"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>

View File

@ -46,47 +46,43 @@
android:textAppearance="@style/AppearanceFoundation.Title" android:textAppearance="@style/AppearanceFoundation.Title"
android:textColor="?colorPrimary" android:textColor="?colorPrimary"
app:layout_constraintBottom_toBottomOf="@+id/home_magisk_icon" 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_constraintStart_toEndOf="@+id/home_magisk_icon"
app:layout_constraintTop_toTopOf="@+id/home_magisk_icon" /> app:layout_constraintTop_toTopOf="@+id/home_magisk_icon" />
<FrameLayout <Button
android:id="@+id/home_magisk_action" android:id="@+id/home_magisk_button"
invisible="@{viewModel.stateMagisk == MagiskState.LOADING || !viewModel.isConnected}" style="@style/WidgetFoundation.Button"
invisible="@{viewModel.stateMagisk != MagiskState.OBSOLETE}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.onMagiskPressed()}"
android:text="@string/update"
android:textAllCaps="false"
app:icon="@drawable/ic_update_md2"
app:layout_constraintBottom_toBottomOf="@+id/home_magisk_title" app:layout_constraintBottom_toBottomOf="@+id/home_magisk_title"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_magisk_title"> app:layout_constraintTop_toTopOf="@+id/home_magisk_title"/>
<Button <Button
style="@style/WidgetFoundation.Button" style="@style/WidgetFoundation.Button.Text"
gone="@{viewModel.stateMagisk != MagiskState.OBSOLETE}" invisible="@{viewModel.stateMagisk == MagiskState.OBSOLETE}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.onMagiskPressed()}" android:onClick="@{() -> viewModel.onMagiskPressed()}"
android:text="@string/update" android:text="@string/install"
android:textAllCaps="false" android:textAllCaps="false"
app:icon="@drawable/ic_update_md2" /> app:icon="@drawable/ic_install"
app:layout_constraintBottom_toBottomOf="@+id/home_magisk_title"
<Button app:layout_constraintEnd_toEndOf="parent"
style="@style/WidgetFoundation.Button.Text" app:layout_constraintTop_toTopOf="@+id/home_magisk_title"/>
gone="@{viewModel.stateMagisk == MagiskState.OBSOLETE}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.onMagiskPressed()}"
android:text="@string/install"
android:textAllCaps="false"
app:icon="@drawable/ic_install" />
</FrameLayout>
<androidx.constraintlayout.widget.Barrier <androidx.constraintlayout.widget.Barrier
android:id="@+id/home_magisk_title_barrier" android:id="@+id/home_magisk_title_barrier"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:barrierDirection="bottom" app:barrierDirection="bottom"
tools:constraint_referenced_ids="home_magisk_action,home_magisk_title,home_magisk_icon" /> tools:constraint_referenced_ids="home_magisk_button,home_magisk_title,home_magisk_icon" />
<HorizontalScrollView <HorizontalScrollView
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -46,48 +46,44 @@
android:textAppearance="@style/AppearanceFoundation.Title" android:textAppearance="@style/AppearanceFoundation.Title"
android:textColor="?colorPrimary" android:textColor="?colorPrimary"
app:layout_constraintBottom_toBottomOf="@+id/home_manager_icon" app:layout_constraintBottom_toBottomOf="@+id/home_manager_icon"
app:layout_constraintEnd_toStartOf="@+id/home_manager_action" app:layout_constraintEnd_toStartOf="@+id/home_manager_button"
app:layout_constraintStart_toEndOf="@+id/home_manager_icon" app:layout_constraintStart_toEndOf="@+id/home_manager_icon"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="@string/manager" /> tools:text="@string/manager" />
<FrameLayout <Button
android:id="@+id/home_manager_action" android:id="@+id/home_manager_button"
invisible="@{viewModel.stateMagisk == MagiskState.LOADING || !viewModel.isConnected}" style="@style/WidgetFoundation.Button"
invisible="@{viewModel.stateManager != MagiskState.OBSOLETE}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.onManagerPressed()}"
android:text="@string/update"
android:textAllCaps="false"
app:icon="@drawable/ic_update_md2"
app:layout_constraintBottom_toBottomOf="@+id/home_manager_title" app:layout_constraintBottom_toBottomOf="@+id/home_manager_title"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_manager_title"> app:layout_constraintTop_toTopOf="@+id/home_manager_title"/>
<Button <Button
style="@style/WidgetFoundation.Button" style="@style/WidgetFoundation.Button.Text"
gone="@{viewModel.stateManager != MagiskState.OBSOLETE}" invisible="@{viewModel.stateManager == MagiskState.OBSOLETE}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.onManagerPressed()}" android:onClick="@{() -> viewModel.onManagerPressed()}"
android:text="@string/update" android:text="@string/install"
android:textAllCaps="false" android:textAllCaps="false"
app:icon="@drawable/ic_update_md2" /> app:icon="@drawable/ic_install"
app:layout_constraintBottom_toBottomOf="@+id/home_manager_title"
<Button app:layout_constraintEnd_toEndOf="parent"
style="@style/WidgetFoundation.Button.Text" app:layout_constraintTop_toTopOf="@+id/home_manager_title"/>
gone="@{viewModel.stateManager == MagiskState.OBSOLETE}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.onManagerPressed()}"
android:text="@string/install"
android:textAllCaps="false"
app:icon="@drawable/ic_install" />
</FrameLayout>
<androidx.constraintlayout.widget.Barrier <androidx.constraintlayout.widget.Barrier
android:id="@+id/home_manager_title_barrier" android:id="@+id/home_manager_title_barrier"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:barrierDirection="bottom" app:barrierDirection="bottom"
tools:constraint_referenced_ids="home_manager_action,home_manager_title,home_manager_icon" /> tools:constraint_referenced_ids="home_manager_button,home_manager_title,home_manager_icon" />
<HorizontalScrollView <HorizontalScrollView
android:layout_width="match_parent" android:layout_width="match_parent"