Skip to content

Commit

Permalink
android app: use cachapa/ExpandableLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Feb 24, 2025
1 parent 2e4a391 commit c602734
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 102 deletions.
1 change: 1 addition & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ android {
dependencies {
implementation(libs.colorpickerview)
implementation(libs.colorpickerpref)
implementation(libs.expandablelayout)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions android/app/src/main/res/layout/about_me_fragment.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background">

android:background="@color/background"
tools:ignore="HardcodedText">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
117 changes: 63 additions & 54 deletions android/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
android:id="@+id/activity_main"
style="@style/Theme.MainActivity"
tools:context=".MainActivity"
tools:ignore="MissingConstraints" >
tools:ignore="MissingConstraints,HardcodedText" >
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
<Space
android:id="@+id/spacer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_marginTop="15sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
Expand Down Expand Up @@ -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" />

Expand Down Expand Up @@ -125,53 +125,53 @@
android:layout_marginTop="8dp" />
</LinearLayout>

<!-- Social Links -->
<!-- Title with Arrow -->
<LinearLayout
android:id="@+id/collapseSocials"
android:layout_width="match_parent"
android:id="@+id/collapseSocialsTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_marginTop="15dp"
app:layout_constraintTop_toBottomOf="@id/aboutMe"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">

<!-- Title with Arrow -->
<LinearLayout
android:id="@+id/collapseSocialsBar"
android:layout_width="wrap_content"
<ImageView
android:id="@+id/arrowIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/mini_arrow" />

<TextView
android:id="@+id/titleText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp">

<ImageView
android:id="@+id/arrowIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/mini_arrow" />

<TextView
android:id="@+id/titleText"
android:layout_width="0dp"
android:layout_height="wrap_content"
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_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" />

</LinearLayout>
</LinearLayout>

<net.cachapa.expandablelayout.ExpandableLayout
android:id="@+id/collapseSocialsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:el_duration="450"
app:el_expanded="false"
app:el_parallax="1"
app:layout_constraintTop_toBottomOf="@id/collapseSocialsTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" >

<!-- Collapsible Content -->
<LinearLayout
android:id="@+id/collapseSocialsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
android:paddingTop="8dp">
android:layout_height="wrap_content"
android:orientation="vertical" >

<!-- Discord server -->
<androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -299,21 +299,30 @@

</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</net.cachapa.expandablelayout.ExpandableLayout>

<TextView
android:id="@+id/app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="360dp"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textColor="@color/text"
android:text="yes" />
<TextView
android:id="@+id/app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="470dp"
app:layout_constraintTop_toBottomOf="@id/aboutMe"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textColor="@color/text"
android:text="yes" />

</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="45dp"
app:layout_constraintTop_toBottomOf="@id/app_version"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
Expand Down
5 changes: 3 additions & 2 deletions android/app/src/main/res/layout/customfetch_configure.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:padding="16dp">
android:padding="16dp"
tools:ignore="HardcodedText">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
agp = "8.7.2"
colorpickerpref = "1.1.0"
colorpickerview = "2.3.0"
expandablelayout = "2.9.2"
htmlspanner = "0.4"
kotlin = "1.9.24"
coreKtx = "1.15.0"
Expand All @@ -20,6 +21,7 @@ preference = "1.2.1"
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
colorpickerpref = { module = "com.jaredrummler:colorpicker", version.ref = "colorpickerpref" }
colorpickerview = { module = "com.github.skydoves:colorpickerview", version.ref = "colorpickerview" }
expandablelayout = { module = "com.github.cachapa:ExpandableLayout", version.ref = "expandablelayout" }
htmlspanner = { module = "com.github.NightWhistler:HtmlSpanner", version.ref = "htmlspanner" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
Expand Down

0 comments on commit c602734

Please sign in to comment.