From ae38fecae749d4becab20848834406c7b9d33741 Mon Sep 17 00:00:00 2001 From: tarsin Date: Fri, 17 Mar 2023 17:42:34 +0800 Subject: [PATCH] Restore preview hint --- .../ehviewer/ui/scene/GalleryDetailScene.kt | 72 ++++++++++++++----- .../hippo/ehviewer/ui/scene/HintAdapter.kt | 53 -------------- 2 files changed, 54 insertions(+), 71 deletions(-) delete mode 100644 app/src/main/java/com/hippo/ehviewer/ui/scene/HintAdapter.kt diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt index 846757e73..da84da312 100755 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt @@ -45,14 +45,17 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridScope import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan +import androidx.compose.foundation.lazy.staggeredgrid.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack @@ -66,6 +69,7 @@ import androidx.compose.material.icons.filled.Share import androidx.compose.material.icons.filled.SwapVerticalCircle import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.DropdownMenu @@ -100,6 +104,7 @@ import androidx.compose.ui.unit.dp import androidx.core.content.ContextCompat import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController +import arrow.core.partially1 import coil.Coil.imageLoader import coil.annotation.ExperimentalCoilApi import com.google.accompanist.themeadapter.material3.Mdc3Theme @@ -199,9 +204,6 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { private var mArchiveFormParamOr: String? = null private var mArchiveList: List? = null private var mCurrentFunds: HomeParser.Funds? = null - private var previewsAdapter: GalleryPreviewsAdapter? = null - private var footerAdapter: HintAdapter? = null - private var headerAdapter: HintAdapter? = null @State private var mState = STATE_INIT @@ -565,6 +567,55 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { } } } + if (galleryDetail != null) { + galleryDetailPreview(galleryDetail) + } + } + } + + private fun LazyStaggeredGridScope.galleryDetailPreview(gd: GalleryDetail) { + val previewList = gd.previewList + item { + Column { + Box( + contentAlignment = Alignment.Center + ) { + Card( + onClick = ::navigateToPreview, + modifier = Modifier + .fillMaxWidth() + .aspectRatio(0.6666667F) + ) {} + Text(stringResource(R.string.more_previews)) + } + Text("") + } + } + items(previewList) { + + } + item { + val footerText = if (gd.previewPages <= 0 || previewList.isEmpty()) { + stringResource(R.string.no_previews) + } else if (gd.previewPages == 1) { + stringResource(R.string.no_more_previews) + } else { + stringResource(R.string.more_previews) + } + Column { + Box( + contentAlignment = Alignment.Center + ) { + Card( + onClick = ::navigateToPreview.partially1(true), + modifier = Modifier + .fillMaxWidth() + .aspectRatio(0.6666667F) + ) {} + Text(footerText) + } + Text("") + } } } @@ -915,7 +966,6 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { ratingText = getAllRatingText(gd.rating, gd.ratingCount) torrentText = resources.getString(R.string.torrent_count, gd.torrentCount) // bindComments(gd.comments!!.comments) - bindPreviews(gd) } @Composable @@ -1034,20 +1084,6 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { */ - private fun bindPreviews(gd: GalleryDetail) { - val previewList = gd.previewList - headerAdapter?.text = getString(R.string.more_previews) - if (gd.previewPages <= 0 || previewList.isEmpty()) { - footerAdapter?.text = getString(R.string.no_previews) - return - } else if (gd.previewPages == 1) { - footerAdapter?.text = getString(R.string.no_more_previews) - } else { - footerAdapter?.text = getString(R.string.more_previews) - } - previewsAdapter?.submitList(previewList) - } - private fun getAllRatingText(rating: Float, ratingCount: Int): String { return getString( R.string.rating_text, diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/HintAdapter.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/HintAdapter.kt deleted file mode 100644 index 6d26f469a..000000000 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/HintAdapter.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.hippo.ehviewer.ui.scene - -import android.view.ViewGroup -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.aspectRatio -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material3.Card -import androidx.compose.material3.Text -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.ComposeView -import androidx.recyclerview.widget.RecyclerView -import com.google.accompanist.themeadapter.material3.Mdc3Theme - -class HintAdapter(private val onClick: () -> Unit) : - RecyclerView.Adapter() { - var text by mutableStateOf("") - - inner class ViewHolder(val composeView: ComposeView) : RecyclerView.ViewHolder(composeView) - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return ViewHolder(ComposeView(parent.context)) - } - - override fun getItemCount(): Int { - return 1 - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - holder.composeView.setContent { - Mdc3Theme { - Column { - Box( - contentAlignment = Alignment.Center - ) { - Card( - onClick = onClick, - modifier = Modifier - .fillMaxWidth() - .aspectRatio(0.6666667F) - ) {} - Text(text) - } - Text("") - } - } - } - } -} \ No newline at end of file