Hide icons when things don't fit

This commit is contained in:
topjohnwu 2021-02-11 05:08:40 -08:00
parent 75584e2b19
commit 5f63e88984
4 changed files with 93 additions and 51 deletions

View File

@ -29,13 +29,35 @@ class HomeFragment : BaseUIFragment<HomeViewModel, FragmentHomeMd2Binding>() {
): View {
super.onCreateView(inflater, container, savedInstanceState)
// Set barrier reference IDs in code, since resource IDs will be stripped in release mode
binding.homeMagiskWrapper.homeMagiskTitleBarrier.referencedIds =
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_installed_version, R.id.home_device_details_ramdisk)
binding.homeManagerWrapper.homeManagerTitleBarrier.referencedIds =
intArrayOf(R.id.home_manager_button, R.id.home_manager_title, R.id.home_manager_icon)
// If titles are squished, hide icons
with(binding.homeMagiskWrapper) {
with(homeMagiskTitle) {
post {
if (lineCount != 1) {
with(homeMagiskIcon) {
layoutParams.width = 0
layoutParams.height = 0
requestLayout()
}
}
}
}
}
with(binding.homeManagerWrapper) {
with(homeManagerTitle) {
post {
if (lineCount != 1) {
with(homeManagerIcon) {
layoutParams.width = 0
layoutParams.height = 0
requestLayout()
}
}
}
}
}
return binding.root
}

View File

@ -31,6 +31,13 @@ class HomeViewModel(
private val svc: NetworkService
) : BaseViewModel() {
val magiskTitleBarrierIds =
intArrayOf(R.id.home_magisk_icon, R.id.home_magisk_title, R.id.home_magisk_button)
val magiskDetailBarrierIds =
intArrayOf(R.id.home_magisk_installed_version, R.id.home_device_details_ramdisk)
val appTitleBarrierIds =
intArrayOf(R.id.home_manager_icon, R.id.home_manager_title, R.id.home_manager_button)
@get:Bindable
var isNoticeVisible = Config.safetyNotice
set(value) = set(value, field, { field = it }, BR.noticeVisible)

View File

@ -51,39 +51,45 @@
app:layout_constraintStart_toEndOf="@+id/home_magisk_icon"
app:layout_constraintTop_toTopOf="@+id/home_magisk_icon" />
<Button
<FrameLayout
android:id="@+id/home_magisk_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/home_magisk_title"
app:layout_constraintTop_toTopOf="@+id/home_magisk_title">
<Button
style="@style/WidgetFoundation.Button"
invisible="@{viewModel.stateMagisk != MagiskState.OBSOLETE}"
gone="@{viewModel.stateMagisk != MagiskState.OBSOLETE}"
android:layout_width="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_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_magisk_title"/>
android:layout_gravity="end"
app:icon="@drawable/ic_update_md2" />
<Button
style="@style/WidgetFoundation.Button.Text"
invisible="@{viewModel.stateMagisk == MagiskState.OBSOLETE}"
gone="@{viewModel.stateMagisk == MagiskState.OBSOLETE}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:onClick="@{() -> viewModel.onMagiskPressed()}"
android:text="@string/install"
android:textAllCaps="false"
app:icon="@drawable/ic_install"
app:layout_constraintBottom_toBottomOf="@+id/home_magisk_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_magisk_title"/>
app:icon="@drawable/ic_install"/>
</FrameLayout>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/home_magisk_title_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
tools:constraint_referenced_ids="home_magisk_button,home_magisk_title,home_magisk_icon" />
app:referencedIds="@{viewModel.magiskTitleBarrierIds}"
tools:constraint_referenced_ids="home_magisk_icon,home_magisk_title,home_magisk_button" />
<HorizontalScrollView
android:layout_width="match_parent"
@ -141,6 +147,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="end"
app:referencedIds="@{viewModel.magiskDetailBarrierIds}"
tools:constraint_referenced_ids="home_magisk_installed_version,home_device_details_ramdisk"/>
<LinearLayout

View File

@ -52,39 +52,45 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/home_app_title" />
<Button
<FrameLayout
android:id="@+id/home_manager_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/home_manager_title"
app:layout_constraintTop_toTopOf="@+id/home_manager_title">
<Button
style="@style/WidgetFoundation.Button"
invisible="@{viewModel.stateManager != MagiskState.OBSOLETE}"
gone="@{viewModel.stateManager != MagiskState.OBSOLETE}"
android:layout_width="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_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_manager_title"/>
android:layout_gravity="end"
app:icon="@drawable/ic_update_md2" />
<Button
style="@style/WidgetFoundation.Button.Text"
invisible="@{viewModel.stateManager == MagiskState.OBSOLETE}"
gone="@{viewModel.stateManager != MagiskState.UP_TO_DATE}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:onClick="@{() -> viewModel.onManagerPressed()}"
android:text="@string/install"
android:textAllCaps="false"
app:icon="@drawable/ic_install"
app:layout_constraintBottom_toBottomOf="@+id/home_manager_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_manager_title"/>
app:icon="@drawable/ic_install"/>
</FrameLayout>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/home_manager_title_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
tools:constraint_referenced_ids="home_manager_button,home_manager_title,home_manager_icon" />
app:referencedIds="@{viewModel.appTitleBarrierIds}"
tools:constraint_referenced_ids="home_manager_icon,home_manager_title,home_manager_button" />
<HorizontalScrollView
android:layout_width="match_parent"