Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: collapsible sections in home screen #621

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.jdtech.jellyfin.adapters

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -38,6 +39,27 @@ class ViewListAdapter(
binding.viewAll.setOnClickListener {
onClickListener(view)
}

binding.toggleView.setOnClickListener {
val isExpanded = !binding.itemsRecyclerView.isVisible

// Animate RecyclerView's visibility
binding.itemsRecyclerView
.animate()
.setDuration(200)
.alpha(if (isExpanded) 1f else 0f)
.withEndAction {
binding.itemsRecyclerView.visibility =
if (isExpanded) android.view.View.VISIBLE else android.view.View.GONE
}

// Rotate the arrow
binding.toggleView
.animate()
.setDuration(200)
.rotation(if (isExpanded) 0f else -90f)
.start()
}
}
}

Expand All @@ -50,6 +72,27 @@ class ViewListAdapter(
binding.sectionName.text = section.homeSection.name.asString(binding.sectionName.context.resources)
binding.itemsRecyclerView.adapter = HomeEpisodeListAdapter(onClickListener)
(binding.itemsRecyclerView.adapter as HomeEpisodeListAdapter).submitList(section.homeSection.items)

binding.toggleView.setOnClickListener {
val isExpanded = !binding.itemsRecyclerView.isVisible

// Animate RecyclerView's visibility
binding.itemsRecyclerView
.animate()
.setDuration(200)
.alpha(if (isExpanded) 1f else 0f)
.withEndAction {
binding.itemsRecyclerView.visibility =
if (isExpanded) android.view.View.VISIBLE else android.view.View.GONE
}

// Rotate the arrow
binding.toggleView
.animate()
.setDuration(200)
.rotation(if (isExpanded) 0f else -90f)
.start()
}
}
}

Expand Down
26 changes: 21 additions & 5 deletions app/phone/src/main/res/layout/next_up_section.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:orientation="vertical">

<ImageView
android:id="@+id/toggle_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:contentDescription="@string/toggle_view"
android:src="@drawable/ic_chevron_down"
app:layout_constraintBottom_toBottomOf="@id/section_name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/section_name" />

<TextView
android:id="@+id/section_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginBottom="12dp"
android:layout_marginStart="4dp"
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
android:textSize="18sp"
app:layout_constraintStart_toEndOf="@id/toggle_view"
app:layout_constraintTop_toTopOf="parent"
tools:text="Next Up" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/items_recycler_view"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:clipToPadding="false"
android:orientation="horizontal"
android:paddingHorizontal="12dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/section_name"
tools:listitem="@layout/home_episode_item" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
15 changes: 13 additions & 2 deletions app/phone/src/main/res/layout/view_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@
android:layout_height="wrap_content"
android:layout_marginBottom="12dp">

<ImageView
android:id="@+id/toggle_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
app:layout_constraintBottom_toBottomOf="@id/view_name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/view_name"
android:contentDescription="@string/toggle_view"
android:src="@drawable/ic_chevron_down" />

<TextView
android:id="@+id/view_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginStart="4dp"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="@id/view_all"
app:layout_constraintEnd_toStartOf="@id/view_all"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/toggle_view"
tools:text="Movies" />

<Button
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/res/drawable/ic_chevron_down.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="m6,9 l6,6 6,-6"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="@android:color/white"
android:strokeLineCap="round"/>
</vector>
1 change: 1 addition & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<string name="title_settings">Settings</string>
<string name="title_download">Downloads</string>
<string name="view_all">View all</string>
<string name="toggle_view">Toggle View</string>
<string name="error_loading_data">Error loading data</string>
<string name="retry">Retry</string>
<string name="genres">Genres</string>
Expand Down