diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/lessons/lesson_16/Lesson_16.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/lessons/lesson_16/Lesson_16.kt new file mode 100644 index 00000000..173d53df --- /dev/null +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/lessons/lesson_16/Lesson_16.kt @@ -0,0 +1,129 @@ +package com.example.jetpack_compose_all_in_one.lessons.lesson_16 + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.Card +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp + +@Composable +@Preview(showBackground = true) +fun Lesson_16() { + var t1 by rememberSaveable { mutableStateOf("T1") } + var t2 by rememberSaveable { mutableStateOf("T2") } + var t3 by rememberSaveable { mutableStateOf("T3") } + var visible by rememberSaveable { mutableStateOf(true) } + Column( + Modifier + .fillMaxSize() + .height(300.dp) + ) { + Column( + modifier = Modifier + .fillMaxWidth() + .background(Color.Cyan) + .padding(10.dp) + ) { + Card( + modifier = Modifier + .fillMaxWidth() + .padding(10.dp) + .height(80.dp) + ) { + Box(Modifier.fillMaxSize()) { + if (visible) { + Text( + text = t1, + modifier = Modifier.align(Alignment.Center), + style = TextStyle(fontWeight = FontWeight.Bold, fontSize = 30.sp), + ) + } + } + } + Card( + modifier = Modifier + .fillMaxWidth() + .padding(10.dp) + .height(80.dp) + ) { + Box(Modifier.fillMaxSize()) { + if (visible) { + Text( + text = t2, + modifier = Modifier.align(Alignment.Center), + style = TextStyle(fontWeight = FontWeight.Bold, fontSize = 30.sp) + ) + } + } + } + Card( + modifier = Modifier + .fillMaxWidth() + .padding(10.dp) + .height(80.dp) + ) { + Box(Modifier.fillMaxSize()) { + if (visible) { + Text( + text = t3, + modifier = Modifier.align(Alignment.Center), + style = TextStyle(fontWeight = FontWeight.Bold, fontSize = 30.sp) + ) + } + } + } + } + + Spacer(modifier = Modifier.height(30.dp)) + + Box( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp) + ) { + Button(onClick = { t1 = "Text 1" }, Modifier.align(Alignment.TopStart)) { + Text(text = "button 1") + } + Button(onClick = { t2 = "Text 2" }, Modifier.align(Alignment.TopCenter)) { + Text(text = "button 2") + } + Button(onClick = { t3 = "Text 3" }, Modifier.align(Alignment.TopEnd)) { + Text(text = "button 3") + } + } + + Spacer(modifier = Modifier.height(30.dp)) + + Box( + modifier = Modifier + .fillMaxWidth() + .padding(32.dp) + ) { + Button(onClick = { visible = false }, Modifier.align(Alignment.TopStart)) { + Text(text = "Hide") + } + Button(onClick = { visible = true }, Modifier.align(Alignment.TopEnd)) { + Text(text = "Show") + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/ui/components/MainContainerOfApp.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/ui/components/MainContainerOfApp.kt index 144c8530..5bfe0983 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/ui/components/MainContainerOfApp.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/ui/components/MainContainerOfApp.kt @@ -68,6 +68,7 @@ import com.example.jetpack_compose_all_in_one.lessons.lesson_12.Lesson_12 import com.example.jetpack_compose_all_in_one.lessons.lesson_13.Lesson_13 import com.example.jetpack_compose_all_in_one.lessons.lesson_14.Lesson_14 import com.example.jetpack_compose_all_in_one.lessons.lesson_15.Lesson_15 +import com.example.jetpack_compose_all_in_one.lessons.lesson_16.Lesson_16 import com.example.jetpack_compose_all_in_one.lessons.lesson_2.Lesson_2_Chapter_2_Screen import com.example.jetpack_compose_all_in_one.lessons.lesson_2.Lesson_2_Chapter_4_Image import com.example.jetpack_compose_all_in_one.lessons.lesson_2.Lesson_2_Chapter_5_Progressbar @@ -396,6 +397,10 @@ fun MainContainerOfApp( Lesson_15() } + composable(NavDes.Lesson16.route()){ + Lesson_16() + } + composable(NavDes.L6Chapter1.route()) { Lesson_6_ThemeChange() } diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/utils/navigation/NavConstants.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/utils/navigation/NavConstants.kt index d3862782..f8c1c408 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/utils/navigation/NavConstants.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/utils/navigation/NavConstants.kt @@ -125,6 +125,9 @@ object NavConstants { const val LESSON_15 = "LESSON_15" const val LESSON_15_ABOUT = "Lesson 15: Custom Radio Buttons" + const val LESSON_16 = "LESSON_16" + const val LESSON_16_ABOUT = "Lesson 16: State and Visibility" + const val QUOTE_2 = "quote2" const val QUOTE_2_ABOUT = "Swipe Quotes" diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/utils/navigation/NavDes.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/utils/navigation/NavDes.kt index 4901567d..e8220349 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/utils/navigation/NavDes.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/utils/navigation/NavDes.kt @@ -69,6 +69,8 @@ import com.example.jetpack_compose_all_in_one.utils.navigation.NavConstants.LESS import com.example.jetpack_compose_all_in_one.utils.navigation.NavConstants.LESSON_14_DROP_DOWN_MENU_ABOUT import com.example.jetpack_compose_all_in_one.utils.navigation.NavConstants.LESSON_15 import com.example.jetpack_compose_all_in_one.utils.navigation.NavConstants.LESSON_15_ABOUT +import com.example.jetpack_compose_all_in_one.utils.navigation.NavConstants.LESSON_16 +import com.example.jetpack_compose_all_in_one.utils.navigation.NavConstants.LESSON_16_ABOUT import com.example.jetpack_compose_all_in_one.utils.navigation.NavConstants.LESSON_1_ABOUT import com.example.jetpack_compose_all_in_one.utils.navigation.NavConstants.LESSON_2_CHAPTER_1 import com.example.jetpack_compose_all_in_one.utils.navigation.NavConstants.LESSON_2_CHAPTER_1_ABOUT @@ -274,6 +276,9 @@ sealed class NavDes(val data: INavigationDrawerItem, val customAppBarStringId: I object Lesson15 : NavDes(NavigationDrawerData(LESSON_15, LESSON_15_ABOUT)) + object Lesson16 : + NavDes(NavigationDrawerData(LESSON_16, LESSON_16_ABOUT)) + object Lesson14DropDownMenu : NavDes(NavigationDrawerData(LESSON_14_DROP_DOWN_MENU, LESSON_14_DROP_DOWN_MENU_ABOUT)) @@ -470,7 +475,8 @@ sealed class NavDes(val data: INavigationDrawerItem, val customAppBarStringId: I Lesson12WebView, Lesson13Localization, Lesson14DropDownMenu, - Lesson15 + Lesson15, + Lesson16 ), LESSONS ) )