All refresh thumb at any time
This commit is contained in:
1 parent
dfce07d7eb
commit
725679f5d4
2 files changed
+17
-57
No files matched your search
@@ -73,9 +73,4 @@ public class FixedThumb extends LoadImageView {
|
||||
|
||||
setScaleType(ScaleType.FIT_CENTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreSetImageResource(int resId, boolean isTarget) {
|
||||
setScaleType(ScaleType.FIT_CENTER);
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,6 @@ import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.annotation.IntDef
|
||||
import coil.load
|
||||
import coil.request.Disposable
|
||||
import coil.request.ImageRequest
|
||||
import coil.size.Size
|
||||
import com.hippo.drawable.PreciselyClipDrawable
|
||||
import com.hippo.ehviewer.R
|
||||
@@ -32,14 +30,11 @@ open class LoadImageView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||
) : FixedAspectImageView(context, attrs, defStyleAttr), View.OnClickListener,
|
||||
View.OnLongClickListener {
|
||||
private var mRequest: ImageRequest? = null
|
||||
private var mOffsetX = Integer.MIN_VALUE
|
||||
private var mOffsetY = Integer.MIN_VALUE
|
||||
private var mClipWidth = Integer.MIN_VALUE
|
||||
private var mClipHeight = Integer.MIN_VALUE
|
||||
private var mRetryType: Int = 0
|
||||
private var mFailed: Boolean = false
|
||||
private var task: Disposable? = null
|
||||
private var mUrl: String? = null
|
||||
|
||||
init {
|
||||
val a = context.obtainStyledAttributes(attrs, R.styleable.LoadImageView, defStyleAttr, 0)
|
||||
@@ -47,36 +42,17 @@ open class LoadImageView @JvmOverloads constructor(
|
||||
a.recycle()
|
||||
}
|
||||
|
||||
private fun clearRetry() {
|
||||
if (mRetryType == RETRY_TYPE_CLICK) {
|
||||
setOnClickListener(null)
|
||||
isClickable = false
|
||||
} else if (mRetryType == RETRY_TYPE_LONG_CLICK) {
|
||||
setOnLongClickListener(null)
|
||||
isLongClickable = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun setRetryType(@RetryType retryType: Int) {
|
||||
if (mRetryType != retryType) {
|
||||
val oldRetryType = mRetryType
|
||||
mRetryType = retryType
|
||||
|
||||
if (mFailed) {
|
||||
if (oldRetryType == RETRY_TYPE_CLICK) {
|
||||
setOnClickListener(null)
|
||||
isClickable = false
|
||||
} else if (oldRetryType == RETRY_TYPE_LONG_CLICK) {
|
||||
setOnLongClickListener(null)
|
||||
isLongClickable = false
|
||||
}
|
||||
|
||||
if (retryType == RETRY_TYPE_CLICK) {
|
||||
setOnClickListener(this)
|
||||
} else if (retryType == RETRY_TYPE_LONG_CLICK) {
|
||||
setOnLongClickListener(this)
|
||||
}
|
||||
when (retryType) {
|
||||
RETRY_TYPE_CLICK -> {
|
||||
setOnClickListener(this)
|
||||
}
|
||||
|
||||
RETRY_TYPE_LONG_CLICK -> {
|
||||
setOnLongClickListener(this)
|
||||
}
|
||||
|
||||
RETRY_TYPE_NONE -> {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,12 +71,17 @@ open class LoadImageView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
fun load(url: String, crossfade: Boolean = true) {
|
||||
mUrl = url
|
||||
load(url) {
|
||||
size(Size.ORIGINAL)
|
||||
if (!crossfade) crossfade(false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun reload() {
|
||||
mUrl?.let { this.load(it) }
|
||||
}
|
||||
|
||||
override fun setImageDrawable(drawable: Drawable?) {
|
||||
var newDrawable = drawable
|
||||
if (newDrawable != null) {
|
||||
@@ -120,33 +101,17 @@ open class LoadImageView @JvmOverloads constructor(
|
||||
return newDrawable
|
||||
}
|
||||
|
||||
fun onFailure() {
|
||||
when (mRetryType) {
|
||||
RETRY_TYPE_CLICK -> {
|
||||
setOnClickListener(this)
|
||||
}
|
||||
|
||||
RETRY_TYPE_LONG_CLICK -> {
|
||||
setOnLongClickListener(this)
|
||||
}
|
||||
|
||||
else -> {
|
||||
mRequest = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
reload()
|
||||
}
|
||||
|
||||
override fun onLongClick(v: View): Boolean {
|
||||
reload()
|
||||
return true
|
||||
}
|
||||
|
||||
open fun onPreSetImageDrawable(drawable: Drawable?, isTarget: Boolean) {}
|
||||
|
||||
open fun onPreSetImageResource(resId: Int, isTarget: Boolean) {}
|
||||
|
||||
@IntDef(RETRY_TYPE_NONE, RETRY_TYPE_CLICK, RETRY_TYPE_LONG_CLICK)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
private annotation class RetryType
|
||||
|
||||
Reference in new issue
Block a user