Add background to draggable items (#5353)

This commit is contained in:
Ivan Iskandar 2021-06-10 04:16:59 +07:00 committed by GitHub
parent 653b7ffcd0
commit 73e5e9ecd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 150 additions and 120 deletions

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.category package eu.kanade.tachiyomi.ui.category
import android.view.View import android.view.View
import androidx.recyclerview.widget.ItemTouchHelper
import eu.davidea.viewholders.FlexibleViewHolder import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.databinding.CategoriesItemBinding import eu.kanade.tachiyomi.databinding.CategoriesItemBinding
@ -36,5 +37,13 @@ class CategoryHolder(view: View, val adapter: CategoryAdapter) : FlexibleViewHol
override fun onItemReleased(position: Int) { override fun onItemReleased(position: Int) {
super.onItemReleased(position) super.onItemReleased(position)
adapter.onItemReleaseListener.onItemReleased(position) adapter.onItemReleaseListener.onItemReleased(position)
binding.container.isDragged = false
}
override fun onActionStateChanged(position: Int, actionState: Int) {
super.onActionStateChanged(position, actionState)
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
binding.container.isDragged = true
}
} }
} }

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.download package eu.kanade.tachiyomi.ui.download
import android.view.View import android.view.View
import androidx.recyclerview.widget.ItemTouchHelper
import eu.davidea.viewholders.FlexibleViewHolder import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.Download
@ -63,7 +64,7 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
if (binding.downloadProgress.max == 1) { if (binding.downloadProgress.max == 1) {
binding.downloadProgress.max = pages.size * 100 binding.downloadProgress.max = pages.size * 100
} }
binding.downloadProgress.progress = download.totalProgress binding.downloadProgress.setProgressCompat(download.totalProgress, true)
} }
/** /**
@ -77,6 +78,14 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
override fun onItemReleased(position: Int) { override fun onItemReleased(position: Int) {
super.onItemReleased(position) super.onItemReleased(position)
adapter.downloadItemListener.onItemReleased(position) adapter.downloadItemListener.onItemReleased(position)
binding.container.isDragged = false
}
override fun onActionStateChanged(position: Int, actionState: Int) {
super.onActionStateChanged(position, actionState)
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
binding.container.isDragged = true
}
} }
private fun showPopupMenu(view: View) { private fun showPopupMenu(view: View) {

View File

@ -1,40 +1,41 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="56dp" android:layout_height="wrap_content"
android:background="@drawable/list_item_selector_background"> app:cardBackgroundColor="?android:attr/colorBackground"
app:cardElevation="0dp">
<ImageView <LinearLayout
android:id="@+id/reorder" android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="16dp" android:background="@drawable/list_item_selector_background">
android:scaleType="center"
app:srcCompat="@drawable/ic_drag_handle_24dp"
app:tint="?android:attr/textColorHint"
tools:ignore="ContentDescription" />
<ImageView <ImageView
android:layout_width="wrap_content" android:id="@+id/reorder"
android:layout_height="match_parent" android:layout_width="wrap_content"
android:scaleType="center" android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_label_24dp" android:padding="16dp"
app:tint="?android:attr/textColorPrimary" android:scaleType="center"
tools:ignore="ContentDescription" /> app:srcCompat="@drawable/ic_drag_handle_24dp"
app:tint="?android:attr/textColorHint"
tools:ignore="ContentDescription" />
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_weight="1" android:layout_weight="1"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:textAppearance="@style/TextAppearance.Regular.SubHeading" android:textAppearance="@style/TextAppearance.Regular.SubHeading"
tools:text="Title" /> tools:text="Category Title" />
</LinearLayout> </LinearLayout>
</com.google.android.material.card.MaterialCardView>

View File

@ -1,102 +1,113 @@
<?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" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="8dp"> android:layout_marginTop="8dp"
app:cardBackgroundColor="?android:attr/colorBackground"
app:cardElevation="0dp">
<ImageView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/reorder" android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentStart="true" android:background="@drawable/list_item_selector_background">
android:layout_gravity="start"
android:padding="16dp"
android:scaleType="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_drag_handle_24dp"
app:tint="?android:attr/textColorHint" />
<TextView <ImageView
android:id="@+id/manga_full_title" android:id="@+id/reorder"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_alignParentStart="true"
android:layout_toEndOf="@id/reorder" android:layout_gravity="start"
android:ellipsize="end" android:padding="16dp"
android:maxLines="1" android:scaleType="center"
android:textAppearance="@style/TextAppearance.Regular.Body1" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/download_progress_text" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@+id/reorder" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/ic_drag_handle_24dp"
tools:text="Manga title" /> app:tint="?android:attr/textColorHint"
tools:ignore="ContentDescription" />
<TextView <TextView
android:id="@+id/chapter_title" android:id="@+id/manga_full_title"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_marginEnd="8dp"
android:layout_marginEnd="8dp" android:layout_toEndOf="@id/reorder"
android:layout_toEndOf="@id/reorder" android:ellipsize="end"
android:ellipsize="end" android:maxLines="1"
android:maxLines="1" android:textAppearance="@style/TextAppearance.Regular.Body1"
android:textAppearance="@style/TextAppearance.Regular.Caption" app:layout_constraintEnd_toStartOf="@+id/download_progress_text"
app:layout_constraintEnd_toStartOf="@+id/manga_source" app:layout_constraintStart_toEndOf="@+id/reorder"
app:layout_constraintStart_toStartOf="@+id/manga_full_title" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@+id/manga_full_title" tools:text="Manga title" />
tools:text="Chapter Title" />
<com.google.android.material.progressindicator.LinearProgressIndicator <TextView
android:id="@+id/download_progress" android:id="@+id/chapter_title"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_marginTop="2dp"
android:layout_marginBottom="4dp" android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_toEndOf="@id/reorder"
app:layout_constraintEnd_toStartOf="@+id/menu" android:ellipsize="end"
app:layout_constraintStart_toEndOf="@+id/reorder" android:maxLines="1"
app:layout_constraintTop_toBottomOf="@+id/chapter_title" /> android:textAppearance="@style/TextAppearance.Regular.Caption"
app:layout_constraintEnd_toStartOf="@+id/manga_source"
app:layout_constraintStart_toStartOf="@+id/manga_full_title"
app:layout_constraintTop_toBottomOf="@+id/manga_full_title"
tools:text="Chapter Title" />
<TextView <com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/download_progress_text" android:id="@+id/download_progress"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toEndOf="@id/manga_full_title" android:layout_marginTop="8dp"
android:maxLines="1" android:layout_marginBottom="4dp"
android:textAppearance="@style/TextAppearance.Regular.Caption.Hint" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/manga_full_title" app:layout_constraintEnd_toStartOf="@+id/menu"
app:layout_constraintEnd_toStartOf="@+id/menu" app:layout_constraintStart_toEndOf="@+id/reorder"
app:layout_constraintTop_toTopOf="@+id/manga_full_title" app:layout_constraintTop_toBottomOf="@+id/chapter_title" />
tools:text="(0/10)" />
<TextView <TextView
android:id="@+id/manga_source" android:id="@+id/download_progress_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toEndOf="@id/chapter_title" android:layout_toEndOf="@id/manga_full_title"
android:maxLines="1" android:maxLines="1"
android:textAppearance="@style/TextAppearance.Regular.Caption.Hint" android:textAppearance="@style/TextAppearance.Regular.Caption.Hint"
app:layout_constraintBottom_toBottomOf="@+id/chapter_title" app:layout_constraintBottom_toBottomOf="@+id/manga_full_title"
app:layout_constraintEnd_toStartOf="@+id/menu" app:layout_constraintEnd_toStartOf="@+id/menu"
app:layout_constraintTop_toTopOf="@+id/chapter_title" app:layout_constraintTop_toTopOf="@+id/manga_full_title"
tools:text="Manga Source" /> tools:text="0/10" />
<ImageButton <TextView
android:id="@+id/menu" android:id="@+id/manga_source"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toEndOf="@id/download_progress_text" android:layout_toEndOf="@id/chapter_title"
android:background="@drawable/ripple_regular" android:maxLines="1"
android:contentDescription="@string/action_menu" android:textAppearance="@style/TextAppearance.Regular.Caption.Hint"
android:paddingHorizontal="10dp" app:layout_constraintBottom_toBottomOf="@+id/chapter_title"
android:paddingVertical="16dp" app:layout_constraintEnd_toStartOf="@+id/menu"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toTopOf="@+id/chapter_title"
app:layout_constraintEnd_toEndOf="parent" tools:text="Manga Source" />
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_overflow_24dp"
app:tint="?attr/colorOnBackground" />
</androidx.constraintlayout.widget.ConstraintLayout> <ImageButton
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/download_progress_text"
android:background="@drawable/ripple_regular"
android:contentDescription="@string/action_menu"
android:paddingHorizontal="10dp"
android:paddingVertical="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_overflow_24dp"
app:tint="?attr/colorOnBackground" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>