Преглед изворни кода

create LoadProgram and AuthorizationAndLogin + Navigathion

CoolVery пре 2 месеци
родитељ
комит
9006afe8ac

+ 1 - 0
.idea/gradle.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
+  <component name="GradleMigrationSettings" migrationVersion="1" />
   <component name="GradleSettings">
     <option name="linkedExternalProjectsSettings">
       <GradleProjectSettings>

+ 3 - 0
app/build.gradle.kts

@@ -59,6 +59,9 @@ dependencies {
     implementation(libs.androidx.ui.graphics)
     implementation(libs.androidx.ui.tooling.preview)
     implementation(libs.androidx.material3)
+    implementation(libs.androidx.navigation.runtime.ktx)
+    implementation(libs.androidx.work.runtime.ktx)
+    implementation(libs.androidx.navigation.compose)
     testImplementation(libs.junit)
     androidTestImplementation(libs.androidx.junit)
     androidTestImplementation(libs.androidx.espresso.core)

+ 11 - 1
app/src/main/java/com/example/collectionofshortstories/MainActivity.kt

@@ -6,11 +6,14 @@ import androidx.activity.compose.setContent
 import androidx.activity.enableEdgeToEdge
 import androidx.compose.foundation.layout.fillMaxSize
 import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.Scaffold
+import androidx.compose.material3.Surface
 import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.tooling.preview.Preview
+import com.example.collectionofshortstories.navigation.Navigathion
 import com.example.collectionofshortstories.ui.theme.CollectionOfShortStoriesTheme
 
 class MainActivity : ComponentActivity() {
@@ -18,7 +21,14 @@ class MainActivity : ComponentActivity() {
         super.onCreate(savedInstanceState)
         enableEdgeToEdge()
         setContent {
-
+            CollectionOfShortStoriesTheme {
+                Surface (
+                    modifier = Modifier.fillMaxSize(),
+                    color = MaterialTheme.colorScheme.background
+                ) {
+                    Navigathion()
+                }
+            }
         }
     }
 }

+ 25 - 0
app/src/main/java/com/example/collectionofshortstories/navigation/navigation.kt

@@ -0,0 +1,25 @@
+package com.example.collectionofshortstories.navigation
+
+import androidx.compose.runtime.Composable
+import androidx.lifecycle.ViewModel
+import androidx.navigation.compose.NavHost
+import androidx.navigation.compose.composable
+import androidx.navigation.compose.rememberNavController
+import com.example.collectionofshortstories.view.authorization.AuthorizationAndLogin
+import com.example.collectionofshortstories.view.start.LoadProgram
+
+@Composable
+fun Navigathion() {
+    val navController = rememberNavController()
+    NavHost(
+        navController = navController,
+        startDestination = "LoadProgram"
+    ) {
+        composable("LoadProgram") {
+            LoadProgram(navController)
+        }
+        composable("AuthorizationAndLogin") {
+            AuthorizationAndLogin(navController)
+        }
+    }
+}

+ 85 - 0
app/src/main/java/com/example/collectionofshortstories/view/authorization/AuthorizationAndLogin.kt

@@ -0,0 +1,85 @@
+package com.example.collectionofshortstories.view.authorization
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Divider
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextField
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.text.font.FontFamily
+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
+import androidx.navigation.NavHostController
+import androidx.compose.material3.TextField
+
+
+//@Preview
+@Composable
+fun AuthorizationAndLogin(navHostController: NavHostController) {
+    Column(
+        horizontalAlignment = Alignment.CenterHorizontally,
+        modifier = Modifier
+            .fillMaxSize()
+            .background(Color(0xFFFCE0C6))
+    ) {
+        Column (
+            horizontalAlignment = Alignment.CenterHorizontally,
+            modifier = Modifier
+
+                .padding(0.dp, 0.dp, 0.dp, 80.dp)
+
+        ) {
+            Text(
+                text = "СБОРНИК РАССКАЗОВ",
+                color = Color.Black,
+                fontSize = 30.sp,
+                fontWeight = FontWeight.Bold,
+                modifier = Modifier
+                    .padding(0.dp, 50.dp, 0.dp, 30.dp)
+            )
+            Divider(
+                modifier = Modifier.fillMaxWidth(),
+                thickness = 5.dp,  // Толщина линии
+                color = Color.Black  // Цвет линии
+            )
+        }
+        Column (
+            horizontalAlignment = Alignment.CenterHorizontally
+        ) {
+            Text(
+                text = "Авторизация",
+                color = Color.Black,
+                fontSize = 30.sp
+            )
+            CreateTextFolder()
+        }
+    }
+}
+@Composable
+fun CreateTextFolder() {
+    TextField(
+        value = "",
+        onValueChange = {},
+        maxLines = 1,
+        placeholder = { Text("example@mail") },
+        modifier = Modifier
+            .padding(0.dp, 30.dp, 0.dp, 0.dp)
+    )
+    TextField(
+        value = "",
+        onValueChange = {},
+        maxLines = 1,
+        placeholder = { Text("password") },
+        modifier = Modifier
+            .padding(0.dp, 30.dp, 0.dp, 0.dp)
+    )
+}

+ 4 - 0
app/src/main/java/com/example/collectionofshortstories/view/authorization/AuthorizationAndLoginViewModel.kt

@@ -0,0 +1,4 @@
+package com.example.collectionofshortstories.view.authorization
+
+class AuthorizationAndLoginViewModel {
+}

+ 4 - 0
app/src/main/java/com/example/collectionofshortstories/view/authorization/components/ViewComponents.kt

@@ -0,0 +1,4 @@
+package com.example.collectionofshortstories.view.authorization.components
+
+import androidx.compose.runtime.Composable
+

+ 35 - 0
app/src/main/java/com/example/collectionofshortstories/view/start/LoadProgram.kt

@@ -0,0 +1,35 @@
+package com.example.collectionofshortstories.view.start
+
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.ImageBitmap
+import androidx.compose.ui.res.imageResource
+import androidx.navigation.NavController
+import androidx.navigation.NavHostController
+import com.example.collectionofshortstories.R
+
+@Composable
+fun LoadProgram(navController: NavHostController) {
+    Column(
+        verticalArrangement = Arrangement.Center,
+        horizontalAlignment = Alignment.CenterHorizontally,
+        modifier = Modifier
+            .fillMaxSize()
+            .fillMaxSize()
+            .background(Color(0xFFFCE0C6))
+    ) {
+        Image(
+            bitmap = ImageBitmap.imageResource(R.drawable.load_program_icon),
+            contentDescription = "icon",
+
+        )
+    }
+    SwitchingTheFirstPage(navController!!)
+}

+ 26 - 0
app/src/main/java/com/example/collectionofshortstories/view/start/LoadProgramViewModel.kt

@@ -0,0 +1,26 @@
+package com.example.collectionofshortstories.view.start
+
+import android.content.res.Configuration
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.ui.platform.LocalConfiguration
+import androidx.navigation.NavHostController
+import kotlinx.coroutines.delay
+
+@Composable
+fun SwitchingTheFirstPage(navController: NavHostController) {
+    val configuration = LocalConfiguration.current
+    if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
+        LaunchedEffect(key1 = true) {
+            delay(1500L)
+            navController.navigate("AuthorizationAndLogin") {
+                //Удаление экрана, чтобы потом нельзя было использовать
+                popUpTo("StartProgram")
+                {
+                    inclusive = true
+                }
+            }
+        }
+    }
+}
+

BIN
app/src/main/res/drawable/load_program_icon.png


+ 6 - 0
gradle/libs.versions.toml

@@ -8,6 +8,9 @@ espressoCore = "3.5.1"
 lifecycleRuntimeKtx = "2.6.1"
 activityCompose = "1.8.0"
 composeBom = "2024.04.01"
+navigationRuntimeKtx = "2.8.0"
+workRuntimeKtx = "2.9.1"
+navigationCompose = "2.8.0"
 
 [libraries]
 androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -24,6 +27,9 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
 androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
 androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
 androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
+androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationRuntimeKtx" }
+androidx-work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workRuntimeKtx" }
+androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
 
 [plugins]
 android-application = { id = "com.android.application", version.ref = "agp" }