@@ -14,6 +14,7 @@ import com.opentasker.core.model.Task
1414import com.opentasker.core.storage.toEntity
1515import com.opentasker.ui.screens.ActionEditorScreen
1616import com.opentasker.ui.screens.ActionPickerScreen
17+ import com.opentasker.ui.screens.ContextPickerScreen
1718import com.opentasker.ui.screens.ProfileEditorScreen
1819import com.opentasker.ui.screens.ProfileListScreen
1920import com.opentasker.ui.screens.TaskEditorScreen
@@ -29,6 +30,7 @@ class MainActivity : ComponentActivity() {
2930 OpenTaskerTheme {
3031 var currentScreen by remember { mutableStateOf<Screen >(Screen .ProfileList ) }
3132 var currentEditingTask by remember { mutableStateOf<Task ?>(null ) }
33+ var currentEditingProfile by remember { mutableStateOf<Profile ?>(null ) }
3234 val scope = rememberCoroutineScope()
3335
3436 when (val screen = currentScreen) {
@@ -45,19 +47,25 @@ class MainActivity : ComponentActivity() {
4547 )
4648 }
4749 is Screen .ProfileEditor -> {
50+ if (currentEditingProfile == null ) currentEditingProfile = screen.profile
4851 ProfileEditorScreen (
49- profile = screen.profile ,
52+ profile = currentEditingProfile ,
5053 onSave = { profile ->
5154 scope.launch {
5255 if (profile.id == 0L ) {
5356 db.profileDao().insert(profile.toEntity())
5457 } else {
5558 db.profileDao().update(profile.toEntity())
5659 }
60+ currentEditingProfile = null
5761 currentScreen = Screen .ProfileList
5862 }
5963 },
60- onBack = { currentScreen = Screen .ProfileList },
64+ onBack = {
65+ currentEditingProfile = null
66+ currentScreen = Screen .ProfileList
67+ },
68+ onAddContext = { currentScreen = Screen .ContextPicker },
6169 )
6270 }
6371 is Screen .TaskEditor -> {
@@ -107,6 +115,19 @@ class MainActivity : ComponentActivity() {
107115 onCancel = { currentScreen = Screen .ActionPicker },
108116 )
109117 }
118+ is Screen .ContextPicker -> {
119+ ContextPickerScreen (
120+ onContextSelected = { context ->
121+ if (currentEditingProfile != null ) {
122+ currentEditingProfile = currentEditingProfile!! .copy(
123+ contexts = currentEditingProfile!! .contexts + context
124+ )
125+ }
126+ currentScreen = Screen .ProfileEditor (currentEditingProfile)
127+ },
128+ onCancel = { currentScreen = Screen .ProfileEditor (currentEditingProfile) },
129+ )
130+ }
110131 }
111132 }
112133 }
@@ -119,4 +140,5 @@ sealed class Screen {
119140 data class TaskEditor (val task : Task ? ) : Screen()
120141 data object ActionPicker : Screen ()
121142 data class ActionEditor (val actionSpec : com.opentasker.core.model.ActionSpec ) : Screen()
143+ data object ContextPicker : Screen ()
122144}
0 commit comments