Drop CheckableComposeView
It was required by EasyRecyclerView
This commit is contained in:
1 parent
30ee1816df
commit
eedc3ba5eb
2 files changed
+38
-87
No files matched your search
@@ -19,11 +19,13 @@ import android.graphics.Rect
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.IntDef
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.paging.PagingDataAdapter
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import arrow.core.partially1
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.Settings.detailSize
|
||||
@@ -153,8 +155,8 @@ class GalleryAdapter(
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
|
||||
TYPE_LIST -> ListGalleryHolder(CheckableComposeView(parent.context), showFavorite)
|
||||
TYPE_GRID -> GridGalleryHolder(CheckableComposeView(parent.context))
|
||||
TYPE_LIST -> ListGalleryHolder(ComposeView(parent.context), showFavorite)
|
||||
TYPE_GRID -> GridGalleryHolder(ComposeView(parent.context))
|
||||
else -> error("Unexpected value: $viewType")
|
||||
}
|
||||
|
||||
@@ -162,13 +164,9 @@ class GalleryAdapter(
|
||||
|
||||
override fun onBindViewHolder(holder: GalleryHolder, position: Int) {
|
||||
val gi = getItem(position) ?: return
|
||||
val selected = tracker?.isSelected(gi.gid) ?: false
|
||||
holder.galleryId = gi.gid
|
||||
holder.bind(
|
||||
gi,
|
||||
tracker?.isSelected(gi.gid) ?: false,
|
||||
{ onItemClick(gi) },
|
||||
{ onItemLongClick(gi) },
|
||||
)
|
||||
holder.bind(gi, selected, onItemClick.partially1(gi), onItemLongClick.partially1(gi))
|
||||
}
|
||||
|
||||
@IntDef(TYPE_LIST, TYPE_GRID)
|
||||
|
||||
@@ -15,32 +15,26 @@
|
||||
*/
|
||||
package com.hippo.ehviewer.ui.scene
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.Checkable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.AbstractComposeView
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.accompanist.themeadapter.material3.Mdc3Theme
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.Settings.listThumbSize
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.ui.main.GalleryInfoGridItem
|
||||
import com.hippo.ehviewer.ui.main.GalleryInfoListItem
|
||||
import com.hippo.ehviewer.ui.setMD3Content
|
||||
import eu.kanade.tachiyomi.util.system.pxToDp
|
||||
|
||||
abstract class GalleryHolder(composeView: CheckableComposeView) : RecyclerView.ViewHolder(composeView) {
|
||||
abstract class GalleryHolder(composeView: ComposeView) : RecyclerView.ViewHolder(composeView) {
|
||||
var galleryId = 0L
|
||||
|
||||
abstract fun bind(
|
||||
@@ -51,35 +45,37 @@ abstract class GalleryHolder(composeView: CheckableComposeView) : RecyclerView.V
|
||||
)
|
||||
}
|
||||
|
||||
class ListGalleryHolder(private val composeView: CheckableComposeView, private val showFavourite: Boolean) : GalleryHolder(composeView) {
|
||||
class ListGalleryHolder(private val composeView: ComposeView, private val showFavourite: Boolean) : GalleryHolder(composeView) {
|
||||
|
||||
private val height = (3 * listThumbSize * 3).pxToDp.dp
|
||||
private val showPages = Settings.showGalleryPages
|
||||
|
||||
override fun bind(galleryInfo: GalleryInfo, isChecked: Boolean, onClick: () -> Unit, onLongClick: () -> Unit) {
|
||||
composeView.isChecked = isChecked
|
||||
composeView.setMD3Content {
|
||||
GalleryInfoListItem(
|
||||
onClick = onClick,
|
||||
onLongClick = onLongClick,
|
||||
info = galleryInfo,
|
||||
modifier = Modifier.height(height),
|
||||
isInFavScene = !showFavourite,
|
||||
showPages = showPages,
|
||||
)
|
||||
CheckableItem(checked = isChecked) {
|
||||
GalleryInfoListItem(
|
||||
onClick = onClick,
|
||||
onLongClick = onLongClick,
|
||||
info = galleryInfo,
|
||||
modifier = Modifier.height(height),
|
||||
isInFavScene = !showFavourite,
|
||||
showPages = showPages,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GridGalleryHolder(private val composeView: CheckableComposeView) : GalleryHolder(composeView) {
|
||||
class GridGalleryHolder(private val composeView: ComposeView) : GalleryHolder(composeView) {
|
||||
override fun bind(galleryInfo: GalleryInfo, isChecked: Boolean, onClick: () -> Unit, onLongClick: () -> Unit) {
|
||||
composeView.isChecked = isChecked
|
||||
composeView.setMD3Content {
|
||||
GalleryInfoGridItem(
|
||||
onClick = onClick,
|
||||
onLongClick = onLongClick,
|
||||
info = galleryInfo,
|
||||
)
|
||||
CheckableItem(checked = isChecked) {
|
||||
GalleryInfoGridItem(
|
||||
onClick = onClick,
|
||||
onLongClick = onLongClick,
|
||||
info = galleryInfo,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround https://github.com/Ehviewer-Overhauled/Ehviewer/issues/1023
|
||||
@@ -88,59 +84,16 @@ class GridGalleryHolder(private val composeView: CheckableComposeView) : Gallery
|
||||
}
|
||||
}
|
||||
|
||||
class CheckableComposeView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0,
|
||||
) : AbstractComposeView(context, attrs, defStyleAttr), Checkable {
|
||||
|
||||
private val content = mutableStateOf<(@Composable (Boolean) -> Unit)?>(null)
|
||||
|
||||
private var mChecked by mutableStateOf(false)
|
||||
|
||||
@Suppress("RedundantVisibilityModifier")
|
||||
protected override var shouldCreateCompositionOnAttachedToWindow: Boolean = false
|
||||
private set
|
||||
|
||||
@Composable
|
||||
override fun Content() {
|
||||
content.value?.invoke(mChecked)
|
||||
}
|
||||
|
||||
override fun getAccessibilityClassName(): CharSequence {
|
||||
return javaClass.name
|
||||
}
|
||||
|
||||
private fun setContent(content: @Composable () -> Unit) {
|
||||
shouldCreateCompositionOnAttachedToWindow = true
|
||||
this.content.value = { selected ->
|
||||
Mdc3Theme {
|
||||
Box {
|
||||
content()
|
||||
if (selected) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.align(Alignment.TopEnd),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isAttachedToWindow) {
|
||||
createComposition()
|
||||
@Composable
|
||||
fun CheckableItem(checked: Boolean, content: @Composable () -> Unit) {
|
||||
Box {
|
||||
content()
|
||||
if (checked) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.align(Alignment.TopEnd),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setChecked(value: Boolean) {
|
||||
mChecked = value
|
||||
}
|
||||
|
||||
override fun isChecked() = mChecked
|
||||
|
||||
override fun toggle() {
|
||||
mChecked = !mChecked
|
||||
}
|
||||
|
||||
fun setMD3Content(content: @Composable () -> Unit) = setContent(content)
|
||||
}
|
||||
Reference in new issue
Block a user