Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
2.8 kB
2
Indexable
Never
data class Note(
    val id: String = UUID.randomUUID().toString(),
    var title: String,
    var desc: String,
    var isChecked: MutableState<Boolean> = mutableStateOf(false)
)

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val list = remember {
                mutableStateListOf<Note>()
            }
            val navController = rememberNavController()
            NotesTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    NavHost(navController = navController, startDestination = Screen.Overview.route) {
                        composable(route = Screen.Overview.route) {
                            Overview(navController = navController, list = list)
                        }
                        composable(route = Screen.MainScreen.route) {
                            TextInputView(navController, list)
                        } 
                        
                        composable(
                            route = Screen.DetailScreen.route + "/{id}",
                            arguments = listOf(
                                navArgument("id") {
                                    type = NavType.StringType
                                    nullable = false
                                }
                            )
                        ) {entry ->
                            val id = entry.arguments?.getString("id")
                            val note: Note? = list.find { it.id == id }
                            if(note != null)
                                DetailScreen(navController,note)
                        }
                        composable(
                            route = Screen.EditScreen.route + "/{id}",
                            arguments = listOf(
                                navArgument("id")
                                {
                                    type = NavType.StringType
                                    nullable = false
                                }
                            )
                        )
                        {entry ->
                            val id = entry.arguments?.getString("id")
                            val note: Note? = list.find { it.id == id }
                            if(note != null)
                                Edit(navController, list, note)
                        }
                    }
                }
            }

            }
        }
    }