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

some fixes

parent 6340a573
package com.biganto.visual.roompark.presentation.screen.photo.util
import android.content.Context
import android.graphics.Point
import android.view.View
import android.view.WindowManager
import butterknife.BindView
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication
......@@ -11,6 +14,8 @@ import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewH
import com.github.chrisbanes.photoview.PhotoView
import com.google.android.material.textview.MaterialTextView
import timber.log.Timber
import javax.security.auth.callback.Callback
import kotlin.math.absoluteValue
/**
* Created by Vladislav Bogdashkin on 16.10.2019.
......@@ -36,26 +41,76 @@ class PhotosAdapter : CommonRecyclerAdapter<PhotosViewHolder, PhotoModel>() {
class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView) {
@BindView(R.id.photo_view) lateinit var photoPreview: PhotoView
@BindView(R.id.photo_view)
lateinit var photoPreview: PhotoView
@BindView(R.id.photo_description) lateinit var description: MaterialTextView
@BindView(R.id.photo_description)
lateinit var description: MaterialTextView
private val picassoAsync by lazy {
return@lazy RoomParkApplication.component.providePicassoAsync()
}
private val windowSize by lazy {
val pSize: Point = Point()
(itemView.context.getSystemService(Context.WINDOW_SERVICE) as WindowManager)
.defaultDisplay.getSize(pSize)
pSize
}
override fun onViewBound(model: PhotoModel) {
description.visibility = if (model.description != null) View.VISIBLE else View.GONE
model.description?.let{ description.text = it}
model.description?.let { description.text = it }
model.resolutionList.lowelest()?.let {
picassoAsync
.load(it.url)
.centerCrop()
.fit()
.into(photoPreview, object :Callback, com.squareup.picasso.Callback {
override fun onSuccess() {
model.resolutionList
.onEach { Timber.d("val ensure: ${it.resWidth} : ${it.resHeight}") }
.minBy {
((windowSize.x - it.resWidth + .1f).absoluteValue
+ (windowSize.y - it.resHeight + .1f).absoluteValue
)
}
?.let {photo ->
Timber.d("val: ${photo.resWidth} : ${photo.resHeight}")
picassoAsync
.load(photo.url)
.centerCrop()
.fit()
.into(photoPreview)
}}
}
}
override fun onError(e: Exception?) {
model.resolutionList
.onEach { Timber.d("val ensure: ${it.resWidth} : ${it.resHeight}") }
.minBy {
((windowSize.x - it.resWidth + .1f).absoluteValue
+ (windowSize.y - it.resHeight + .1f).absoluteValue
)
}
?.let {
Timber.d("val: ${it.resWidth} : ${it.resHeight}")
picassoAsync
.load(it.url)
.centerCrop()
.fit()
.into(photoPreview)
}
}
})
}
}
}
private fun List<PhotoResolutionModel>.lowelest() =
......
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