From c60273481d02fe955a149ef952e8c318b316f2c7 Mon Sep 17 00:00:00 2001 From: Toni500git Date: Mon, 24 Feb 2025 19:11:22 +0100 Subject: [PATCH] android app: use cachapa/ExpandableLayout --- android/app/build.gradle.kts | 1 + .../toni/customfetch_android/MainActivity.kt | 50 +------- .../src/main/res/layout/about_me_fragment.xml | 5 +- .../app/src/main/res/layout/activity_main.xml | 117 ++++++++++-------- .../main/res/layout/customfetch_configure.xml | 5 +- android/gradle/libs.versions.toml | 2 + 6 files changed, 78 insertions(+), 102 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 6074fdd..fceef75 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -95,6 +95,7 @@ android { dependencies { implementation(libs.colorpickerview) implementation(libs.colorpickerpref) + implementation(libs.expandablelayout) implementation(libs.androidx.core.ktx) implementation(libs.androidx.appcompat) diff --git a/android/app/src/main/java/org/toni/customfetch_android/MainActivity.kt b/android/app/src/main/java/org/toni/customfetch_android/MainActivity.kt index ba97501..79b26f6 100644 --- a/android/app/src/main/java/org/toni/customfetch_android/MainActivity.kt +++ b/android/app/src/main/java/org/toni/customfetch_android/MainActivity.kt @@ -133,15 +133,13 @@ class MainActivity : AppCompatActivity() { binding.appVersion.text = "customfetch v${BuildConfig.VERSION_NAME} (${BuildConfig.GIT_COMMIT_HASH}) (${BuildConfig.BUILD_TYPE})" - var isExpanded = false - binding.collapseSocialsBar.setOnClickListener { - isExpanded = !isExpanded - if (isExpanded) { - expandView(binding.collapseSocialsLayout) - binding.arrowIcon.animate().rotation(180f).setInterpolator(AccelerateDecelerateInterpolator()).start() - } else { - collapseView(binding.collapseSocialsLayout) + binding.collapseSocialsTitle.setOnClickListener { + if (binding.collapseSocialsLayout.isExpanded) { binding.arrowIcon.animate().rotation(0f).setInterpolator(AccelerateDecelerateInterpolator()).start() + binding.collapseSocialsLayout.collapse() + } else { + binding.arrowIcon.animate().rotation(180f).setInterpolator(AccelerateDecelerateInterpolator()).start() + binding.collapseSocialsLayout.expand() } } } @@ -212,42 +210,6 @@ class MainActivity : AppCompatActivity() { colorAnimator.start() return false } - - private fun expandView(view: View) { - view.measure( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT - ) - val targetedHeight = view.measuredHeight - view.layoutParams.height = 0 - view.visibility = View.VISIBLE - - val animator = ValueAnimator.ofInt(0, targetedHeight) - animator.addUpdateListener { animation -> - val value = animation.animatedValue as Int - view.layoutParams.height = value - view.requestLayout() - } - animator.duration = 300 - animator.interpolator = AccelerateDecelerateInterpolator() - animator.start() - } - - private fun collapseView(view: View) { - val initialHeight = view.measuredHeight - - val animator = ValueAnimator.ofInt(initialHeight, 0) - animator.addUpdateListener { animation -> - val value = animation.animatedValue as Int - view.layoutParams.height = value - view.requestLayout() - if (value == 0) - view.visibility = View.GONE - } - animator.duration = 300 - animator.interpolator = AccelerateDecelerateInterpolator() - animator.start() - } } internal fun copyToAssetFolder(assets: AssetManager, absolutePath: String, assetSubFolder: String) { diff --git a/android/app/src/main/res/layout/about_me_fragment.xml b/android/app/src/main/res/layout/about_me_fragment.xml index b37e9b4..1711f71 100644 --- a/android/app/src/main/res/layout/about_me_fragment.xml +++ b/android/app/src/main/res/layout/about_me_fragment.xml @@ -1,11 +1,12 @@ - + android:background="@color/background" + tools:ignore="HardcodedText"> + tools:ignore="MissingConstraints,HardcodedText" > - @@ -88,9 +88,9 @@ android:id="@+id/click_me_settings" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="210dp" + android:layout_marginStart="210dp" android:visibility="gone" - android:textSize="16dp" + android:textSize="16sp" android:textColor="@color/text" android:text="CLICK ME NOW" /> @@ -125,53 +125,53 @@ android:layout_marginTop="8dp" /> - + - - + + - - - - + android:layout_weight="1" + android:text="Social Links" + android:gravity="center" + android:textSize="16sp" + android:textStyle="bold" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" /> - + + + - + android:layout_height="wrap_content" + android:orientation="vertical" > + - + - + diff --git a/android/app/src/main/res/layout/customfetch_configure.xml b/android/app/src/main/res/layout/customfetch_configure.xml index 729dd72..54d01cb 100644 --- a/android/app/src/main/res/layout/customfetch_configure.xml +++ b/android/app/src/main/res/layout/customfetch_configure.xml @@ -1,10 +1,11 @@ + android:padding="16dp" + tools:ignore="HardcodedText">