From 63590d379c37767d930c99dc5043e0a1a74deaf2 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 11 Feb 2021 22:38:41 -0800 Subject: [PATCH] Update hide icon strategy --- .../topjohnwu/magisk/ui/home/HomeFragment.kt | 40 ++++++++----------- .../main/res/layout/include_home_magisk.xml | 2 + .../main/res/layout/include_home_manager.xml | 2 + 3 files changed, 20 insertions(+), 24 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 bfbb5a6a7..3d7f7f001 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 @@ -2,6 +2,8 @@ package com.topjohnwu.magisk.ui.home import android.os.Bundle import android.view.* +import android.widget.ImageView +import android.widget.TextView import com.topjohnwu.magisk.R import com.topjohnwu.magisk.arch.BaseUIFragment import com.topjohnwu.magisk.core.download.BaseDownloader @@ -22,6 +24,18 @@ class HomeFragment : BaseUIFragment() { BaseDownloader.observeProgress(this, viewModel::onProgressUpdate) } + private fun checkTitle(text: TextView, icon: ImageView) { + text.post { + if (text.layout.getEllipsisCount(0) != 0) { + with (icon) { + layoutParams.width = 0 + layoutParams.height = 0 + requestLayout() + } + } + } + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -30,33 +44,11 @@ class HomeFragment : BaseUIFragment() { super.onCreateView(inflater, container, savedInstanceState) // If titles are squished, hide icons - with(binding.homeMagiskWrapper) { - with(homeMagiskTitle) { - post { - if (lineCount != 1) { - with(homeMagiskIcon) { - layoutParams.width = 0 - layoutParams.height = 0 - requestLayout() - } - } - } - } + checkTitle(homeMagiskTitle, homeMagiskIcon) } - with(binding.homeManagerWrapper) { - with(homeManagerTitle) { - post { - if (lineCount != 1) { - with(homeManagerIcon) { - layoutParams.width = 0 - layoutParams.height = 0 - requestLayout() - } - } - } - } + checkTitle(homeManagerTitle, homeManagerIcon) } return binding.root diff --git a/app/src/main/res/layout/include_home_magisk.xml b/app/src/main/res/layout/include_home_magisk.xml index 137a39e38..20eeec4bd 100644 --- a/app/src/main/res/layout/include_home_magisk.xml +++ b/app/src/main/res/layout/include_home_magisk.xml @@ -46,6 +46,8 @@ android:text="@string/magisk" android:textAppearance="@style/AppearanceFoundation.Title" android:textColor="?colorPrimary" + android:maxLines="1" + android:ellipsize="end" app:layout_constraintBottom_toBottomOf="@+id/home_magisk_icon" app:layout_constraintEnd_toStartOf="@+id/home_magisk_button" app:layout_constraintStart_toEndOf="@+id/home_magisk_icon" diff --git a/app/src/main/res/layout/include_home_manager.xml b/app/src/main/res/layout/include_home_manager.xml index e1e9f5de2..80c8337b9 100644 --- a/app/src/main/res/layout/include_home_manager.xml +++ b/app/src/main/res/layout/include_home_manager.xml @@ -46,6 +46,8 @@ android:text="@string/home_app_title" android:textAppearance="@style/AppearanceFoundation.Title" android:textColor="?colorPrimary" + android:maxLines="1" + android:ellipsize="end" app:layout_constraintBottom_toBottomOf="@+id/home_manager_icon" app:layout_constraintEnd_toStartOf="@+id/home_manager_button" app:layout_constraintStart_toEndOf="@+id/home_manager_icon"