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

bluured and cropped background

parent fdcdf6b9
......@@ -33,6 +33,8 @@ private const val TIMEOUT_SECONDS=120L
private const val WRITE_SECONDS=120L
private const val READ_SECONDS=120L
val INTERCEPT_LOG_LEVEL = HttpLoggingInterceptor.Level.NONE
@Module
class RetrofitModule{
......@@ -70,7 +72,7 @@ class RetrofitModule{
.addInterceptor(VersionValidationInterceptor(appVersionManager))
.addInterceptor(
HttpLoggingInterceptor { Timber.tag("OkHttp").d("RetroLogger: $it") }
.setLevel(HttpLoggingInterceptor.Level.BODY)
.setLevel(INTERCEPT_LOG_LEVEL)
)
.addInterceptor {
it.proceed(
......
......@@ -30,8 +30,8 @@ class DbModule{
Timber.d("Kotlin store creating..")
val source = DatabaseSource(context, Models.DEFAULT, "BigantoPerfect", DATABASE_VERSION)
source.setLoggingEnabled(true)
source.setWriteAheadLoggingEnabled(true)
// source.setLoggingEnabled(true)
// source.setWriteAheadLoggingEnabled(true)
source.setTableCreationMode(TableCreationMode.DROP_CREATE)
val store = KotlinEntityDataStore<Persistable>(source.configuration)
......
package com.biganto.visual.roompark.presentation.screen.albums
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.View
import androidx.core.os.bundleOf
......@@ -14,8 +17,12 @@ import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.albums.util.AlbumsHeaderAdapter
import com.biganto.visual.roompark.presentation.screen.favorites.util.AlbumListAdapter
import com.biganto.visual.roompark.util.extensions.scaleCenterCrop
import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration
import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.BlurTransformation
import jp.wasabeef.picasso.transformations.ColorFilterTransformation
import timber.log.Timber
import javax.inject.Inject
......@@ -127,6 +134,52 @@ class AlbumsScreenController :
)
}
try {
val urlToLoadBg =
viewState.list.first { it.albumId == viewState.selectedAlbumId }.previewUrl
Timber.d("URL TO LOAD BG $urlToLoadBg")
urlToLoadBg.let {
Picasso.get()
.load(it)
.transform(BlurTransformation(activity, 13, 2))
.transform(ColorFilterTransformation(0xCC000000.toInt()))
.into(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)
}
})
}
}
catch (e:java.lang.Exception){Timber.e(e)}
}
private fun render(viewState: AlbumsScreenViewState.AlbumsSelected){
......
package com.biganto.visual.roompark.util.extensions
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.RectF
import android.view.View
import timber.log.Timber
import java.text.DecimalFormat
/**
* Created by Vladislav Bogdashkin on 23.10.2019.
*/
......@@ -44,4 +50,45 @@ fun Float.format(fracDigits: Int): String {
fun View.setGone(isGone:Boolean){
this.visibility = if (isGone) View.GONE else View.VISIBLE
}
fun Bitmap.scaleCenterCrop(viewHolder:View): Bitmap {
Timber.d("go crpo")
val sourceWidth = this.width
val sourceHeight = this.height
// Compute the scaling factors to fit the new height and width, respectively.
// To cover the final image, the final scaling will be the bigger
// of these two.
val xScale = viewHolder.measuredWidth.toFloat() / sourceWidth
val yScale = viewHolder.measuredHeight.toFloat() / sourceHeight
val scale = xScale.coerceAtLeast(yScale)
Timber.d(" left/top $xScale/$yScale")
// Now get the size 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
val left = (viewHolder.measuredWidth - scaledWidth) / 2
val top = (viewHolder.measuredHeight - scaledHeight) / 2
Timber.d(" left/top $left/$top")
// The target rectangle for the new, scaled version of the source bitmap will now
// be
val targetRect = RectF(left, top, left + scaledWidth, top + scaledHeight)
// Finally, we create a new bitmap of the specified size and draw our new,
// scaled bitmap onto it.
val dest = Bitmap.createBitmap(viewHolder.measuredWidth, viewHolder.measuredHeight, this.config)
val canvas = Canvas(dest)
Timber.d(" targetRect $targetRect")
canvas.drawBitmap(this, null, targetRect, null)
return dest
}
\ No newline at end of file
......@@ -5,7 +5,6 @@
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorOpacityBackground"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
......
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