Drop URLImageGetter
This commit is contained in:
1 parent
14faa38de3
commit
31c32123c9
8 files changed
+40
-295
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package com.hippo.ehviewer.ui.legacy
|
||||
|
||||
import android.graphics.drawable.DrawableWrapper
|
||||
import android.text.Html
|
||||
import android.widget.TextView
|
||||
import coil.imageLoader
|
||||
import com.hippo.ehviewer.ktbuilder.imageRequest
|
||||
|
||||
class CoilImageGetter(
|
||||
private val textView: TextView,
|
||||
) : Html.ImageGetter {
|
||||
override fun getDrawable(source: String) = object : DrawableWrapper(null) {}.apply {
|
||||
textView.context.imageLoader.enqueue(
|
||||
textView.context.imageRequest {
|
||||
data(source)
|
||||
crossfade(false)
|
||||
target { drawable ->
|
||||
setDrawable(drawable)
|
||||
setBounds(0, 0, intrinsicWidth, intrinsicHeight)
|
||||
textView.text = textView.text
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,12 @@ import android.text.Spanned
|
||||
import android.text.style.ClickableSpan
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
|
||||
class LinkifyTextView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
) : ObservedTextView(context, attrs) {
|
||||
) : AppCompatTextView(context, attrs) {
|
||||
var currentSpan: ClickableSpan? = null
|
||||
private set
|
||||
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.hippo.ehviewer.ui.legacy
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
|
||||
open class ObservedTextView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
) : AppCompatTextView(context, attrs) {
|
||||
private var mOnWindowAttachListener: OnWindowAttachListener? = null
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
if (mOnWindowAttachListener != null) {
|
||||
mOnWindowAttachListener!!.onAttachedToWindow()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
if (mOnWindowAttachListener != null) {
|
||||
mOnWindowAttachListener!!.onDetachedFromWindow()
|
||||
}
|
||||
}
|
||||
|
||||
fun setOnWindowAttachListener(onWindowAttachListener: OnWindowAttachListener?) {
|
||||
mOnWindowAttachListener = onWindowAttachListener
|
||||
}
|
||||
|
||||
interface OnWindowAttachListener {
|
||||
fun onAttachedToWindow()
|
||||
fun onDetachedFromWindow()
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 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
|
||||
* 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.ui.legacy
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.Html.ImageGetter
|
||||
|
||||
class URLImageGetter(
|
||||
private val mTextView: ObservedTextView,
|
||||
) : ImageGetter {
|
||||
override fun getDrawable(source: String): Drawable {
|
||||
return UnikeryDrawable(mTextView, source)
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright 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
|
||||
* 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.ui.legacy
|
||||
|
||||
import android.graphics.drawable.AnimatedImageDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import coil.imageLoader
|
||||
import coil.request.ImageRequest
|
||||
import com.hippo.ehviewer.ktbuilder.imageRequest
|
||||
|
||||
class UnikeryDrawable(private val mTextView: ObservedTextView, url: String) :
|
||||
WrapDrawable(),
|
||||
ObservedTextView.OnWindowAttachListener {
|
||||
private val mImageRequest: ImageRequest
|
||||
|
||||
init {
|
||||
mTextView.setOnWindowAttachListener(this)
|
||||
mImageRequest = mTextView.context.imageRequest {
|
||||
target(onSuccess = { onGetValue(it) })
|
||||
data(url)
|
||||
}
|
||||
load()
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
drawable ?: load()
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
clearDrawable()
|
||||
}
|
||||
|
||||
fun load() {
|
||||
mTextView.context.imageLoader.enqueue(mImageRequest)
|
||||
}
|
||||
|
||||
private fun clearDrawable() {
|
||||
drawable = null
|
||||
}
|
||||
|
||||
override var drawable: Drawable?
|
||||
get() = super.drawable
|
||||
set(drawable) {
|
||||
// Remove old callback
|
||||
val oldDrawable = drawable
|
||||
if (oldDrawable != null) {
|
||||
oldDrawable.callback = null
|
||||
}
|
||||
super.drawable = drawable
|
||||
if (drawable != null) {
|
||||
drawable.callback = mTextView
|
||||
}
|
||||
updateBounds()
|
||||
if (drawable != null) {
|
||||
invalidateSelf()
|
||||
}
|
||||
}
|
||||
|
||||
override fun invalidateSelf() {
|
||||
val cs = mTextView.text
|
||||
mTextView.text = cs
|
||||
}
|
||||
|
||||
private fun onGetValue(drawable: Drawable) {
|
||||
clearDrawable()
|
||||
this.drawable = drawable
|
||||
if (drawable is AnimatedImageDrawable) {
|
||||
drawable.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Copyright 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
|
||||
* 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.ui.legacy
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.ColorFilter
|
||||
import android.graphics.PixelFormat
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
open class WrapDrawable : Drawable() {
|
||||
open var drawable: Drawable? = null
|
||||
fun updateBounds() {
|
||||
setBounds(0, 0, intrinsicWidth, intrinsicHeight)
|
||||
}
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
if (drawable != null) {
|
||||
drawable!!.draw(canvas)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setBounds(left: Int, top: Int, right: Int, bottom: Int) {
|
||||
super.setBounds(left, top, right, bottom)
|
||||
if (drawable != null) {
|
||||
drawable!!.setBounds(left, top, right, bottom)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setBounds(bounds: Rect) {
|
||||
super.setBounds(bounds)
|
||||
if (drawable != null) {
|
||||
drawable!!.bounds = bounds
|
||||
}
|
||||
}
|
||||
|
||||
override fun getChangingConfigurations(): Int {
|
||||
return if (drawable != null) {
|
||||
drawable!!.changingConfigurations
|
||||
} else {
|
||||
super.getChangingConfigurations()
|
||||
}
|
||||
}
|
||||
|
||||
override fun setChangingConfigurations(configs: Int) {
|
||||
super.setChangingConfigurations(configs)
|
||||
if (drawable != null) {
|
||||
drawable!!.changingConfigurations = configs
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun setDither(dither: Boolean) {
|
||||
super.setDither(dither)
|
||||
if (drawable != null) {
|
||||
drawable!!.setDither(dither)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setFilterBitmap(filter: Boolean) {
|
||||
super.setFilterBitmap(filter)
|
||||
if (drawable != null) {
|
||||
drawable!!.isFilterBitmap = filter
|
||||
}
|
||||
}
|
||||
|
||||
override fun setAlpha(alpha: Int) {
|
||||
if (drawable != null) {
|
||||
drawable!!.alpha = alpha
|
||||
}
|
||||
}
|
||||
|
||||
override fun setColorFilter(cf: ColorFilter?) {
|
||||
if (drawable != null) {
|
||||
drawable!!.colorFilter = cf
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
"Deprecated in Java",
|
||||
ReplaceWith("PixelFormat.TRANSLUCENT", "android.graphics.PixelFormat"),
|
||||
)
|
||||
override fun getOpacity(): Int {
|
||||
return if (drawable != null) {
|
||||
drawable!!.opacity
|
||||
} else {
|
||||
PixelFormat.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
override fun getIntrinsicWidth(): Int {
|
||||
return if (drawable != null) {
|
||||
drawable!!.intrinsicWidth
|
||||
} else {
|
||||
super.getIntrinsicWidth()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getIntrinsicHeight(): Int {
|
||||
return if (drawable != null) {
|
||||
drawable!!.intrinsicHeight
|
||||
} else {
|
||||
super.getIntrinsicHeight()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewAnimationUtils
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.text.getSpans
|
||||
@@ -73,9 +74,8 @@ import com.hippo.ehviewer.databinding.ItemGalleryCommentProgressBinding
|
||||
import com.hippo.ehviewer.databinding.SceneGalleryCommentsBinding
|
||||
import com.hippo.ehviewer.ui.jumpToReaderByPage
|
||||
import com.hippo.ehviewer.ui.legacy.BaseDialogBuilder
|
||||
import com.hippo.ehviewer.ui.legacy.CoilImageGetter
|
||||
import com.hippo.ehviewer.ui.legacy.EditTextDialogBuilder
|
||||
import com.hippo.ehviewer.ui.legacy.ObservedTextView
|
||||
import com.hippo.ehviewer.ui.legacy.URLImageGetter
|
||||
import com.hippo.ehviewer.ui.legacy.ViewTransition
|
||||
import com.hippo.ehviewer.ui.legacy.WindowInsetsAnimationHelper
|
||||
import com.hippo.ehviewer.ui.openBrowser
|
||||
@@ -759,10 +759,10 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
||||
|
||||
private fun generateComment(
|
||||
context: Context,
|
||||
textView: ObservedTextView,
|
||||
textView: TextView,
|
||||
comment: GalleryComment,
|
||||
): CharSequence {
|
||||
sp = comment.comment.orEmpty().parseAsHtml(imageGetter = URLImageGetter(textView))
|
||||
sp = comment.comment.orEmpty().parseAsHtml(imageGetter = CoilImageGetter(textView))
|
||||
val ssb = SpannableStringBuilder(sp)
|
||||
if (0L != comment.id && 0 != comment.score) {
|
||||
val score = comment.score
|
||||
|
||||
@@ -139,9 +139,9 @@ import com.hippo.ehviewer.ui.MainActivity
|
||||
import com.hippo.ehviewer.ui.addToFavorites
|
||||
import com.hippo.ehviewer.ui.legacy.BaseDialogBuilder
|
||||
import com.hippo.ehviewer.ui.legacy.CheckBoxDialogBuilder
|
||||
import com.hippo.ehviewer.ui.legacy.CoilImageGetter
|
||||
import com.hippo.ehviewer.ui.legacy.EditTextDialogBuilder
|
||||
import com.hippo.ehviewer.ui.legacy.GalleryRatingBar.OnUserRateListener
|
||||
import com.hippo.ehviewer.ui.legacy.URLImageGetter
|
||||
import com.hippo.ehviewer.ui.legacy.calculateSuitableSpanCount
|
||||
import com.hippo.ehviewer.ui.main.EhPreviewItem
|
||||
import com.hippo.ehviewer.ui.main.GalleryDetailErrorTip
|
||||
@@ -996,15 +996,14 @@ class GalleryDetailScene : BaseScene() {
|
||||
val length = maxShowCount.coerceAtMost(commentsList.size)
|
||||
for (i in 0 until length) {
|
||||
val comment = commentsList[i]
|
||||
AndroidView(factory = {
|
||||
ItemGalleryCommentBinding.inflate(LayoutInflater.from(it), null, false)
|
||||
.apply {
|
||||
user.text = comment.user
|
||||
user.setBackgroundColor(Color.TRANSPARENT)
|
||||
time.text = ReadableTime.getTimeAgo(comment.time)
|
||||
this.comment.maxLines = 5
|
||||
this.comment.text = comment.comment.orEmpty().parseAsHtml(imageGetter = URLImageGetter(this.comment))
|
||||
}.root
|
||||
AndroidView(factory = { context ->
|
||||
ItemGalleryCommentBinding.inflate(LayoutInflater.from(context), null, false).apply {
|
||||
user.text = comment.user
|
||||
user.setBackgroundColor(Color.TRANSPARENT)
|
||||
time.text = ReadableTime.getTimeAgo(comment.time)
|
||||
this.comment.maxLines = 5
|
||||
this.comment.text = comment.comment.orEmpty().parseAsHtml(imageGetter = CoilImageGetter(this.comment))
|
||||
}.root
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user