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 { ): View {
super.onCreateView(inflater, container, savedInstanceState) super.onCreateView(inflater, container, savedInstanceState)
// Set barrier reference IDs in code, since resource IDs will be stripped in release mode // If titles are squished, hide icons
binding.homeMagiskWrapper.homeMagiskTitleBarrier.referencedIds =
intArrayOf(R.id.home_magisk_button, R.id.home_magisk_title, R.id.home_magisk_icon) with(binding.homeMagiskWrapper) {
binding.homeMagiskWrapper.homeMagiskBarrier.referencedIds = with(homeMagiskTitle) {
intArrayOf(R.id.home_magisk_installed_version, R.id.home_device_details_ramdisk) post {
binding.homeManagerWrapper.homeManagerTitleBarrier.referencedIds = if (lineCount != 1) {
intArrayOf(R.id.home_manager_button, R.id.home_manager_title, R.id.home_manager_icon) 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 return binding.root
} }

View File

@ -31,6 +31,13 @@ class HomeViewModel(
private val svc: NetworkService private val svc: NetworkService
) : BaseViewModel() { ) : 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 @get:Bindable
var isNoticeVisible = Config.safetyNotice var isNoticeVisible = Config.safetyNotice
set(value) = set(value, field, { field = it }, BR.noticeVisible) 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_constraintStart_toEndOf="@+id/home_magisk_icon"
app:layout_constraintTop_toTopOf="@+id/home_magisk_icon" /> app:layout_constraintTop_toTopOf="@+id/home_magisk_icon" />
<Button <FrameLayout
android:id="@+id/home_magisk_button" 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" style="@style/WidgetFoundation.Button"
invisible="@{viewModel.stateMagisk != MagiskState.OBSOLETE}" gone="@{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/update"
android:textAllCaps="false" android:textAllCaps="false"
app:icon="@drawable/ic_update_md2" android:layout_gravity="end"
app:layout_constraintBottom_toBottomOf="@+id/home_magisk_title" app:icon="@drawable/ic_update_md2" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_magisk_title"/>
<Button <Button
style="@style/WidgetFoundation.Button.Text" style="@style/WidgetFoundation.Button.Text"
invisible="@{viewModel.stateMagisk == MagiskState.OBSOLETE}" gone="@{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:layout_gravity="end"
android:onClick="@{() -> viewModel.onMagiskPressed()}" android:onClick="@{() -> viewModel.onMagiskPressed()}"
android:text="@string/install" android:text="@string/install"
android:textAllCaps="false" android:textAllCaps="false"
app:icon="@drawable/ic_install" app:icon="@drawable/ic_install"/>
app:layout_constraintBottom_toBottomOf="@+id/home_magisk_title"
app:layout_constraintEnd_toEndOf="parent" </FrameLayout>
app:layout_constraintTop_toTopOf="@+id/home_magisk_title"/>
<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_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 <HorizontalScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -141,6 +147,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:barrierDirection="end" app:barrierDirection="end"
app:referencedIds="@{viewModel.magiskDetailBarrierIds}"
tools:constraint_referenced_ids="home_magisk_installed_version,home_device_details_ramdisk"/> tools:constraint_referenced_ids="home_magisk_installed_version,home_device_details_ramdisk"/>
<LinearLayout <LinearLayout

View File

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