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

optimize picasso loader

parent c03a1a85
...@@ -55,6 +55,35 @@ class AlbumsScreenController : ...@@ -55,6 +55,35 @@ class AlbumsScreenController :
val photosBackgroundTarget = object : com.squareup.picasso.Target {
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
Timber.d("View measures: 1 - " +
"${nestedScrollView.width} " +
"/ ${nestedScrollView.height} " +
"/ ${nestedScrollView.measuredWidth} " +
"/${nestedScrollView.measuredHeight}")
nestedScrollView.background = placeHolderDrawable
}
override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {
Timber.e(e)
}
override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
Timber.d("View measures: 2 - " +
"${nestedScrollView.width} " +
"/ ${nestedScrollView.height} " +
"/ ${nestedScrollView.measuredWidth} " +
"/${nestedScrollView.measuredHeight}"
)
val croppedBtimpa = bitmap?.scaleCenterCrop(nestedScrollView)
nestedScrollView.background =
BitmapDrawable(activity?.resources
, croppedBtimpa)
}
}
private fun bindRecycler() { private fun bindRecycler() {
...@@ -141,39 +170,11 @@ class AlbumsScreenController : ...@@ -141,39 +170,11 @@ class AlbumsScreenController :
Timber.d("URL TO LOAD BG $urlToLoadBg") Timber.d("URL TO LOAD BG $urlToLoadBg")
urlToLoadBg.let { urlToLoadBg.let {
Picasso.get() Picasso.Builder(activity!!).build()
.load(it) .load(it)
.transform(BlurTransformation(activity, 13, 2)) .transform(BlurTransformation(activity, 13, 2))
.transform(ColorFilterTransformation(0xCC000000.toInt())) .transform(ColorFilterTransformation(0xCC000000.toInt()))
.into(object : com.squareup.picasso.Target { .into(photosBackgroundTarget)
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
Timber.d("View measures: 1 - " +
"${nestedScrollView.width} " +
"/ ${nestedScrollView.height} " +
"/ ${nestedScrollView.measuredWidth} " +
"/${nestedScrollView.measuredHeight}")
nestedScrollView.background = placeHolderDrawable
}
override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {
Timber.e(e)
}
override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
Timber.d("View measures: 2 - " +
"${nestedScrollView.width} " +
"/ ${nestedScrollView.height} " +
"/ ${nestedScrollView.measuredWidth} " +
"/${nestedScrollView.measuredHeight}"
)
val croppedBtimpa = bitmap?.scaleCenterCrop(nestedScrollView)
nestedScrollView.background =
BitmapDrawable(activity?.resources
, croppedBtimpa)
}
})
} }
} }
catch (e:java.lang.Exception){Timber.e(e)} catch (e:java.lang.Exception){Timber.e(e)}
......
...@@ -5,6 +5,7 @@ import androidx.recyclerview.widget.RecyclerView ...@@ -5,6 +5,7 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager import androidx.recyclerview.widget.StaggeredGridLayoutManager
import butterknife.BindView import butterknife.BindView
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.domain.model.AlbumSortedModel import com.biganto.visual.roompark.domain.model.AlbumSortedModel
import com.biganto.visual.roompark.domain.model.PhotoModel import com.biganto.visual.roompark.domain.model.PhotoModel
import com.biganto.visual.roompark.domain.model.PhotoResolutionModel import com.biganto.visual.roompark.domain.model.PhotoResolutionModel
...@@ -13,6 +14,7 @@ import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewH ...@@ -13,6 +14,7 @@ import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewH
import com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView import com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
import java.util.concurrent.Executors
/** /**
* Created by Vladislav Bogdashkin on 16.10.2019. * Created by Vladislav Bogdashkin on 16.10.2019.
...@@ -51,6 +53,10 @@ class PhotosAdapter : CommonRecyclerAdapter<PhotosViewHolder, PhotoModel>() { ...@@ -51,6 +53,10 @@ class PhotosAdapter : CommonRecyclerAdapter<PhotosViewHolder, PhotoModel>() {
override fun getVhLayout(): Int = R.layout.photo_preview_viewholder override fun getVhLayout(): Int = R.layout.photo_preview_viewholder
} }
val exSercv = Executors.newFixedThreadPool(4)
val picoAbuilder= Picasso.Builder(RoomParkApplication.component.provideAppContext())
.executor(exSercv)
.build()
class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView) { class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView) {
...@@ -58,7 +64,7 @@ class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView) ...@@ -58,7 +64,7 @@ class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView)
override fun onViewBound(model: PhotoModel) { override fun onViewBound(model: PhotoModel) {
model.resolutionList.lowelest()?.let { model.resolutionList.lowelest()?.let {
Picasso.get() picoAbuilder
.load(it.url) .load(it.url)
.centerCrop() .centerCrop()
.fit() .fit()
......
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