Skip to content

Commit

Permalink
Show statin alert with animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Sep 13, 2024
1 parent 111c1ee commit 37aa2d4
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions app/src/main/java/org/simple/clinic/summary/PatientSummaryScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -730,40 +730,7 @@ class PatientSummaryScreen :
}

override fun showClinicalDecisionSupportAlert() {
clinicalDecisionSupportAlertView.translationY = clinicalDecisionSupportAlertView.height.unaryMinus().toFloat()

val spring = clinicalDecisionSupportAlertView.spring(DynamicAnimation.TRANSLATION_Y)

val transition = AutoTransition().apply {
excludeChildren(clinicalDecisionSupportAlertView, true)
excludeTarget(R.id.newBPItemContainer, true)
excludeTarget(R.id.bloodSugarItemContainer, true)
excludeTarget(R.id.drugsSummaryContainer, true)
// We are doing this to wait for the router transitions to be done before we start this.
startDelay = 500
}
val transitionListener = object : Transition.TransitionListener {
override fun onTransitionStart(transition: Transition) {
}

override fun onTransitionEnd(transition: Transition) {
transition.removeListener(this)
spring.animateToFinalPosition(0f)
}

override fun onTransitionCancel(transition: Transition) {
}

override fun onTransitionPause(transition: Transition) {
}

override fun onTransitionResume(transition: Transition) {
}
}
transition.addListener(transitionListener)
TransitionManager.beginDelayedTransition(summaryViewsContainer, transition)

clinicalDecisionSupportAlertView.visibility = VISIBLE
showWithAnimation(clinicalDecisionSupportAlertView)
}

override fun hideClinicalDecisionSupportAlert() {
Expand Down Expand Up @@ -819,8 +786,7 @@ class PatientSummaryScreen :

append(".")
}

statinAlertView.visibility = VISIBLE
showWithAnimation(statinAlertView)
}

private fun getCVDString(hasDiabetes: Boolean): String {
Expand All @@ -831,6 +797,43 @@ class PatientSummaryScreen :
}
}

private fun showWithAnimation(view: View) {
view.translationY = view.height.unaryMinus().toFloat()

val spring = view.spring(DynamicAnimation.TRANSLATION_Y)

val transition = AutoTransition().apply {
excludeChildren(view, true)
excludeTarget(R.id.newBPItemContainer, true)
excludeTarget(R.id.bloodSugarItemContainer, true)
excludeTarget(R.id.drugsSummaryContainer, true)
// We are doing this to wait for the router transitions to be done before we start this.
startDelay = 500
}
val transitionListener = object : Transition.TransitionListener {
override fun onTransitionStart(transition: Transition) {
}

override fun onTransitionEnd(transition: Transition) {
transition.removeListener(this)
spring.animateToFinalPosition(0f)
}

override fun onTransitionCancel(transition: Transition) {
}

override fun onTransitionPause(transition: Transition) {
}

override fun onTransitionResume(transition: Transition) {
}
}
transition.addListener(transitionListener)
TransitionManager.beginDelayedTransition(summaryViewsContainer, transition)

view.visibility = VISIBLE
}

override fun hideStatinAlert() {
statinAlertView.visibility = GONE
}
Expand Down

0 comments on commit 37aa2d4

Please sign in to comment.