diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryPreview.kt b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryPreview.kt index 0ede3519c..04eef9410 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryPreview.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryPreview.kt @@ -16,7 +16,6 @@ package com.hippo.ehviewer.client.data import android.os.Parcelable -import com.hippo.widget.LoadImageView import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize @@ -30,9 +29,4 @@ data class GalleryPreview( val offsetY: Int = Int.MIN_VALUE, val clipWidth: Int = Int.MIN_VALUE, val clipHeight: Int = Int.MIN_VALUE, -) : Parcelable { - fun load(view: LoadImageView) { - view.setClip(offsetX, offsetY, clipWidth, clipHeight) - view.load(imageUrl) - } -} +) : Parcelable diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt index 5774534fb..6d09136a7 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt @@ -28,6 +28,12 @@ import android.view.View import android.view.ViewGroup import android.widget.Button import androidx.appcompat.app.AlertDialog +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.height +import androidx.compose.material3.Card +import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.unit.dp import androidx.core.content.ContextCompat import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout @@ -37,6 +43,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.SimpleItemAnimator import androidx.recyclerview.widget.StaggeredGridLayoutManager +import com.google.accompanist.themeadapter.material3.Mdc3Theme import com.google.android.material.floatingactionbutton.FloatingActionButton import com.hippo.app.BaseDialogBuilder import com.hippo.app.CheckBoxDialogBuilder @@ -60,6 +67,7 @@ import com.hippo.ehviewer.download.DownloadManager.DownloadInfoListener import com.hippo.ehviewer.download.DownloadService import com.hippo.ehviewer.download.DownloadService.Companion.clear import com.hippo.ehviewer.spider.SpiderDen +import com.hippo.ehviewer.ui.widget.EhAsyncThumb import com.hippo.unifile.UniFile import com.hippo.view.ViewTransition import com.hippo.widget.FabLayout @@ -69,13 +77,13 @@ import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager import com.hippo.widget.recyclerview.STRATEGY_MIN_SIZE import com.hippo.yorozuya.FileUtils import com.hippo.yorozuya.ObjectUtils -import com.hippo.yorozuya.ViewUtils import com.hippo.yorozuya.collect.LongList import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchNonCancellable import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.lang.withUIContext +import eu.kanade.tachiyomi.util.system.pxToDp import rikka.core.res.resolveColor import java.util.LinkedList import com.hippo.ehviewer.download.DownloadManager as downloadManager @@ -808,16 +816,9 @@ class DownloadsScene : private inner class DownloadHolder( private val binding: ItemDownloadBinding, - thumbWidth: Int, - thumbHeight: Int, ) : RecyclerView.ViewHolder(binding.root), View.OnClickListener { init { - val lp = binding.thumb.layoutParams - lp.width = thumbWidth - lp.height = thumbHeight - binding.thumb.layoutParams = lp - // TODO cancel on click listener when select items binding.thumb.setOnClickListener(this) binding.start.setOnClickListener(this) @@ -857,8 +858,22 @@ class DownloadsScene : } } + private val height = (Settings.listThumbSize * 3).pxToDp.dp + fun bind(info: DownloadInfo) { - info.thumb?.let { binding.thumb.load(it) } + binding.thumb.setContent { + Mdc3Theme { + Card { + EhAsyncThumb( + model = info.thumb, + contentScale = ContentScale.Crop, + modifier = Modifier + .height(height) + .aspectRatio(0.6666667F), + ) + } + } + } binding.title.text = EhUtils.getSuitableTitle(info) binding.uploader.text = info.uploader binding.rating.rating = info.rating @@ -955,16 +970,6 @@ class DownloadsScene : private inner class DownloadAdapter : RecyclerView.Adapter() { private val mInflater: LayoutInflater = layoutInflater - private val mListThumbWidth: Int - private val mListThumbHeight: Int - - init { - @SuppressLint("InflateParams") - val calculator = mInflater.inflate(R.layout.item_gallery_list_thumb_height, null) - ViewUtils.measureView(calculator, 1024, ViewGroup.LayoutParams.WRAP_CONTENT) - mListThumbHeight = calculator.measuredHeight - mListThumbWidth = mListThumbHeight * 2 / 3 - } override fun getItemId(position: Int): Long { return if (mList == null || position < 0 || position >= mList!!.size) { @@ -975,11 +980,7 @@ class DownloadsScene : } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DownloadHolder { - val holder = DownloadHolder( - ItemDownloadBinding.inflate(mInflater, parent, false), - mListThumbWidth, - mListThumbHeight, - ) + val holder = DownloadHolder(ItemDownloadBinding.inflate(mInflater, parent, false)) holder.itemView.setOnClickListener { onItemClick(holder.bindingAdapterPosition) } holder.itemView.setOnLongClickListener { onItemLongClick(holder.bindingAdapterPosition) } return holder diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt index e28416124..2343b0749 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt @@ -32,7 +32,6 @@ 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 -import com.hippo.yorozuya.ViewUtils internal abstract class GalleryAdapter( private val mInflater: LayoutInflater, @@ -45,8 +44,6 @@ internal abstract class GalleryAdapter( AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL) private val mPaddingTopSB: Int = mResources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar) - private val mListThumbWidth: Int - private val mListThumbHeight: Int private val mShowFavourited: Boolean private var mListDecoration: MarginItemDecoration? = null private var mGirdDecoration: MarginItemDecoration? = null @@ -111,11 +108,6 @@ internal abstract class GalleryAdapter( mRecyclerView.adapter = this mRecyclerView.layoutManager = mLayoutManager @SuppressLint("InflateParams") - val calculator = - mInflater.inflate(R.layout.item_gallery_list_thumb_height, null) - ViewUtils.measureView(calculator, 1024, ViewGroup.LayoutParams.WRAP_CONTENT) - mListThumbHeight = calculator.measuredHeight - mListThumbWidth = mListThumbHeight * 2 / 3 this.type = type adjustPaddings() } @@ -135,8 +127,6 @@ internal abstract class GalleryAdapter( TYPE_LIST -> ListGalleryHolder( ItemGalleryListBinding.inflate(mInflater, parent, false), mShowFavourited, - mListThumbWidth, - mListThumbHeight, ) TYPE_GRID -> GridGalleryHolder(ItemGalleryGridBinding.inflate(mInflater, parent, false)) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryHolder.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryHolder.kt index fa660609f..84af1d11e 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryHolder.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryHolder.kt @@ -18,8 +18,15 @@ package com.hippo.ehviewer.ui.scene import android.annotation.SuppressLint import android.text.TextUtils import android.view.View +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.height +import androidx.compose.material3.Card +import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.unit.dp import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding +import com.google.accompanist.themeadapter.material3.Mdc3Theme import com.hippo.drawable.TriangleDrawable import com.hippo.ehviewer.Settings import com.hippo.ehviewer.client.EhUtils @@ -27,6 +34,8 @@ 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 eu.kanade.tachiyomi.util.system.pxToDp internal abstract class GalleryHolder(binding: ViewBinding) : RecyclerView.ViewHolder(binding.root) { @@ -36,20 +45,24 @@ internal abstract class GalleryHolder(binding: ViewBinding) : internal class ListGalleryHolder( private val binding: ItemGalleryListBinding, private val showFavourited: Boolean, - thumbWidth: Int, - thumbHeight: Int, ) : GalleryHolder(binding) { - init { - val lp = binding.thumb.layoutParams - lp.width = thumbWidth - lp.height = thumbHeight - binding.thumb.layoutParams = lp - } + + private val height = (Settings.listThumbSize * 3).pxToDp.dp @SuppressLint("SetTextI18n") override fun bind(galleryInfo: GalleryInfo) { binding.run { - thumb.load(galleryInfo.thumb!!) + thumb.setContent { + Mdc3Theme { + 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 diff --git a/app/src/main/java/com/hippo/ehviewer/widget/FixedThumb.java b/app/src/main/java/com/hippo/ehviewer/widget/FixedThumb.java deleted file mode 100644 index 606846d69..000000000 --- a/app/src/main/java/com/hippo/ehviewer/widget/FixedThumb.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2019 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. - */ - -package com.hippo.ehviewer.widget; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; - -import com.hippo.ehviewer.R; -import com.hippo.widget.LoadImageView; - -public class FixedThumb extends LoadImageView { - - private float minAspect; - private float maxAspect; - private boolean alwaysCutAndScale; - - public FixedThumb(Context context) { - super(context); - init(context, null, 0, 0); - } - - public FixedThumb(Context context, AttributeSet attrs) { - super(context, attrs); - init(context, attrs, 0, 0); - } - - public FixedThumb(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - init(context, attrs, defStyle, 0); - } - - private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FixedThumb, defStyleAttr, defStyleRes); - minAspect = a.getFloat(R.styleable.FixedThumb_minAspect, 0.0f); - maxAspect = a.getFloat(R.styleable.FixedThumb_maxAspect, 0.0f); - alwaysCutAndScale = a.getBoolean(R.styleable.FixedThumb_alwaysCutAndScale, false); - a.recycle(); - } - - @Override - public void onPreSetImageDrawable(Drawable drawable, boolean isTarget) { - if (alwaysCutAndScale) { - setScaleType(ScaleType.CENTER_CROP); - return; - } - if (isTarget && drawable != null) { - int width = drawable.getIntrinsicWidth(); - int height = drawable.getIntrinsicHeight(); - if (width > 0 && height > 0) { - float aspect = (float) width / (float) height; - if (aspect < maxAspect && aspect > minAspect) { - setScaleType(ScaleType.CENTER_CROP); - return; - } - } - } - - setScaleType(ScaleType.FIT_CENTER); - } -} diff --git a/app/src/main/java/com/hippo/ehviewer/widget/ResizeableFixedThumb.kt b/app/src/main/java/com/hippo/ehviewer/widget/ResizeableFixedThumb.kt deleted file mode 100644 index dea6b986c..000000000 --- a/app/src/main/java/com/hippo/ehviewer/widget/ResizeableFixedThumb.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.hippo.ehviewer.widget - -import android.content.Context -import android.util.AttributeSet -import com.hippo.ehviewer.Settings - -class ResizeableFixedThumb @JvmOverloads constructor( - context: Context, - attrs: AttributeSet? = null, -) : FixedThumb(context, attrs) { - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - setMeasuredDimension(Settings.listThumbSize * 2, Settings.listThumbSize * 3) - } -} diff --git a/app/src/main/res/layout/item_download.xml b/app/src/main/res/layout/item_download.xml index aac76b4a1..4840cca5f 100644 --- a/app/src/main/res/layout/item_download.xml +++ b/app/src/main/res/layout/item_download.xml @@ -29,20 +29,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - - - - + android:layout_height="wrap_content" /> + android:layout_toEndOf="@id/thumb" /> diff --git a/app/src/main/res/layout/item_gallery_list.xml b/app/src/main/res/layout/item_gallery_list.xml index ff08b2625..b3a72077c 100644 --- a/app/src/main/res/layout/item_gallery_list.xml +++ b/app/src/main/res/layout/item_gallery_list.xml @@ -29,20 +29,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - - - - + android:layout_height="wrap_content" /> + android:layout_toEndOf="@id/thumb" /> diff --git a/app/src/main/res/layout/item_gallery_list_thumb_height.xml b/app/src/main/res/layout/item_gallery_list_thumb_height.xml deleted file mode 100644 index e8f3a0fcf..000000000 --- a/app/src/main/res/layout/item_gallery_list_thumb_height.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - -