Commit d72a59a7 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

photo loads with preview

parent 69b6e42f
......@@ -93,7 +93,7 @@ fun fromRaw(raw:ResolutionRaw) =
//fun fromRaw(raw: List<FeedRaw>):List<FeedEntity> = List(raw.size) { index-> fromRaw(raw[index]) }
//fun fromRaw(raw: List<FeedRaw>):List<FeedEntity> = List(raw.displaySize) { index-> fromRaw(raw[index]) }
fun <E,M> fromRawList(raw: List<E>,block:(E)->M):List<M> = List(raw.size) { index-> block(raw[index]) }
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.domain.model
import com.biganto.visual.roompark.data.repository.db.requrey.model.GalleryPhotoEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.ImageAlbumEntity
import timber.log.Timber
import java.util.*
/**
......@@ -48,8 +49,9 @@ data class PhotoModel(
fun optimalResolution(width:Int,height:Int) =
resolutionList
.asSequence()
.filter { it.resWidth >= width }
.filter { it.resHeight >= height }
.filter { it.resWidth >= width || it.resWidth >= height }
.filter { it.resHeight >= height || it.resHeight >= width }
.onEach { Timber.d("res filtered: ${it.resWidth} / ${it.resHeight}") }
.minBy { it.resHeight * it.resWidth }
?: resolutionList.maxBy { it.resHeight * it.resWidth }!!
......
......@@ -43,7 +43,7 @@ class PhotoScreenController :
private fun bindRecycler() {
photoViewPager.isNestedScrollingEnabled = false
photoViewPager.offscreenPageLimit = 2
photoViewPager.adapter = PhotoViewerAdapter()
}
......
package com.biganto.visual.roompark.presentation.screen.photo.util
import android.app.Activity
import android.graphics.Bitmap
import android.graphics.Point
import android.graphics.drawable.Drawable
import android.util.DisplayMetrics
import android.view.View
import butterknife.BindView
import com.biganto.visual.roompark.R
......@@ -9,7 +14,12 @@ import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyc
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
import com.github.chrisbanes.photoview.PhotoView
import com.google.android.material.textview.MaterialTextView
import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso
import com.squareup.picasso.Target
import jp.wasabeef.picasso.transformations.BlurTransformation
import jp.wasabeef.picasso.transformations.ColorFilterTransformation
import timber.log.Timber
/**
......@@ -34,20 +44,53 @@ class PhotoViewerViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemV
@BindView(R.id.photo_view) lateinit var photoView:PhotoView
@BindView(R.id.photo_description) lateinit var photoDesc:MaterialTextView
val picassoAsync: Picasso by lazy {
private val displayMetrics = DisplayMetrics()
private val displaySize = Point()
private val picassoAsync: Picasso by lazy {
return@lazy RoomParkApplication.component.providePicassoAsync()
}
private val _t = object :Target{
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
Timber.d("lalala")
}
override fun onBitmapFailed(e: java.lang.Exception?, errorDrawable: Drawable?) {
Timber.e(e)
}
override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
Timber.d("bitmap loaded: $bitmap")
photoView.setImageBitmap(bitmap)
}
}
override fun onViewBound(model: PhotoModel) {
photoDesc.visibility = if (model.description.isNullOrBlank()) View.GONE else View.VISIBLE
model.description?.let{ photoDesc.text = it}
model.optimalResolution(photoView.width,photoView.height).let {
model.description?.let { photoDesc.text = it }
(itemView.context as Activity).windowManager.defaultDisplay.getSize(displaySize)
model.resolutionList.minBy { it.resHeight * it.resWidth }?.let { photoRes ->
picassoAsync
.load(it.url)
// .transform(BlurTransformation(itemView.context,13,2))
.into(photoView)
.load(photoRes.url)
.transform(BlurTransformation(itemView.context, 13, 1))
.transform(ColorFilterTransformation(0xCC000000.toInt()))
.into(photoView, object : Callback {
override fun onSuccess() {
model.optimalResolution(displaySize.x, displaySize.y).let {
Timber.d("goonna load image with ${it.resWidth} / ${it.resHeight}")
Picasso.get()
.load(it.url)
.into(_t)
}
}
override fun onError(e: Exception?) {
Timber.e(e)
}
})
}
}
}
......@@ -67,12 +67,12 @@ fun Bitmap.scaleCenterCrop(viewHolder:View): Bitmap {
Timber.d(" left/top $xScale/$yScale")
// Now get the size of the source bitmap when scaled
// Now get the displaySize of the source bitmap when scaled
val scaledWidth = scale * sourceWidth
val scaledHeight = scale * sourceHeight
// Let's find out the upper left coordinates if the scaled bitmap
// should be centered in the new size give by the parameters
// should be centered in the new displaySize give by the parameters
val left = (viewHolder.measuredWidth - scaledWidth) / 2
val top = (viewHolder.measuredHeight - scaledHeight) / 2
......@@ -82,7 +82,7 @@ fun Bitmap.scaleCenterCrop(viewHolder:View): Bitmap {
// be
val targetRect = RectF(left, top, left + scaledWidth, top + scaledHeight)
// Finally, we create a new bitmap of the specified size and draw our new,
// Finally, we create a new bitmap of the specified displaySize and draw our new,
// scaled bitmap onto it.
val dest = Bitmap.createBitmap(viewHolder.measuredWidth, viewHolder.measuredHeight, this.config)
val canvas = Canvas(dest)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment