Drop FixedThumb
This commit is contained in:
1 parent
be1d80de0f
commit
7ec9d9e1cf
9 files changed
+60
-228
No files matched your search
@@ -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
|
||||
@@ -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<DownloadHolder>() {
|
||||
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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user