From 73e5e9ecd9f39af88183eaadc2832e8d8b87063e Mon Sep 17 00:00:00 2001
From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com>
Date: Thu, 10 Jun 2021 04:16:59 +0700
Subject: [PATCH] Add background to draggable items (#5353)
---
.../tachiyomi/ui/category/CategoryHolder.kt | 9 +
.../tachiyomi/ui/download/DownloadHolder.kt | 11 +-
app/src/main/res/layout/categories_item.xml | 63 +++---
app/src/main/res/layout/download_item.xml | 187 +++++++++---------
4 files changed, 150 insertions(+), 120 deletions(-)
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt
index 98ad8306cf..be6483e859 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt
@@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.category
import android.view.View
+import androidx.recyclerview.widget.ItemTouchHelper
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.databinding.CategoriesItemBinding
@@ -36,5 +37,13 @@ class CategoryHolder(view: View, val adapter: CategoryAdapter) : FlexibleViewHol
override fun onItemReleased(position: Int) {
super.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
+ }
}
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt
index f7d76643a3..f0ff9c3b72 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt
@@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.download
import android.view.View
+import androidx.recyclerview.widget.ItemTouchHelper
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R
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) {
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) {
super.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) {
diff --git a/app/src/main/res/layout/categories_item.xml b/app/src/main/res/layout/categories_item.xml
index c5bf5edc3a..a729e8982b 100644
--- a/app/src/main/res/layout/categories_item.xml
+++ b/app/src/main/res/layout/categories_item.xml
@@ -1,40 +1,41 @@
-
+ android:layout_height="wrap_content"
+ app:cardBackgroundColor="?android:attr/colorBackground"
+ app:cardElevation="0dp">
-
+ android:background="@drawable/list_item_selector_background">
-
+
-
+
-
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/download_item.xml b/app/src/main/res/layout/download_item.xml
index e433955d82..b353473cb0 100644
--- a/app/src/main/res/layout/download_item.xml
+++ b/app/src/main/res/layout/download_item.xml
@@ -1,102 +1,113 @@
-
+ android:layout_marginTop="8dp"
+ app:cardBackgroundColor="?android:attr/colorBackground"
+ app:cardElevation="0dp">
-
+ android:background="@drawable/list_item_selector_background">
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+