diff --git a/app/src/main/java/com/tangem/tap/common/leapfrogWidget/LeapView.kt b/app/src/main/java/com/tangem/tap/common/leapfrogWidget/LeapView.kt index a9d5212f3e..0c4d37a066 100644 --- a/app/src/main/java/com/tangem/tap/common/leapfrogWidget/LeapView.kt +++ b/app/src/main/java/com/tangem/tap/common/leapfrogWidget/LeapView.kt @@ -23,11 +23,14 @@ class LeapView( init { val initialProperties = createInitialProperty(position) currentProperties = AnimationProperties.from(initialProperties, initialProperties) + initView(initialProperties) + } - view.elevation = initialProperties.elevation - view.translationY = initialProperties.yTranslation - view.scaleX = initialProperties.scale - view.scaleY = initialProperties.scale + private fun initView(properties: Properties) { + view.elevation = properties.elevation + view.translationY = properties.yTranslation + view.scaleX = properties.scale + view.scaleY = properties.scale // initialProperties.hasForeground } @@ -67,6 +70,17 @@ class LeapView( updateProperties(currentProperties.toUnfold(calculator)) } + fun getState(): LeapViewState { + return LeapViewState(index, currentPosition, previousPosition, currentProperties) + } + + fun applyState(state: LeapViewState) { + previousPosition = state.previousPosition + currentPosition = state.currentPosition + updateProperties(state.properties) + initView(state.properties.endProperties()) + } + private fun updateProperties(properties: AnimationProperties) { currentProperties = properties } @@ -112,6 +126,13 @@ class LeapView( } +data class LeapViewState( + val index: Int, + val currentPosition: Int, + val previousPosition: Int, + val properties: AnimationProperties +) + enum class LeapFrogAnimation { LEAP, PULL } @@ -137,6 +158,16 @@ data class AnimationProperties( val hasForegroundEnd: Boolean, ) { + fun endProperties(): Properties { + return Properties( + positionEnd, + scaleEnd, + elevationEnd, + yTranslationEnd, + hasForegroundEnd, + ) + } + override fun toString(): String { return """ scaleStart: $scaleStart, scaleEnd: $scaleEnd, diff --git a/app/src/main/java/com/tangem/tap/common/leapfrogWidget/LeapfrogWidget.kt b/app/src/main/java/com/tangem/tap/common/leapfrogWidget/LeapfrogWidget.kt index 423be3b97b..37b04d4f2a 100644 --- a/app/src/main/java/com/tangem/tap/common/leapfrogWidget/LeapfrogWidget.kt +++ b/app/src/main/java/com/tangem/tap/common/leapfrogWidget/LeapfrogWidget.kt @@ -127,6 +127,15 @@ class LeapfrogWidget( return leapViews.firstOrNull { it.currentPosition == position }?.view } + fun getState(): LeapfrogWidgetState = LeapfrogWidgetState(isFolded, leapViews.map { it.getState() }) + + fun applyState(state: LeapfrogWidgetState) { + isFolded = state.isFolded + state.leapViewStates.forEach { state -> + leapViews.firstOrNull { it.index == state.index }?.applyState(state) + } + } + private fun viewIsFullFledged(): Boolean = parentContainer.childCount > 1 private fun canFoldUnfold(): Boolean { @@ -163,6 +172,11 @@ class LeapfrogWidget( private fun leapBackInProgress(): Boolean = leapBackProgress != 100 } +data class LeapfrogWidgetState( + val isFolded: Boolean, + val leapViewStates: List +) + class PropertyCalculator( val elevationFactor: Float = 1f, val decreaseScaleFactor: Float = 0.1f,