@@ -35,32 +35,72 @@ import one.mixin.android.Constants
3535import one.mixin.android.R
3636import one.mixin.android.compose.theme.MixinAppTheme
3737import one.mixin.android.extension.openUrl
38+ import one.mixin.android.extension.toast
3839import one.mixin.android.ui.landing.SetupPinViewModel
3940import one.mixin.android.ui.landing.vo.SetupState
41+ import one.mixin.android.ui.tip.LegacyPIN
42+ import one.mixin.android.ui.tip.Processing
43+ import one.mixin.android.ui.tip.RetryConnect
44+ import one.mixin.android.ui.tip.RetryProcess
45+ import one.mixin.android.ui.tip.RetryRegister
46+ import one.mixin.android.ui.tip.TryConnecting
4047
4148@Composable
4249fun SetPinLoadingPage (
43- pin : String ,
50+ pin : String ,
4451 next : () -> Unit ,
45- onError : ((String ) -> Unit )? = null
4652) {
4753 val viewModel = hiltViewModel<SetupPinViewModel >()
4854 val coroutineScope = rememberCoroutineScope()
4955 val setupState by viewModel.setupState.observeAsState(SetupState .Loading )
56+ val tipStep by viewModel.tipStep.observeAsState(TryConnecting )
57+ val errorMessage by viewModel.errorMessage.observeAsState(" " )
5058 val context = LocalContext .current
51-
59+
5260 LaunchedEffect (pin) {
5361 if (pin.isNotBlank()) {
5462 viewModel.executeCreatePin(context, pin)
5563 }
5664 }
57-
65+
5866 LaunchedEffect (setupState) {
5967 if (setupState == SetupState .Success ) {
6068 next()
6169 }
6270 }
63-
71+
72+ val statusMessage =
73+ when (val step = tipStep) {
74+ TryConnecting -> stringResource(R .string.Trying_connect_tip_network )
75+ Processing .Creating -> stringResource(R .string.Trying_connect_tip_node )
76+ is Processing .SyncingNode -> {
77+ val percent = if (step.total > 0 ) {
78+ ((step.step * 100f ) / step.total.toFloat()).toInt().coerceIn(0 , 100 )
79+ } else {
80+ 0
81+ }
82+ stringResource(R .string.Exchanging_data , percent.toString())
83+ }
84+ Processing .Updating -> stringResource(R .string.Generating_keys )
85+ Processing .Registering -> stringResource(R .string.Registering )
86+ is RetryConnect -> buildString {
87+ if (step.reason.isNotBlank()) {
88+ append(step.reason)
89+ append(' \n ' )
90+ }
91+ append(stringResource(R .string.Connect_to_TIP_network_failed ))
92+ }
93+ is RetryProcess -> step.reason
94+ is RetryRegister -> step.reason
95+ is LegacyPIN -> step.message
96+ else -> stringResource(R .string.Set_up_pin_error_message )
97+ }
98+ val statusColor =
99+ when (tipStep) {
100+ is RetryConnect , is RetryProcess , is RetryRegister , is LegacyPIN -> MixinAppTheme .colors.red
101+ else -> MixinAppTheme .colors.textAssist
102+ }
103+
64104 PageScaffold (
65105 title = " " ,
66106 verticalScrollable = false ,
@@ -104,8 +144,8 @@ fun SetPinLoadingPage(
104144 )
105145 Spacer (modifier = Modifier .height(16 .dp))
106146 Text (
107- text = stringResource( R .string. Trying_connect_tip_node ) ,
108- color = MixinAppTheme .colors.textAssist ,
147+ text = statusMessage ,
148+ color = statusColor ,
109149 textAlign = TextAlign .Center
110150 )
111151 }
@@ -137,8 +177,8 @@ fun SetPinLoadingPage(
137177 }
138178 Spacer (modifier = Modifier .height(16 .dp))
139179 Text (
140- text = stringResource( R .string. Set_up_pin_error_message ) ,
141- color = MixinAppTheme .colors.red ,
180+ text = statusMessage ,
181+ color = statusColor ,
142182 fontSize = 14 .sp,
143183 textAlign = TextAlign .Center ,
144184 modifier = Modifier .padding(horizontal = 16 .dp)
@@ -152,4 +192,4 @@ fun SetPinLoadingPage(
152192 Spacer (modifier = Modifier .height(30 .dp))
153193 }
154194 }
155- }
195+ }
0 commit comments