@@ -29,51 +29,44 @@ import androidx.lifecycle.ViewModel
2929import androidx.lifecycle.ViewModelProvider
3030import androidx.navigation.compose.NavHost
3131import androidx.navigation.compose.composable
32+ import androidx.navigation.compose.navigation
3233import androidx.navigation.compose.rememberNavController
33- import androidx.room.Room
3434import ch.skew.remotrix.classes.Account
3535import ch.skew.remotrix.classes.Destination
36+ import ch.skew.remotrix.classes.Setup
3637import ch.skew.remotrix.components.ListHeader
3738import ch.skew.remotrix.data.RemotrixDB
3839import ch.skew.remotrix.data.RemotrixSettings
39- import ch.skew.remotrix.data.accountDB.AccountEvent
40- import ch.skew.remotrix.data.accountDB.AccountEventAsync
4140import ch.skew.remotrix.data.accountDB.AccountViewModel
41+ import ch.skew.remotrix.data.forwardRuleDB.ForwardRule
42+ import ch.skew.remotrix.data.forwardRuleDB.ForwardRuleViewModel
4243import ch.skew.remotrix.data.logDB.LogData
4344import ch.skew.remotrix.data.logDB.LogViewModel
44- import ch.skew.remotrix.data.sendActionDB.SendAction
45- import ch.skew.remotrix.data.sendActionDB.SendActionEvent
46- import ch.skew.remotrix.data.sendActionDB.SendActionViewModel
45+ import ch.skew.remotrix.setup.AdditionalInfo
46+ import ch.skew.remotrix.setup.SetManagementSpace
47+ import ch.skew.remotrix.setup.SetManagerAccount
48+ import ch.skew.remotrix.setup.Welcome
4749import ch.skew.remotrix.ui.theme.RemotrixTheme
48- import kotlinx.coroutines.Deferred
4950
5051
5152class MainActivity : ComponentActivity () {
5253
53- private val db by lazy {
54- Room .databaseBuilder(
55- applicationContext,
56- RemotrixDB ::class .java,
57- " accounts.db"
58- ).build()
59- }
60-
6154 @Suppress(" UNCHECKED_CAST" )
6255 private val accountViewModel by viewModels<AccountViewModel >(
6356 factoryProducer = {
6457 object : ViewModelProvider .Factory {
6558 override fun <T : ViewModel > create (modelClass : Class <T >): T {
66- return AccountViewModel (db .accountDao) as T
59+ return AccountViewModel (RemotrixDB .getInstance(applicationContext) .accountDao) as T
6760 }
6861 }
6962 }
7063 )
7164 @Suppress(" UNCHECKED_CAST" )
72- private val sendActionViewModel by viewModels<SendActionViewModel >(
65+ private val forwardRuleViewModel by viewModels<ForwardRuleViewModel >(
7366 factoryProducer = {
7467 object : ViewModelProvider .Factory {
7568 override fun <T : ViewModel > create (modelClass : Class <T >): T {
76- return SendActionViewModel (db.sendActionDao ) as T
69+ return ForwardRuleViewModel ( RemotrixDB .getInstance(applicationContext).forwardRuleDao ) as T
7770 }
7871 }
7972 }
@@ -83,7 +76,7 @@ class MainActivity : ComponentActivity() {
8376 factoryProducer = {
8477 object : ViewModelProvider .Factory {
8578 override fun <T : ViewModel > create (modelClass : Class <T >): T {
86- return LogViewModel (db .logDao) as T
79+ return LogViewModel (RemotrixDB .getInstance(applicationContext) .logDao) as T
8780 }
8881 }
8982 }
@@ -92,13 +85,10 @@ class MainActivity : ComponentActivity() {
9285 super .onCreate(savedInstanceState)
9386 setContent {
9487 val accounts by accountViewModel.accounts.collectAsState()
95- val sendActions by sendActionViewModel.sendActions .collectAsState()
88+ val sendActions by forwardRuleViewModel.forwardRule .collectAsState()
9689 val logs by logViewModel.logs.collectAsState()
9790 RemotrixApp (
98- accountViewModel::onEvent,
99- accountViewModel::onEventAsync,
10091 Account .from(accounts),
101- sendActionViewModel::onEvent,
10292 sendActions,
10393 logs
10494 )
@@ -107,11 +97,8 @@ class MainActivity : ComponentActivity() {
10797}
10898@Composable
10999fun RemotrixApp (
110- onAccountEvent : (AccountEvent ) -> Unit ,
111- onAccountEventAsync : (AccountEventAsync ) -> Deferred <Long >,
112100 accounts : List <Account >,
113- onSendActionEvent : (SendActionEvent ) -> Unit ,
114- sendActions : List <SendAction >,
101+ forwardRules : List <ForwardRule >,
115102 logs : List <LogData >
116103) {
117104 val settings = RemotrixSettings (LocalContext .current)
@@ -137,24 +124,28 @@ fun RemotrixApp(
137124 composable(route = Destination .AccountList .route) {
138125 AccountList (
139126 accounts = accounts,
140- onAccountEvent = onAccountEvent,
141127 onClickGoBack = { navController.popBackStack() },
142128 onClickNewAccount = { navController.navigate(Destination .NewAccount .route) },
143129 )
144130 }
145131 composable(route = Destination .NewAccount .route) {
146132 NewAccount (
147- onClickGoBack = { navController.popBackStack() },
148- onAccountEvent = onAccountEvent,
149- onAccountEventAsync = onAccountEventAsync
133+ onClickGoBack = { navController.popBackStack() }
150134 )
151135 }
152- composable(route = Destination .Setup .route) {
153- SetupScreen (
154- done = { navController.navigate(Destination .Home .route) },
155- goBack = { navController.popBackStack() },
156- openedBefore = openedBefore.value!!
157- )
136+ navigation(route = Destination .Setup .route, startDestination = Setup .Welcome .route) {
137+ composable(Setup .Welcome .route){
138+ Welcome { navController.navigate(Setup .Manager .route) }
139+ }
140+ composable(Setup .Manager .route){
141+ SetManagerAccount { navController.navigate(Setup .ManagerSpace .route) }
142+ }
143+ composable(Setup .ManagerSpace .route){
144+ SetManagementSpace { navController.navigate(Setup .NextStep .route) }
145+ }
146+ composable(Setup .NextStep .route){
147+ AdditionalInfo { navController.navigate(Destination .Home .route) }
148+ }
158149 }
159150 composable(route = Destination .Settings .route) {
160151 Settings (
@@ -169,7 +160,7 @@ fun RemotrixApp(
169160 accounts = accounts,
170161 logs = logs,
171162 isEnabled = logging.value!! ,
172- goBack = { navController.popBackStack() },
163+ goBack = { navController.popBackStack() }
173164 )
174165 }
175166 }
@@ -182,7 +173,7 @@ fun HomeScreen(
182173 accounts : List <Account > = listOf(),
183174 navigate : (String ) -> Unit = {},
184175 defaultSend : Int = -1,
185- sendActions : List <SendAction > = listOf()
176+ forwardRules : List <ForwardRule > = listOf()
186177) {
187178 Scaffold (
188179 topBar = {
@@ -215,7 +206,7 @@ fun HomeScreen(
215206 },
216207 modifier = Modifier .clickable { navigate(Destination .AccountList .route) }
217208 )
218- val desc = stringResource(R .string.settings_desc) + if (sendActions .isEmpty() && defaultSend == - 1 ) stringResource(R .string.settings_desc_warning) else " "
209+ val desc = stringResource(R .string.settings_desc) + if (forwardRules .isEmpty() && defaultSend == - 1 ) stringResource(R .string.settings_desc_warning) else " "
219210 ListItem (
220211 headlineText = { Text (stringResource(R .string.settings)) },
221212 supportingText = { Text (desc) },
0 commit comments