Initial move GalleryHolder to compose
TODO: Grid categoryColor, simpleLang badge, and don't show favourite icon in FavouriteScene
This commit is contained in:
1 parent
1bb0c1d537
commit
bb6ed820a7
6 files changed
+51
-276
No files matched your search
@@ -822,16 +822,16 @@ class FavoritesScene :
|
||||
resources: Resources,
|
||||
recyclerView: RecyclerView,
|
||||
type: Int,
|
||||
) : GalleryAdapter(inflater, resources, recyclerView, type, false) {
|
||||
) : GalleryAdapter(resources, recyclerView, type, false) {
|
||||
override fun getItemCount(): Int {
|
||||
return if (null != mHelper) mHelper!!.size() else 0
|
||||
}
|
||||
|
||||
override fun onItemClick(view: View, position: Int) {
|
||||
override fun onItemClick(position: Int) {
|
||||
this@FavoritesScene.onItemClick(position)
|
||||
}
|
||||
|
||||
override fun onItemLongClick(view: View, position: Int): Boolean {
|
||||
override fun onItemLongClick(position: Int): Boolean {
|
||||
return this@FavoritesScene.onItemLongClick(position)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,24 +17,20 @@ package com.hippo.ehviewer.ui.scene
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.res.Resources
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.IntDef
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.hippo.easyrecyclerview.MarginItemDecoration
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.databinding.ItemGalleryGridBinding
|
||||
import com.hippo.ehviewer.databinding.ItemGalleryListBinding
|
||||
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager
|
||||
import com.hippo.widget.recyclerview.STRATEGY_MIN_SIZE
|
||||
import com.hippo.widget.recyclerview.STRATEGY_SUITABLE_SIZE
|
||||
|
||||
internal abstract class GalleryAdapter(
|
||||
private val mInflater: LayoutInflater,
|
||||
abstract class GalleryAdapter(
|
||||
private val mResources: Resources,
|
||||
private val mRecyclerView: RecyclerView,
|
||||
type: Int,
|
||||
@@ -125,24 +121,17 @@ internal abstract class GalleryAdapter(
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GalleryHolder {
|
||||
val holder = when (viewType) {
|
||||
TYPE_LIST -> ListGalleryHolder(
|
||||
ItemGalleryListBinding.inflate(mInflater, parent, false),
|
||||
ComposeView(parent.context),
|
||||
mShowFavourited,
|
||||
)
|
||||
|
||||
TYPE_GRID -> GridGalleryHolder(ItemGalleryGridBinding.inflate(mInflater, parent, false))
|
||||
TYPE_GRID -> GridGalleryHolder(ComposeView(parent.context))
|
||||
else -> throw IllegalStateException("Unexpected value: $viewType")
|
||||
}
|
||||
holder.itemView.setOnClickListener {
|
||||
onItemClick(holder.itemView, holder.bindingAdapterPosition)
|
||||
}
|
||||
holder.itemView.setOnLongClickListener {
|
||||
onItemLongClick(holder.itemView, holder.bindingAdapterPosition)
|
||||
}
|
||||
return holder
|
||||
}
|
||||
|
||||
abstract fun onItemClick(view: View, position: Int)
|
||||
abstract fun onItemLongClick(view: View, position: Int): Boolean
|
||||
abstract fun onItemClick(position: Int)
|
||||
abstract fun onItemLongClick(position: Int): Boolean
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return mType
|
||||
}
|
||||
@@ -151,7 +140,11 @@ internal abstract class GalleryAdapter(
|
||||
|
||||
override fun onBindViewHolder(holder: GalleryHolder, position: Int) {
|
||||
val gi = getDataAt(position) ?: return
|
||||
holder.bind(gi)
|
||||
holder.bind(
|
||||
gi,
|
||||
{ onItemClick(position) },
|
||||
{ onItemLongClick(position) },
|
||||
)
|
||||
}
|
||||
|
||||
@IntDef(TYPE_LIST, TYPE_GRID)
|
||||
|
||||
@@ -15,107 +15,68 @@
|
||||
*/
|
||||
package com.hippo.ehviewer.ui.scene
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.hippo.drawable.TriangleDrawable
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.databinding.ItemGalleryGridBinding
|
||||
import com.hippo.ehviewer.databinding.ItemGalleryListBinding
|
||||
import com.hippo.ehviewer.download.DownloadManager
|
||||
import com.hippo.ehviewer.ui.widget.EhAsyncThumb
|
||||
import com.hippo.ehviewer.ui.widget.ListInfoCard
|
||||
import com.hippo.ehviewer.ui.widget.setMD3Content
|
||||
import eu.kanade.tachiyomi.util.system.pxToDp
|
||||
|
||||
internal abstract class GalleryHolder(binding: ViewBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
abstract fun bind(galleryInfo: GalleryInfo)
|
||||
abstract class GalleryHolder(composeView: ComposeView) : RecyclerView.ViewHolder(composeView) {
|
||||
abstract fun bind(
|
||||
galleryInfo: GalleryInfo,
|
||||
onClick: () -> Unit,
|
||||
onLongClick: () -> Unit,
|
||||
)
|
||||
}
|
||||
|
||||
internal class ListGalleryHolder(
|
||||
private val binding: ItemGalleryListBinding,
|
||||
class ListGalleryHolder(
|
||||
private val composeView: ComposeView,
|
||||
private val showFavourited: Boolean,
|
||||
) : GalleryHolder(binding) {
|
||||
) : GalleryHolder(composeView) {
|
||||
|
||||
private val height = (Settings.listThumbSize * 3).pxToDp.dp
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun bind(galleryInfo: GalleryInfo) {
|
||||
binding.run {
|
||||
thumb.setMD3Content {
|
||||
Card {
|
||||
EhAsyncThumb(
|
||||
model = galleryInfo.thumb,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier
|
||||
.height(height)
|
||||
.aspectRatio(0.6666667F),
|
||||
)
|
||||
}
|
||||
}
|
||||
title.text = EhUtils.getSuitableTitle(galleryInfo)
|
||||
uploader.text = galleryInfo.uploader
|
||||
uploader.alpha = if (galleryInfo.disowned) .5f else 1f
|
||||
rating.rating = galleryInfo.rating
|
||||
val newCategoryText = EhUtils.getCategory(galleryInfo.category)
|
||||
if (newCategoryText != category.text.toString()) {
|
||||
category.text = newCategoryText
|
||||
category.setBackgroundColor(EhUtils.getCategoryColor(galleryInfo.category))
|
||||
}
|
||||
posted.text = galleryInfo.posted
|
||||
if (galleryInfo.pages == 0 || !Settings.showGalleryPages) {
|
||||
pages.text = null
|
||||
pages.visibility = View.GONE
|
||||
} else {
|
||||
pages.text = "${galleryInfo.pages}P"
|
||||
pages.visibility = View.VISIBLE
|
||||
}
|
||||
if (TextUtils.isEmpty(galleryInfo.simpleLanguage)) {
|
||||
simpleLanguage.text = null
|
||||
simpleLanguage.visibility = View.GONE
|
||||
} else {
|
||||
simpleLanguage.text = galleryInfo.simpleLanguage
|
||||
simpleLanguage.visibility = View.VISIBLE
|
||||
}
|
||||
favourited.visibility =
|
||||
if (showFavourited && galleryInfo.favoriteSlot >= -1 && galleryInfo.favoriteSlot <= 10) View.VISIBLE else View.GONE
|
||||
downloaded.visibility =
|
||||
if (DownloadManager.containDownloadInfo(galleryInfo.gid)) View.VISIBLE else View.GONE
|
||||
override fun bind(galleryInfo: GalleryInfo, onClick: () -> Unit, onLongClick: () -> Unit) {
|
||||
composeView.setMD3Content {
|
||||
ListInfoCard(
|
||||
onClick = onClick,
|
||||
onLongClick = onLongClick,
|
||||
info = galleryInfo,
|
||||
modifier = Modifier.height(height),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class GridGalleryHolder(private val binding: ItemGalleryGridBinding) :
|
||||
GalleryHolder(binding) {
|
||||
override fun bind(galleryInfo: GalleryInfo) {
|
||||
binding.run {
|
||||
val aspect = (galleryInfo.thumbWidth.toFloat() / galleryInfo.thumbHeight).coerceIn(0.33F, 1.5F)
|
||||
thumb.setMD3Content {
|
||||
class GridGalleryHolder(private val composeView: ComposeView) : GalleryHolder(composeView) {
|
||||
override fun bind(galleryInfo: GalleryInfo, onClick: () -> Unit, onLongClick: () -> Unit) {
|
||||
val aspect = (galleryInfo.thumbWidth.toFloat() / galleryInfo.thumbHeight).coerceIn(0.33F, 1.5F)
|
||||
val color = EhUtils.getCategoryColor(galleryInfo.category)
|
||||
val simpleLang = galleryInfo.simpleLanguage
|
||||
composeView.setMD3Content {
|
||||
ElevatedCard(modifier = Modifier.padding(2.dp)) {
|
||||
EhAsyncThumb(
|
||||
model = galleryInfo.thumb,
|
||||
modifier = Modifier.aspectRatio(aspect),
|
||||
modifier = Modifier.aspectRatio(aspect).fillMaxWidth().combinedClickable(
|
||||
onClick = onClick,
|
||||
onLongClick = onLongClick,
|
||||
),
|
||||
contentScale = ContentScale.Crop,
|
||||
)
|
||||
}
|
||||
var drawable = category.background
|
||||
val color = EhUtils.getCategoryColor(galleryInfo.category)
|
||||
if (drawable !is TriangleDrawable) {
|
||||
drawable = TriangleDrawable(color)
|
||||
category.background = drawable
|
||||
} else {
|
||||
drawable.setColor(color)
|
||||
}
|
||||
simpleLanguage.text = galleryInfo.simpleLanguage
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1257,16 +1257,16 @@ class GalleryListScene :
|
||||
resources: Resources,
|
||||
recyclerView: RecyclerView,
|
||||
type: Int,
|
||||
) : GalleryAdapter(inflater, resources, recyclerView, type, true) {
|
||||
) : GalleryAdapter(resources, recyclerView, type, true) {
|
||||
override fun getItemCount(): Int {
|
||||
return if (null != mHelper) mHelper!!.size() else 0
|
||||
}
|
||||
|
||||
override fun onItemClick(view: View, position: Int) {
|
||||
override fun onItemClick(position: Int) {
|
||||
this@GalleryListScene.onItemClick(position)
|
||||
}
|
||||
|
||||
override fun onItemLongClick(view: View, position: Int): Boolean {
|
||||
override fun onItemLongClick(position: Int): Boolean {
|
||||
return this@GalleryListScene.onItemLongClick(position)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright 2016 Hippo Seven
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/card"
|
||||
style="@style/Widget.Material3.CardView.Elevated"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="2dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:checkable="true"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<androidx.compose.ui.platform.ComposeView
|
||||
android:id="@+id/thumb"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/category"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="top|right" />
|
||||
|
||||
<TextView xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/simple_language"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|right"
|
||||
android:layout_marginRight="2dp"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="10dp"
|
||||
android:textStyle="bold"
|
||||
tools:ignore="SpUsage" />
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
@@ -1,129 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (C) 2015 Hippo Seven
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/card"
|
||||
style="@style/Widget.Material3.CardView.Filled"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="6dp"
|
||||
android:checkable="true"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
app:cardBackgroundColor="@android:color/transparent">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.compose.ui.platform.ComposeView
|
||||
android:id="@+id/thumb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
style="@style/CardTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_toEndOf="@id/thumb" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/uploader"
|
||||
style="@style/CardMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@id/rating"
|
||||
android:layout_alignStart="@id/title"
|
||||
android:layout_marginTop="2dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/category"
|
||||
style="@style/CardMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignStart="@id/title"
|
||||
android:layout_alignBottom="@id/thumb"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingRight="8dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@android:color/white" />
|
||||
|
||||
<com.hippo.ehviewer.widget.SimpleRatingView
|
||||
android:id="@+id/rating"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@id/category"
|
||||
android:layout_alignStart="@id/title"
|
||||
android:layout_marginBottom="2dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/posted"
|
||||
style="@style/CardMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@id/thumb"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:layout_marginBottom="4dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@id/posted"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:divider="@drawable/spacer_x6"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:showDividers="middle">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/downloaded"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:visibility="gone"
|
||||
app:srcCompat="@drawable/v_download_x16" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/favourited"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:visibility="gone"
|
||||
app:srcCompat="@drawable/v_heart_x16" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/simple_language"
|
||||
style="@style/CardMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pages"
|
||||
style="@style/CardMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
Reference in new issue
Block a user