TP-37302 add support for restart in count down timer (#148)

This commit is contained in:
Hitesh Kumar
2023-08-08 14:48:26 +05:30
committed by GitHub
parent dd303bfbe2
commit a2f9249b92
6 changed files with 231 additions and 9 deletions

View File

@@ -2553,6 +2553,203 @@
}
}
},
"restartTimerMock": {
"view": [
{
"property": {
"viewType": "Row",
"arrangementData": {
"arrangementType": "Start"
},
"layoutId": "resend_otp_container",
"width": "WRAP_CONTENT",
"height": "WRAP_CONTENT"
},
"childrenViews": [
{
"property": {
"fontFamily": "ttComposeFontFamily",
"fontWeight": "TT_MEDIUM",
"fontSize": 12,
"textColor": "#444444",
"viewType": "Text",
"layoutId": "resend_otp_in_text",
"width": "WRAP_CONTENT",
"height": "WRAP_CONTENT",
"isStateFul": true,
"statesMap": {
"visible": {
"viewType": "Row",
"visible": true
},
"invisible": {
"viewType": "Row",
"visible": false
}
}
}
},
{
"property": {
"viewType": "CountDownTimer",
"layoutId": "count_down_timer",
"width": "WRAP_CONTENT",
"isStateFul": true,
"statesMap": {
"restart": {
"viewType": "CountDownTimer",
"restartTimer": true
},
"disableRestartTimer": {
"viewType": "CountDownTimer",
"restartTimer": false
}
}
},
"childrenViews": [
{
"property": {
"viewType": "Row",
"layoutId": "count_down_timer_row",
"width": "WRAP_CONTENT",
"height": "WRAP_CONTENT",
"arrangementData": {
"arrangementType": "Start"
},
"isStateFul": true,
"statesMap": {
"visible": {
"viewType": "Row",
"visible": true
},
"invisible": {
"viewType": "Row",
"visible": false
}
}
},
"childrenViews": [
{
"property": {
"fontFamily": "ttComposeFontFamily",
"fontWeight": "TT_MEDIUM",
"fontSize": 12,
"textColor": "#1F002A",
"viewType": "Text",
"layoutId": "minutes_timer_text",
"width": "WRAP_CONTENT",
"height": "WRAP_CONTENT",
"isStateFul": true,
"isDataMutable": true
}
},
{
"property": {
"fontFamily": "ttComposeFontFamily",
"fontWeight": "TT_MEDIUM",
"fontSize": 12,
"textColor": "#1F002A",
"viewType": "Text",
"layoutId": "colon_text",
"width": "WRAP_CONTENT",
"height": "WRAP_CONTENT"
}
},
{
"property": {
"fontFamily": "ttComposeFontFamily",
"fontWeight": "TT_MEDIUM",
"fontSize": 12,
"textColor": "#1F002A",
"viewType": "Text",
"layoutId": "seconds_timer_text",
"width": "WRAP_CONTENT",
"height": "WRAP_CONTENT",
"isStateFul": true,
"isDataMutable": true
}
}
]
}
]
},
{
"property": {
"fontFamily": "ttComposeFontFamily",
"fontWeight": "TT_MEDIUM",
"fontSize": 12,
"textColor": "#1F002A",
"viewType": "Text",
"layoutId": "timer_finish_text",
"textDecoration": "Underline",
"width": "WRAP_CONTENT",
"height": "WRAP_CONTENT",
"isStateFul": true,
"visible": false,
"statesMap": {
"visible": {
"viewType": "Text",
"visible": true
},
"invisible": {
"viewType": "Text",
"visible": false
}
}
}
}
]
}
],
"data": {
"colon_text": {
"text": ":",
"viewType": "Text"
},
"timer_finish_text": {
"text": "Resend OTP",
"viewType": "Text",
"onClick": {
"actions": [
{
"viewStates": {
"count_down_timer_row": "visible",
"resend_otp_in_text": "visible",
"timer_finish_text": "invisible",
"count_down_timer": "restart"
},
"type": "UpdateViewState"
}
]
}
},
"resend_otp_in_text": {
"text": "Resend OTP in ",
"viewType": "Text"
},
"count_down_timer": {
"remainingTimeInMilliseconds": 5000,
"countDownIntervalInMilliseconds": 1000,
"timeUnitValuesLayoutIds": {
"secondsFieldLayoutId": "seconds_timer_text",
"minutesFieldLayoutId": "minutes_timer_text"
},
"viewType": "CountDownTimer",
"onClick": {
"actions": [
{
"viewStates": {
"count_down_timer_row": "invisible",
"resend_otp_in_text": "invisible",
"timer_finish_text": "visible"
},
"type": "UpdateViewState"
}
]
}
}
}
},
"cardShadowTemplate": {
"parentComposeView": [
{

View File

@@ -7,11 +7,20 @@
package com.navi.uitron.model.data
class CountDownTimerData(
val remainingTimeInMilliseconds: Long? = null,
val countDownIntervalInMilliseconds: Long? = null,
val timeUnitValuesLayoutIds: TimeUnitValuesLayoutIds? = null
) : UiTronData()
data class CountDownTimerData(
var remainingTimeInMilliseconds: Long? = null,
var countDownIntervalInMilliseconds: Long? = null,
var timeUnitValuesLayoutIds: TimeUnitValuesLayoutIds? = null
) : UiTronData() {
fun copyNonNull(data: CountDownTimerData?): CountDownTimerData {
remainingTimeInMilliseconds =
data?.remainingTimeInMilliseconds ?: remainingTimeInMilliseconds
countDownIntervalInMilliseconds =
data?.countDownIntervalInMilliseconds ?: countDownIntervalInMilliseconds
timeUnitValuesLayoutIds = data?.timeUnitValuesLayoutIds ?: timeUnitValuesLayoutIds
return this
}
}
data class TimeUnitValuesLayoutIds(
val milliSecondsFieldLayoutId: String? = null,

View File

@@ -7,4 +7,12 @@
package com.navi.uitron.model.ui
class CountDownTimerProperty : BaseProperty()
data class CountDownTimerProperty(
var restartTimer: Boolean? = null
) : BaseProperty() {
override fun copyNonNullFrom(property: BaseProperty?) {
super.copyNonNullFrom(property)
val countDownTimerProperty = property as? CountDownTimerProperty
countDownTimerProperty?.restartTimer?.let { restartTimer = it }
}
}

View File

@@ -15,6 +15,7 @@ import com.navi.uitron.model.data.CountDownTimerData
import com.navi.uitron.model.data.UiTronData
import com.navi.uitron.model.ui.CountDownTimerProperty
import com.navi.uitron.model.ui.UiTronView
import com.navi.uitron.utils.DISABLE_RESTART_TIMER
import com.navi.uitron.viewmodel.UiTronViewModel
import orFalse
import orTrue
@@ -45,16 +46,19 @@ class CountDownTimerRenderer(
property.getDataId(),
null
).collectAsState()
countDownTimerData = updatedDataState.value ?: countDownTimerData
countDownTimerData =
countDownTimerData?.copyNonNull(updatedDataState.value) ?: updatedDataState.value
}
if (property.visible.orTrue()) {
LaunchedEffect(Unit) {
LaunchedEffect(property.restartTimer) {
uiTronViewModel.countDownTimerHelper.startCountDownTimer(
countDownTimerData,
property,
uiTronViewModel,
layoutId = property.layoutId.orEmpty()
)
uiTronViewModel.handle[property.getPropertyId()] = DISABLE_RESTART_TIMER
}
uiTronRenderer.Render(composeViews = childrenComposeViews)
}

View File

@@ -6,6 +6,7 @@ const val SPACE = " "
const val DEFAULT_FORMAT_PATTERN = "ddMMyyyy"
const val PACKAGE_COLON = "package:"
const val STOP = "stop"
const val DISABLE_RESTART_TIMER = "disableRestartTimer"
const val KEY_MVEL_ACTION = "mvelAction"
const val KEY_UI_TRON_DATA = "uiTronData"

View File

@@ -3,8 +3,10 @@ package com.navi.uitron.viewmodel
import android.os.CountDownTimer
import com.navi.uitron.model.data.CountDownTimerData
import com.navi.uitron.model.data.TextData
import com.navi.uitron.model.ui.CountDownTimerProperty
import formatDuration
import getDataId
import orFalse
import orZero
import javax.inject.Inject
@@ -18,10 +20,11 @@ constructor() {
fun startCountDownTimer(
countDownTimerData: CountDownTimerData?,
property: CountDownTimerProperty,
uiTronViewModel: UiTronViewModel,
layoutId: String
): CountDownTimer? {
if (mapOfCountDownTimers.containsKey(layoutId)) {
if (mapOfCountDownTimers.containsKey(layoutId) && property.restartTimer.orFalse().not()) {
return mapOfCountDownTimers[layoutId]
} else {
val countDownTimer = object : CountDownTimer(