From 5f63e889844a00e1d1ed33c152df4bf1eca10215 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 11 Feb 2021 05:08:40 -0800 Subject: [PATCH] Hide icons when things don't fit --- .../topjohnwu/magisk/ui/home/HomeFragment.kt | 36 ++++++++++--- .../topjohnwu/magisk/ui/home/HomeViewModel.kt | 7 +++ .../main/res/layout/include_home_magisk.xml | 51 +++++++++++-------- .../main/res/layout/include_home_manager.xml | 50 ++++++++++-------- 4 files changed, 93 insertions(+), 51 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 64f949af8..bfbb5a6a7 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 @@ -29,13 +29,35 @@ class HomeFragment : BaseUIFragment() { ): 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 } 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 b1230c09a..8808ccc97 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 @@ -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) diff --git a/app/src/main/res/layout/include_home_magisk.xml b/app/src/main/res/layout/include_home_magisk.xml index 438249e0f..137a39e38 100644 --- a/app/src/main/res/layout/include_home_magisk.xml +++ b/app/src/main/res/layout/include_home_magisk.xml @@ -51,39 +51,45 @@ app:layout_constraintStart_toEndOf="@+id/home_magisk_icon" app:layout_constraintTop_toTopOf="@+id/home_magisk_icon" /> -