mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-06 07:29:10 +00:00
Add animations to recyclerview
This commit is contained in:
@@ -39,6 +39,7 @@ import net.underdesk.circolapp.data.Circular
|
|||||||
class CircularLetterAdapter(private val circulars: List<Circular>) :
|
class CircularLetterAdapter(private val circulars: List<Circular>) :
|
||||||
RecyclerView.Adapter<CircularLetterAdapter.CircularLetterViewHolder>() {
|
RecyclerView.Adapter<CircularLetterAdapter.CircularLetterViewHolder>() {
|
||||||
private lateinit var context: Context
|
private lateinit var context: Context
|
||||||
|
private var collapsedItems = -1
|
||||||
|
|
||||||
inner class CircularLetterViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
inner class CircularLetterViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
var title: TextView = view.circular_title_textview
|
var title: TextView = view.circular_title_textview
|
||||||
@@ -69,6 +70,33 @@ class CircularLetterAdapter(private val circulars: List<Circular>) :
|
|||||||
holder.title.text = circulars[position].name
|
holder.title.text = circulars[position].name
|
||||||
holder.date.text = circulars[position].date
|
holder.date.text = circulars[position].date
|
||||||
|
|
||||||
|
if (collapsedItems != position) {
|
||||||
|
holder.collapseButton.setImageDrawable(context.getDrawable(R.drawable.baseline_expand_more_24))
|
||||||
|
|
||||||
|
holder.viewButton.visibility = View.GONE
|
||||||
|
holder.downloadButton.visibility = View.GONE
|
||||||
|
holder.favouriteButton.visibility = View.GONE
|
||||||
|
holder.reminderButton.visibility = View.GONE
|
||||||
|
|
||||||
|
holder.attachmentsList.visibility = View.GONE
|
||||||
|
holder.attachmentsList.adapter = null
|
||||||
|
} else {
|
||||||
|
holder.collapseButton.setImageDrawable(context.getDrawable(R.drawable.baseline_expand_less_24))
|
||||||
|
|
||||||
|
holder.viewButton.visibility = View.VISIBLE
|
||||||
|
holder.downloadButton.visibility = View.VISIBLE
|
||||||
|
holder.favouriteButton.visibility = View.VISIBLE
|
||||||
|
holder.reminderButton.visibility = View.VISIBLE
|
||||||
|
|
||||||
|
if (circulars[position].attachmentsNames.isNotEmpty()) {
|
||||||
|
holder.attachmentsList.visibility = View.VISIBLE
|
||||||
|
holder.attachmentsList.adapter = AttachmentAdapter(
|
||||||
|
circulars[position].attachmentsNames,
|
||||||
|
circulars[position].attachmentsUrls
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
holder.viewButton.setOnClickListener {
|
holder.viewButton.setOnClickListener {
|
||||||
val viewIntent = Intent(Intent.ACTION_VIEW)
|
val viewIntent = Intent(Intent.ACTION_VIEW)
|
||||||
viewIntent.setDataAndType(Uri.parse(circulars[position].url), "application/pdf")
|
viewIntent.setDataAndType(Uri.parse(circulars[position].url), "application/pdf")
|
||||||
@@ -96,28 +124,14 @@ class CircularLetterAdapter(private val circulars: List<Circular>) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
holder.collapseButton.setOnClickListener {
|
holder.collapseButton.setOnClickListener {
|
||||||
if (holder.viewButton.visibility == View.VISIBLE) {
|
collapsedItems = if (collapsedItems == position) {
|
||||||
holder.viewButton.visibility = View.GONE
|
-1
|
||||||
holder.downloadButton.visibility = View.GONE
|
|
||||||
holder.favouriteButton.visibility = View.GONE
|
|
||||||
holder.reminderButton.visibility = View.GONE
|
|
||||||
|
|
||||||
holder.attachmentsList.visibility = View.GONE
|
|
||||||
holder.attachmentsList.adapter = null
|
|
||||||
} else {
|
} else {
|
||||||
holder.viewButton.visibility = View.VISIBLE
|
if (collapsedItems > -1) notifyItemChanged(collapsedItems)
|
||||||
holder.downloadButton.visibility = View.VISIBLE
|
position
|
||||||
holder.favouriteButton.visibility = View.VISIBLE
|
|
||||||
holder.reminderButton.visibility = View.VISIBLE
|
|
||||||
|
|
||||||
if (circulars[position].attachmentsNames.isNotEmpty()) {
|
|
||||||
holder.attachmentsList.visibility = View.VISIBLE
|
|
||||||
holder.attachmentsList.adapter = AttachmentAdapter(
|
|
||||||
circulars[position].attachmentsNames,
|
|
||||||
circulars[position].attachmentsUrls
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notifyItemChanged(position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,5 +6,5 @@
|
|||||||
android:tint="?attr/colorControlNormal">
|
android:tint="?attr/colorControlNormal">
|
||||||
<path
|
<path
|
||||||
android:fillColor="@android:color/white"
|
android:fillColor="@android:color/white"
|
||||||
android:pathData="M7.41,8.59L12,13.17l4.59,-4.58L18,10l-6,6 -6,-6 1.41,-1.41z"/>
|
android:pathData="M12,8l-6,6 1.41,1.41L12,10.83l4.59,4.58L18,14z"/>
|
||||||
</vector>
|
</vector>
|
||||||
10
app/src/main/res/drawable/baseline_expand_more_24.xml
Executable file
10
app/src/main/res/drawable/baseline_expand_more_24.xml
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M16.59,8.59L12,13.17 7.41,8.59 6,10l6,6 6,-6z"/>
|
||||||
|
</vector>
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/circulars_list"
|
android:id="@+id/circulars_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" />
|
||||||
tools:layout_editor_absoluteX="168dp"
|
|
||||||
tools:layout_editor_absoluteY="235dp" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:src="@drawable/baseline_keyboard_arrow_down_24"
|
android:src="@drawable/baseline_expand_more_24"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/circular_reminder_button"
|
app:layout_constraintBottom_toTopOf="@+id/circular_reminder_button"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|||||||
Reference in New Issue
Block a user