Commit 8e88c2e9 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

bubble smooth mooving;

bubble show correct position onn startup
parent 77d333ec
......@@ -99,6 +99,8 @@ class AlbumsScreenController :
, resources?.getDimensionPixelSize(R.dimen.ceil_grid_padding))
)
bubble.setUpView(headersRecyclerView)
albumsRecyclerView.isNestedScrollingEnabled = false
......@@ -169,10 +171,11 @@ class AlbumsScreenController :
viewState.list.asSequence().sortedByDescending { it.published }.toList()
)
headersRecyclerView.let {
it.scrollToPosition(
(it.adapter as AlbumsHeaderAdapter).getItemPosition(viewState.selectedAlbumId)
)
(headersRecyclerView.adapter as AlbumsHeaderAdapter)
.getItemPosition(viewState.selectedAlbumId)
.let {
headersRecyclerView.smoothScrollToPosition(it)
bubble.onCurrentItemChanged(it)
}
viewState.list.first { it.albumId == viewState.selectedAlbumId }.let {
......@@ -185,8 +188,10 @@ class AlbumsScreenController :
private fun render(viewState: AlbumsScreenViewState.HeaderAlbumChoosed) {
(headersRecyclerView.adapter as AlbumsHeaderAdapter)
.getItemPosition(viewState.item.albumId).let {
headersRecyclerView.scrollToPosition(it)
.getItemPosition(viewState.item.albumId)
.let {
headersRecyclerView.smoothScrollToPosition(it)
bubble.onCurrentItemChanged(it)
}
currentAlbomTitle.text = viewState.item.title
......@@ -211,10 +216,11 @@ class AlbumsScreenController :
viewState.restore.albumsPreview.asSequence().sortedByDescending { it.published }.toList()
)
headersRecyclerView.let {
it.scrollToPosition(
(it.adapter as AlbumsHeaderAdapter).getItemPosition(viewState.restore.currentIndex)
)
(headersRecyclerView.adapter as AlbumsHeaderAdapter)
.getItemPosition(viewState.restore.currentIndex)
.let {
headersRecyclerView.smoothScrollToPosition(it)
bubble.onCurrentItemChanged(it)
}
viewState.restore.albumsPreview.first { it.albumId == viewState.restore.currentIndex }
......
package com.biganto.visual.roompark.presentation.screen.albums.util
import android.content.Context
import android.graphics.Rect
import android.graphics.SurfaceTexture
import android.util.AttributeSet
import android.view.TextureView
......@@ -23,24 +22,22 @@ class BubbleSlider @JvmOverloads constructor(
private var actualPosition = -1
private val actualRect = Rect()
private fun invalidatePosition(){
val child = recyclerView?.findViewHolderForAdapterPosition(actualPosition)
if (child == null) texThread?.setCenter(-9999)
else texThread?.setCenter(child.itemView.x.toInt()+child.itemView.width/ 2)
}
fun setUpView(view:RecyclerView) {
recyclerView = view
recyclerView?.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
val child = recyclerView?.getChildAt(actualPosition)
child?.getDrawingRect(actualRect)
actualRect.let {
texThread?.setCenter(it.centerX())
invalidatePosition()
}
}
}
fun onCurrentItemChanged(newPosition:Int){
actualPosition = newPosition
invalidatePosition()
texThread?.setIndex(actualPosition)
}
......
......@@ -7,6 +7,7 @@ import android.graphics.*
import android.view.Surface
import com.biganto.visual.roompark.R
import timber.log.Timber
import kotlin.math.absoluteValue
import kotlin.math.tan
......@@ -14,7 +15,7 @@ import kotlin.math.tan
* Created by Vladislav Bogdashkin on 18.07.2019.
*/
private const val CONST_SLEEP_THRESHOLD = 8L
private const val CONST_SLEEP_THRESHOLD = 6L
private const val CONST_HEIGHT_MARGIN_BORDER_PX = 8
private const val CONST_DECAY_TIMER = 500L
......@@ -37,6 +38,7 @@ class RendererThread(val context: Context, val surface: SurfaceTexture)
private var height = 0
private var centerX = 0
private var destCenterX = 0
private var holdIndex = 0
get() = if (isDragging) field
......@@ -59,15 +61,12 @@ class RendererThread(val context: Context, val surface: SurfaceTexture)
fun setCenter(centerX:Int){
this.centerX = centerX
Timber.w("CENTER IS: $centerX")
isDirty = true
}
private var scrollScaleFactor = 1f
private var touchOffset = 0f
private var scrollOffset = 0f
private var isDragging = false
private var slidePosition = 0f
private var dragKoef = 1f
fun setSlidePosition(newPosition:Float){
slidePosition = newPosition
......@@ -79,57 +78,44 @@ class RendererThread(val context: Context, val surface: SurfaceTexture)
private fun timerDecay(mills:Long){
isDirty=true
decayFraction+=mills
animateBorders()
scrollOffset = scrollOffset.smoothLerp(touchOffset-scrollOffset,.2f)
if (touchOffset> 0 && scrollOffset >= touchOffset) {
scrollOffset = touchOffset
isDirty=false
}
else if (touchOffset< 0 && scrollOffset <= touchOffset) {
scrollOffset = touchOffset
isDirty=false
}
if (decayFraction> DECAY_TIMER) isDirty=false
val dirty = animateBorders()
val dirty = centerSmooth()
if (!isDirty) isDirty = dirty
}
private fun animateBorders():Boolean{
if (isDragging && dragKoef>0){
dragKoef = dragKoef.smoothLerp(-dragKoef,.12f)
if (dragKoef<.1f) dragKoef = 0f
return dragKoef>0
}
if (!isDragging && dragKoef<1f) {
dragKoef = dragKoef.smoothLerp(1f-dragKoef,.03f)
if (dragKoef>.99f) dragKoef = 1f
return dragKoef<1f
}
return false
private fun centerSmooth():Boolean{
centerX = centerX.smoothLerp(destCenterX-centerX,decayFraction/DECAY_TIMER)
Timber.w("CENTER visa verse: $centerX -> $destCenterX")
return (centerX - destCenterX).absoluteValue>1
}
private fun Float.smoothLerp( delta: Float, fraction:Float =.4f): Float {
return this + fraction * (delta)
}
private fun Int.smoothLerp( delta: Int, fraction:Float =.4f): Int {
return (this + fraction * (delta)).int
}
fun setSize(w: Int, h: Int){
width=w
height=h
}
private val pinColor:Int by lazy {
return@lazy context.resources.getColor(R.color.colorOpacityBackground)
context.resources.getColor(R.color.colorOpacityBackground,context.theme)
}
private val trianglePath:Path
get() {
val p = Path()
p.fillType = Path.FillType.EVEN_ODD
p.moveTo(centerX.toFloat(),height.toFloat())
p.lineTo(centerX.toFloat() + height*tan(Math.toRadians(60.0)).toFloat(),height.toFloat())
p.lineTo(centerX.toFloat() - height*tan(Math.toRadians(60.0)).toFloat(),height.toFloat())
p.lineTo(centerX.toFloat(),height.toFloat())
p.moveTo(centerX.toFloat(),0f)
p.lineTo(centerX.toFloat() + height*tan(Math.toRadians(45.0)).toFloat(),height.toFloat())
p.lineTo(centerX.toFloat() - height*tan(Math.toRadians(45.0)).toFloat(),height.toFloat())
p.lineTo(centerX.toFloat(),0f)
p.close()
return p
}
......@@ -161,11 +147,10 @@ class RendererThread(val context: Context, val surface: SurfaceTexture)
, height
)
val c = surf.lockCanvas(dRect)
c.drawColor(Color.TRANSPARENT)
c.drawColor(Color.WHITE)
c.drawPath(trianglePath,trianglePaint)
timerDecay(SLEEP_THRESHOLD)
// c.drawRect(Rect(centerX - 30,height,centerX+30,0),trianglePaint)
// timerDecay(SLEEP_THRESHOLD)
surf.unlockCanvasAndPost(c)
surf.release()
......
......@@ -75,7 +75,7 @@
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@drawable/iic_full_view"/>
<com.biganto.visual.roompark.presentation.screen.albums.util.PhotoPreviewSlider
<com.biganto.visual.roompark.presentation.screen.photo.util.PhotoPreviewSlider
android:id="@+id/photosPreviewSlider"
android:layout_width="0dp"
android:layout_height="48dp"
......
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