1
1
package com.bff.wespot.entire.screen.screen.setting
2
2
3
3
import androidx.compose.foundation.layout.Arrangement
4
+ import androidx.compose.foundation.layout.Box
4
5
import androidx.compose.foundation.layout.Column
5
6
import androidx.compose.foundation.layout.Row
6
7
import androidx.compose.foundation.layout.fillMaxSize
7
8
import androidx.compose.foundation.layout.padding
9
+ import androidx.compose.material3.CircularProgressIndicator
8
10
import androidx.compose.material3.ExperimentalMaterial3Api
9
11
import androidx.compose.material3.Scaffold
10
12
import androidx.compose.material3.Text
11
13
import androidx.compose.runtime.Composable
14
+ import androidx.compose.runtime.LaunchedEffect
15
+ import androidx.compose.runtime.getValue
12
16
import androidx.compose.ui.Alignment
13
17
import androidx.compose.ui.Modifier
14
18
import androidx.compose.ui.res.stringResource
15
19
import androidx.compose.ui.unit.dp
20
+ import androidx.hilt.navigation.compose.hiltViewModel
21
+ import androidx.lifecycle.Lifecycle
16
22
import com.bff.wespot.designsystem.component.header.WSTopBar
17
23
import com.bff.wespot.designsystem.component.toggle.WSSwitch
18
24
import com.bff.wespot.designsystem.theme.Gray400
19
25
import com.bff.wespot.designsystem.theme.StaticTypeScale
20
26
import com.bff.wespot.designsystem.theme.WeSpotThemeManager
21
27
import com.bff.wespot.entire.R
28
+ import com.bff.wespot.entire.screen.state.notification.NotificationSettingAction
29
+ import com.bff.wespot.entire.viewmodel.NotificationSettingViewModel
30
+ import com.bff.wespot.util.OnLifecycleEvent
22
31
import com.ramcosta.composedestinations.annotation.Destination
32
+ import org.orbitmvi.orbit.compose.collectAsState
23
33
24
34
interface NotificationSettingNavigator {
25
35
fun navigateUp ()
@@ -30,7 +40,18 @@ interface NotificationSettingNavigator {
30
40
@Destination
31
41
fun NotificationSettingScreen (
32
42
navigator : NotificationSettingNavigator ,
43
+ viewModel : NotificationSettingViewModel = hiltViewModel(),
33
44
) {
45
+ val action = viewModel::onAction
46
+ val state by viewModel.collectAsState()
47
+
48
+ if (state.isLoading) {
49
+ Box (modifier = Modifier .fillMaxSize(), contentAlignment = Alignment .Center ) {
50
+ CircularProgressIndicator ()
51
+ }
52
+ return
53
+ }
54
+
34
55
Scaffold (
35
56
topBar = {
36
57
WSTopBar (
@@ -50,33 +71,52 @@ fun NotificationSettingScreen(
50
71
NotificationSettingItem (
51
72
title = stringResource(R .string.vote),
52
73
subTitle = stringResource(R .string.vote_notification_title),
53
- switchValue = true ,
54
- onToggled = { },
74
+ switchValue = state.isEnableVoteNotification,
75
+ onSwitched = {
76
+ action(NotificationSettingAction .OnVoteNotificationSwitched )
77
+ },
55
78
)
56
79
57
80
NotificationSettingItem (
58
81
title = stringResource(R .string.message),
59
82
subTitle = stringResource(R .string.message_notification_title),
60
- switchValue = true ,
61
- onToggled = { },
83
+ switchValue = state.isEnableMessageNotification,
84
+ onSwitched = {
85
+ action(NotificationSettingAction .OnMessageNotificationSwitched )
86
+ },
62
87
)
63
88
64
89
NotificationSettingItem (
65
90
title = stringResource(R .string.event_benefit),
66
91
subTitle = stringResource(R .string.event_benefit_notification_title),
67
- switchValue = false ,
68
- onToggled = { },
92
+ switchValue = state.isEnableMarketingNotification,
93
+ onSwitched = {
94
+ action(NotificationSettingAction .OnEventNotificationSwitched )
95
+ },
69
96
)
70
97
}
71
98
}
99
+
100
+ OnLifecycleEvent { _, event ->
101
+ when (event) {
102
+ Lifecycle .Event .ON_PAUSE -> {
103
+ action(NotificationSettingAction .OnNotificationSettingScreenExited )
104
+ }
105
+ else -> { }
106
+ }
107
+ }
108
+
109
+ LaunchedEffect (Unit ) {
110
+ action(NotificationSettingAction .OnNotificationSettingScreenEntered )
111
+ }
72
112
}
73
113
74
114
@Composable
75
115
fun NotificationSettingItem (
76
116
title : String ,
77
117
subTitle : String ,
78
118
switchValue : Boolean ,
79
- onToggled : (Boolean ) -> Unit ,
119
+ onSwitched : (Boolean ) -> Unit ,
80
120
) {
81
121
Row (
82
122
verticalAlignment = Alignment .CenterVertically ,
@@ -101,7 +141,7 @@ fun NotificationSettingItem(
101
141
102
142
WSSwitch (
103
143
checked = switchValue,
104
- onCheckedChange = onToggled ,
144
+ onCheckedChange = onSwitched ,
105
145
)
106
146
}
107
147
}
0 commit comments