Skip to content

Commit

Permalink
Fix note image preview issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ismartcoding committed Aug 11, 2023
1 parent 463eb3c commit 2af2a18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.MotionEvent
import android.widget.TextView
import androidx.core.view.GestureDetectorCompat
import com.ismartcoding.lib.extensions.dp2px
import com.ismartcoding.lib.logcat.LogCat
import com.ismartcoding.lib.markdown.AppImageSchemeHandler
import com.ismartcoding.lib.markdown.FontTagHandler
import com.ismartcoding.lib.markdown.NetworkSchemeHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.ismartcoding.lib.helpers.CoroutinesHelper.coMain
import com.ismartcoding.plain.databinding.ItemImageviewerSubsamplingBinding
import com.ismartcoding.plain.ui.helpers.DialogHelper
import com.ismartcoding.plain.ui.preview.PreviewItem
import com.ismartcoding.plain.ui.preview.utils.initTag
import kotlinx.coroutines.delay
Expand All @@ -26,31 +27,37 @@ class SubsamplingViewHolder(

fun bind(item: PreviewItem) {
val holder = this
binding.loading.isVisible = true
binding.subsamplingView.run {
initTag(item, holder)
orientation = SubsamplingScaleImageView.ORIENTATION_USE_EXIF
coMain {
delay(100)
binding.loading.isVisible = false
if (item.uri.startsWith("http://") || item.uri.startsWith("https://")) {
if (item.uri.startsWith("http://", true) || item.uri.startsWith("https://", true)) {
val request = ImageRequest.Builder(context)
.data(item.uri)
.target(
onStart = { _ ->
binding.loading.isVisible = true
},
onSuccess = { result ->
binding.loading.isVisible = false
val bitmap = (result as? BitmapDrawable)?.bitmap
if (bitmap != null) {
setImage(ImageSource.bitmap(bitmap))
}
},
onError = { _ ->
binding.loading.isVisible = false
}
)
.build()
context.imageLoader.enqueue(request)
} else if (item.uri.startsWith("app://", true)) {
val path = context.getExternalFilesDir(null)?.path?.removeSuffix("/") + "/" + item.uri.substring("app://".length)
setImage(ImageSource.uri(path))
} else {
binding.loading.isVisible = true
delay(100)
binding.loading.isVisible = false
setImage(ImageSource.uri(item.uri))
}
}
Expand Down

0 comments on commit 2af2a18

Please sign in to comment.