From 774d264eda8ed01ebe99ce4694b39d00ae81f459 Mon Sep 17 00:00:00 2001 From: mrugendrakul Date: Wed, 14 Feb 2024 23:52:59 +0530 Subject: [PATCH] Added Theme and Navigation --- .idea/deploymentTargetDropDown.xml | 3 + app/build.gradle.kts | 8 +- .../notificationtest/MainActivity.kt | 154 ++++++++++++++---- .../notificationtest/data/Identified.kt | 9 + .../notificationtest/data/Unidentified.kt | 8 + .../data/{resident.kt => residents.kt} | 5 +- .../notificationtest/ui/IdentifiedList.kt | 81 +++++++++ .../notificationtest/ui/Residents.kt | 80 +++++++++ .../mrugendra/notificationtest/ui/Start.kt | 116 +++++++++++++ .../ui/{MyApp.kt => TokenRestration.kt} | 18 +- .../notificationtest/ui/UnidentifiedList.kt | 96 +++++++++++ .../notificationtest/ui/theme/Color.kt | 69 +++++++- .../notificationtest/ui/theme/Shape.kt | 9 + .../notificationtest/ui/theme/Theme.kt | 79 +++++++-- .../notificationtest/ui/viewModel.kt | 2 +- app/src/main/res/drawable/ic_broken_image.xml | 25 +++ .../main/res/drawable/ic_connection_error.xml | 25 +++ app/src/main/res/drawable/loading_img.xml | 94 +++++++++++ app/src/main/res/values/strings.xml | 5 + 19 files changed, 822 insertions(+), 64 deletions(-) create mode 100644 app/src/main/java/com/mrugendra/notificationtest/data/Identified.kt create mode 100644 app/src/main/java/com/mrugendra/notificationtest/data/Unidentified.kt rename app/src/main/java/com/mrugendra/notificationtest/data/{resident.kt => residents.kt} (52%) create mode 100644 app/src/main/java/com/mrugendra/notificationtest/ui/IdentifiedList.kt create mode 100644 app/src/main/java/com/mrugendra/notificationtest/ui/Residents.kt create mode 100644 app/src/main/java/com/mrugendra/notificationtest/ui/Start.kt rename app/src/main/java/com/mrugendra/notificationtest/ui/{MyApp.kt => TokenRestration.kt} (90%) create mode 100644 app/src/main/java/com/mrugendra/notificationtest/ui/UnidentifiedList.kt create mode 100644 app/src/main/java/com/mrugendra/notificationtest/ui/theme/Shape.kt create mode 100644 app/src/main/res/drawable/ic_broken_image.xml create mode 100644 app/src/main/res/drawable/ic_connection_error.xml create mode 100644 app/src/main/res/drawable/loading_img.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 0c0c338..969ffe1 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -2,6 +2,9 @@ + + + diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5bcf04f..ceeb7a5 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -11,7 +11,7 @@ android { defaultConfig { applicationId = "com.mrugendra.notificationtest" - minSdk = 24 + minSdk = 26 targetSdk = 34 versionCode = 1 versionName = "Testing" @@ -63,10 +63,12 @@ dependencies { implementation("androidx.compose.material3:material3") implementation(platform("com.google.firebase:firebase-bom:32.7.1")) implementation("com.google.firebase:firebase-analytics") - implementation("com.google.firebase:firebase-messaging:23.4.0") + implementation("com.google.firebase:firebase-messaging:23.4.1") implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0") implementation("com.google.firebase:firebase-database:20.3.0") - implementation("com.google.firebase:firebase-firestore:24.10.1") + implementation("com.google.firebase:firebase-firestore:24.10.2") + implementation("androidx.navigation:navigation-compose:2.7.7") + implementation("io.coil-kt:coil-compose:2.4.0") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") diff --git a/app/src/main/java/com/mrugendra/notificationtest/MainActivity.kt b/app/src/main/java/com/mrugendra/notificationtest/MainActivity.kt index 6691ec0..2941168 100644 --- a/app/src/main/java/com/mrugendra/notificationtest/MainActivity.kt +++ b/app/src/main/java/com/mrugendra/notificationtest/MainActivity.kt @@ -3,15 +3,14 @@ package com.mrugendra.notificationtest import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Spacer +import androidx.annotation.StringRes import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.text.selection.SelectionContainer -import androidx.compose.material3.Button +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface @@ -21,19 +20,28 @@ import androidx.compose.material3.TopAppBarDefaults.topAppBarColors import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel -import com.google.android.gms.tasks.Tasks -import com.google.firebase.Firebase -import com.google.firebase.messaging.messaging +import androidx.navigation.compose.NavHost +import androidx.navigation.NavHostController +import androidx.navigation.compose.composable +import androidx.navigation.compose.currentBackStackEntryAsState +import androidx.navigation.compose.rememberNavController +import com.mrugendra.notificationtest.data.Identified +import com.mrugendra.notificationtest.data.Unidentified +import com.mrugendra.notificationtest.data.residents import com.mrugendra.notificationtest.data.uiState -import com.mrugendra.notificationtest.ui.MyApp import com.mrugendra.notificationtest.ui.Notfi +import com.mrugendra.notificationtest.ui.IdentifiedList +import com.mrugendra.notificationtest.ui.ResidentList +import com.mrugendra.notificationtest.ui.StartHere +import com.mrugendra.notificationtest.ui.TokenRegistration +import com.mrugendra.notificationtest.ui.UnidentifiedList import com.mrugendra.notificationtest.ui.theme.MyApplicationTheme +import java.time.LocalDateTime +import java.time.Month class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -57,45 +65,135 @@ class MainActivity : ComponentActivity() { } + @Preview @Composable fun MyMainScreenPreview(){ // MyApp() - MainSceen( - nofUiState = uiState(), - updateName = {}, - updateToken = {} + MyApplicationTheme() + { + MainSceen( + nofUiState = uiState(), + updateName = {}, + updateToken = {} ) + } +} + +enum class AppScreen(@StringRes val title:Int){ + Start(title = R.string.app_name), + Identified(title = R.string.Identified), + Unidentified(title = R.string.Unidentified), + Residents(title = R.string.Residents), + TokenRegistration(title = R.string.TokenRegs), } + @OptIn(ExperimentalMaterial3Api::class) @Composable fun MainSceen( nofUiState:uiState, updateName:(String)->Unit, - updateToken:()->Unit + updateToken:()->Unit, + navController:NavHostController = rememberNavController(), + ){ + val backStackEntry by navController.currentBackStackEntryAsState() + val currentScreen = AppScreen.valueOf( + backStackEntry?.destination?.route?:AppScreen.Start.name + ) Scaffold( topBar = { - TopAppBar(title = { Text (stringResource(id = R.string.app_name) , - color = MaterialTheme.colorScheme.onPrimary)}, - colors = topAppBarColors( - containerColor = MaterialTheme.colorScheme.primary - ) + IntruderAppBar( + currentScreen = currentScreen, + canNavigateBack = navController.previousBackStackEntry!=null, + navigateUp = { navController.navigateUp() } + ) }, ) { + innerPadding -> + NavHost( + navController = navController, + startDestination = AppScreen.Start.name, + modifier = Modifier.padding(innerPadding) + ){ + composable(AppScreen.Start.name){ + StartHere(nofUiState = nofUiState, + navigateToIdentified = { + navController.navigate(AppScreen.Identified.name) + }, + navigateToUnidentified = { + navController.navigate(AppScreen.Unidentified.name) + }, + navigateToResidents = { + navController.navigate(AppScreen.Residents.name) + }, + navigateToToken = { + navController.navigate(AppScreen.TokenRegistration.name) + } + ) + } + composable(AppScreen.Identified.name){ + IdentifiedList(listOf( + Identified("xyz","Mrugendra", LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Identified("xyz","Mrugendra", LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Identified("xyz","Mrugendra", LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Identified("xyz","Mrugendra", LocalDateTime.of(2024, Month.JANUARY,30,22,12)) + )) + } + composable(AppScreen.Unidentified.name){ + UnidentifiedList(unidentifes = listOf( + Unidentified(image ="https://media.istockphoto.com/id/587805156/vector/profile-picture-vector-illustration.jpg?s=1024x1024&w=is&k=20&c=N14PaYcMX9dfjIQx-gOrJcAUGyYRZ0Ohkbj5lH-GkQs=",time=LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Unidentified(image ="https://media.istockphoto.com/id/587805156/vector/profile-picture-vector-illustration.jpg?s=1024x1024&w=is&k=20&c=N14PaYcMX9dfjIQx-gOrJcAUGyYRZ0Ohkbj5lH-GkQs=",time=LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Unidentified(image ="https://media.istockphoto.com/id/587805156/vector/profile-picture-vector-illustration.jpg?s=1024x1024&w=is&k=20&c=N14PaYcMX9dfjIQx-gOrJcAUGyYRZ0Ohkbj5lH-GkQs=",time=LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Unidentified(image ="https://media.istockphoto.com/id/587805156/vector/profile-picture-vector-illustration.jpg?s=1024x1024&w=is&k=20&c=N14PaYcMX9dfjIQx-gOrJcAUGyYRZ0Ohkbj5lH-GkQs=",time=LocalDateTime.of(2024, Month.JANUARY,30,22,12)) + )) + } + composable(AppScreen.Residents.name){ + ResidentList(residents = listOf( + residents("Mrugendra","123uuidxzyabc","Will get there"), + residents("Mrugendra","123uuidxzyabc","Will get there"), + residents("Mrugendra","123uuidxzyabc","Will get there") + )) + } + composable(AppScreen.TokenRegistration.name){ + TokenRegistration( + nofUiState = nofUiState, + updateToken = updateToken, + updateName = updateName) + } + } - MyApp( - nofUiState = nofUiState, - updateName = updateName, - updateToken = updateToken, - modifier = Modifier.padding(it) - ) } } +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun IntruderAppBar( + currentScreen: AppScreen, + canNavigateBack:Boolean, + navigateUp:()->Unit = {}, + modifier:Modifier = Modifier +){ + TopAppBar(title = { Text (stringResource(id = currentScreen.title), + color = MaterialTheme.colorScheme.onPrimary)}, + colors = topAppBarColors( + containerColor = MaterialTheme.colorScheme.primary + ), + navigationIcon = { + if (canNavigateBack) { + IconButton(onClick = navigateUp){ + Icon( + imageVector = Icons.Filled.ArrowBack, + contentDescription = stringResource(id = R.string.back_button)) + } + } + } + ) +} + diff --git a/app/src/main/java/com/mrugendra/notificationtest/data/Identified.kt b/app/src/main/java/com/mrugendra/notificationtest/data/Identified.kt new file mode 100644 index 0000000..46085ef --- /dev/null +++ b/app/src/main/java/com/mrugendra/notificationtest/data/Identified.kt @@ -0,0 +1,9 @@ +package com.mrugendra.notificationtest.data + +import java.time.LocalDateTime + +data class Identified( + val id:String, + val name:String, + val time:LocalDateTime +) diff --git a/app/src/main/java/com/mrugendra/notificationtest/data/Unidentified.kt b/app/src/main/java/com/mrugendra/notificationtest/data/Unidentified.kt new file mode 100644 index 0000000..cd451d9 --- /dev/null +++ b/app/src/main/java/com/mrugendra/notificationtest/data/Unidentified.kt @@ -0,0 +1,8 @@ +package com.mrugendra.notificationtest.data + +import java.time.LocalDateTime + +data class Unidentified( + val image:String, + val time:LocalDateTime +) diff --git a/app/src/main/java/com/mrugendra/notificationtest/data/resident.kt b/app/src/main/java/com/mrugendra/notificationtest/data/residents.kt similarity index 52% rename from app/src/main/java/com/mrugendra/notificationtest/data/resident.kt rename to app/src/main/java/com/mrugendra/notificationtest/data/residents.kt index 52d66fa..c4f26a4 100644 --- a/app/src/main/java/com/mrugendra/notificationtest/data/resident.kt +++ b/app/src/main/java/com/mrugendra/notificationtest/data/residents.kt @@ -1,6 +1,7 @@ package com.mrugendra.notificationtest.data -data class resident( +data class residents( val name:String, - val token:String + val id:String, + val info:String ) diff --git a/app/src/main/java/com/mrugendra/notificationtest/ui/IdentifiedList.kt b/app/src/main/java/com/mrugendra/notificationtest/ui/IdentifiedList.kt new file mode 100644 index 0000000..6b4f8c1 --- /dev/null +++ b/app/src/main/java/com/mrugendra/notificationtest/ui/IdentifiedList.kt @@ -0,0 +1,81 @@ +package com.mrugendra.notificationtest.ui + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.Card +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.mrugendra.notificationtest.data.Identified +import com.mrugendra.notificationtest.ui.theme.MyApplicationTheme +import java.time.LocalDateTime +import java.time.Month +import java.time.format.DateTimeFormatter + +@Composable +fun IdentifiedList( + identified:List +){ + LazyColumn(modifier = Modifier){ + items(identified){identify-> + Person(identify) + } + } +} + +@Composable +fun Person( + identifiy:Identified +){ + Card( + modifier = Modifier + .fillMaxWidth() + .height(120.dp) + .padding(5.dp), +// border = BorderStroke(5.dp,MaterialTheme.colorScheme.primary) + + ){ + Column( + modifier = Modifier.padding(10.dp) + ){ + Text( + text = identifiy.name, + fontSize = 25.sp + ) + Spacer(Modifier.height(15.dp)) + Text( + text = "Time : ${identifiy.time.format(DateTimeFormatter.ofPattern("HH:mm dd/MM/yyyy"))}", + fontSize = 25.sp) + } + } + +} + + +@Preview +@Composable +fun PreviewPerson(){ + Person(Identified(id="xyz",name="Mrugendra", time=LocalDateTime.of(2024, Month.JANUARY,30,22,12))) +} + +@Preview +@Composable +fun PreviewPeopleList(){ + MyApplicationTheme { + IdentifiedList(identified = listOf( + Identified("xyz","Mrugendra",LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Identified("xyz","Mrugendra",LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Identified("xyz","Mrugendra",LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Identified("xyz","Mrugendra",LocalDateTime.of(2024, Month.JANUARY,30,22,12)) + ) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/mrugendra/notificationtest/ui/Residents.kt b/app/src/main/java/com/mrugendra/notificationtest/ui/Residents.kt new file mode 100644 index 0000000..d5415c6 --- /dev/null +++ b/app/src/main/java/com/mrugendra/notificationtest/ui/Residents.kt @@ -0,0 +1,80 @@ +package com.mrugendra.notificationtest.ui + +import com.mrugendra.notificationtest.data.residents +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.Card +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.mrugendra.notificationtest.data.Identified +import com.mrugendra.notificationtest.ui.theme.MyApplicationTheme +import java.time.LocalDateTime +import java.time.Month +import java.time.format.DateTimeFormatter + +@Composable +fun ResidentList( + residents:List +){ + LazyColumn(modifier = Modifier){ + items(residents){resident-> + Resident(resident) + } + } +} + +@Composable +fun Resident( + resident:residents +){ + Card( + modifier = Modifier + .fillMaxWidth() + .height(120.dp) + .padding(5.dp), +// border = BorderStroke(5.dp,MaterialTheme.colorScheme.primary) + + ){ + Column( + modifier = Modifier.padding(10.dp) + ){ + Text( + text = resident.name, + fontSize = 25.sp + ) + Spacer(Modifier.height(15.dp)) + Text( + text = "Unique id: ${resident.id}", + fontSize = 25.sp) + } + } + +} + + +@Preview +@Composable +fun PreviewResident(){ + Resident(residents("Mrugendra","123uuidxzyabc","Will get there")) +} + +@Preview +@Composable +fun PreviewResidentList(){ + MyApplicationTheme { + ResidentList(residents = listOf( + residents("Mrugendra","123uuidxzyabc","Will get there"), + residents("Mrugendra","123uuidxzyabc","Will get there"), + residents("Mrugendra","123uuidxzyabc","Will get there") + )) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/mrugendra/notificationtest/ui/Start.kt b/app/src/main/java/com/mrugendra/notificationtest/ui/Start.kt new file mode 100644 index 0000000..42cbb8a --- /dev/null +++ b/app/src/main/java/com/mrugendra/notificationtest/ui/Start.kt @@ -0,0 +1,116 @@ +package com.mrugendra.notificationtest.ui + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +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.size +import androidx.compose.foundation.layout.width +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.CardElevation +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.mrugendra.notificationtest.R +import com.mrugendra.notificationtest.data.uiState +import com.mrugendra.notificationtest.ui.theme.MyApplicationTheme + +@Composable +fun StartHere( + nofUiState: uiState, + navigateToIdentified:()->Unit, + navigateToUnidentified:()->Unit, + navigateToResidents:()->Unit, + navigateToToken:()->Unit){ + Column( + modifier = Modifier + .fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Row { + SpcButton(text = "Identified", icon = R.drawable.ic_launcher_foreground,navigateToIdentified) + Spacer(Modifier.width(15.dp)) + SpcButton(text = "Unidentified", icon = R.drawable.ic_launcher_foreground,navigateToUnidentified) + } + Spacer(Modifier.height(15.dp)) + Row { + SpcButton(text = "Residents", icon = R.drawable.ic_launcher_foreground,navigateToResidents) + Spacer(Modifier.width(15.dp)) + SpcButton(text = "Token Registration", icon = R.drawable.ic_launcher_foreground,navigateToToken) + } + + } + +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun SpcButton( + text:String, + icon:Int, + onPress:()->Unit +){ + Card( + elevation = CardDefaults.cardElevation(5.dp), + colors = CardDefaults.cardColors( + containerColor = MaterialTheme.colorScheme.secondaryContainer, + ), + border = BorderStroke(1.dp,MaterialTheme.colorScheme.primary), + modifier = Modifier.size(150.dp), + onClick = onPress + ) { + Column( + + ){ + Image(painter = painterResource(id = icon), + contentDescription = text, + modifier = Modifier + .size(100.dp) + .align(Alignment.CenterHorizontally), + contentScale = ContentScale.Crop + ) +// Spacer(modifier = Modifier.height(10.dp)) + Text(text = text, + modifier = Modifier + .fillMaxWidth(), + fontSize = 15.sp, + textAlign = TextAlign.Center + ) + } + } +} + +@Preview +@Composable +fun PreviewStartHere(){ + MyApplicationTheme() + { StartHere(nofUiState = uiState(),{},{},{},{}) } +} + +@Preview +@Composable +fun PreviewSpcButton(){ + MyApplicationTheme() + { SpcButton("Sample Text", + R.drawable.ic_launcher_foreground, + onPress = {}) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/mrugendra/notificationtest/ui/MyApp.kt b/app/src/main/java/com/mrugendra/notificationtest/ui/TokenRestration.kt similarity index 90% rename from app/src/main/java/com/mrugendra/notificationtest/ui/MyApp.kt rename to app/src/main/java/com/mrugendra/notificationtest/ui/TokenRestration.kt index 23784ad..13a167b 100644 --- a/app/src/main/java/com/mrugendra/notificationtest/ui/MyApp.kt +++ b/app/src/main/java/com/mrugendra/notificationtest/ui/TokenRestration.kt @@ -1,7 +1,6 @@ package com.mrugendra.notificationtest.ui import android.util.Log -import androidx.compose.foundation.gestures.scrollable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -15,27 +14,23 @@ import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Button import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Snackbar +import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text -import androidx.compose.material3.TextButton import androidx.compose.material3.TextField import androidx.compose.runtime.Composable -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import androidx.lifecycle.viewmodel.compose.viewModel import com.mrugendra.notificationtest.R import com.mrugendra.notificationtest.data.TAG import com.mrugendra.notificationtest.data.uiState import com.mrugendra.notificationtest.ui.theme.MyApplicationTheme @Composable -fun MyApp( +fun TokenRegistration( nofUiState: uiState, updateName:(String)->Unit, updateToken:()->Unit, @@ -57,7 +52,7 @@ fun MyApp( SelectionContainer { Text("$token") } - TextField(value = nofUiState.name, + OutlinedTextField(value = nofUiState.name, label = { if(nofUiState.nullName==true){ Text(text = stringResource(R.string.name_cannot_be_null)) @@ -81,8 +76,8 @@ fun MyApp( ) Button(onClick = {updateToken() }, - - enabled = !nofUiState.exist and !nofUiState.successSend) { + enabled = !nofUiState.exist and !nofUiState.successSend, + shape = MaterialTheme.shapes.medium) { Log.d(TAG,"Exist inside ui button : ${nofUiState.exist}") Text(text = stringResource(R.string.database_Sync)) } @@ -95,12 +90,11 @@ fun MyApp( } - @Preview @Composable fun MyAppPreview(){ MyApplicationTheme() - { MyApp( + { TokenRegistration( nofUiState = uiState(), updateToken = {}, updateName = { diff --git a/app/src/main/java/com/mrugendra/notificationtest/ui/UnidentifiedList.kt b/app/src/main/java/com/mrugendra/notificationtest/ui/UnidentifiedList.kt new file mode 100644 index 0000000..872bf92 --- /dev/null +++ b/app/src/main/java/com/mrugendra/notificationtest/ui/UnidentifiedList.kt @@ -0,0 +1,96 @@ +package com.mrugendra.notificationtest.ui + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.Card +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import coil.compose.AsyncImage +import coil.request.CachePolicy +import coil.request.ImageRequest +import com.mrugendra.notificationtest.R +import com.mrugendra.notificationtest.data.Unidentified +import com.mrugendra.notificationtest.ui.theme.MyApplicationTheme +import java.time.LocalDateTime +import java.time.Month +import java.time.format.DateTimeFormatter + +@Composable +fun UnidentifiedList( + unidentifes:List +){ + LazyColumn(modifier = Modifier){ + items(unidentifes){unknown-> + Unkown(unknown) + } + } +} + +@Composable +fun Unkown( + unknown:Unidentified +){ + Card( + modifier = Modifier + .fillMaxWidth() +// .height(120.dp) + .padding(5.dp), +// border = BorderStroke(5.dp,MaterialTheme.colorScheme.primary) + + ){ + Column( + modifier = Modifier.padding(10.dp) + ){ + AsyncImage( + model = ImageRequest.Builder(context= LocalContext.current) + .data(unknown.image) + .memoryCachePolicy(CachePolicy.DISABLED) + .build(), + contentDescription = "Unkown person", + modifier = Modifier + .fillMaxWidth() + .height(200.dp), + error = painterResource(id = R.drawable.ic_broken_image), + placeholder = painterResource(id = R.drawable.loading_img), + contentScale = ContentScale.Crop) + Spacer(Modifier.height(15.dp)) + Text( + text = "Time : ${unknown.time.format(DateTimeFormatter.ofPattern("HH:mm dd/MM/yyyy"))}", + fontSize = 25.sp) + } + } + +} + + +@Preview +@Composable +fun PreviewUnkown(){ + Unkown(Unidentified(image ="https://media.istockphoto.com/id/587805156/vector/profile-picture-vector-illustration.jpg?s=1024x1024&w=is&k=20&c=N14PaYcMX9dfjIQx-gOrJcAUGyYRZ0Ohkbj5lH-GkQs=",time=LocalDateTime.of(2024, Month.JANUARY,30,22,12))) +} + +@Preview +@Composable +fun PreviewUnidentifiedList(){ + MyApplicationTheme { + UnidentifiedList(unidentifes = listOf( + Unidentified(image ="https://media.istockphoto.com/id/587805156/vector/profile-picture-vector-illustration.jpg?s=1024x1024&w=is&k=20&c=N14PaYcMX9dfjIQx-gOrJcAUGyYRZ0Ohkbj5lH-GkQs=",time=LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Unidentified(image ="https://media.istockphoto.com/id/587805156/vector/profile-picture-vector-illustration.jpg?s=1024x1024&w=is&k=20&c=N14PaYcMX9dfjIQx-gOrJcAUGyYRZ0Ohkbj5lH-GkQs=",time=LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Unidentified(image ="https://media.istockphoto.com/id/587805156/vector/profile-picture-vector-illustration.jpg?s=1024x1024&w=is&k=20&c=N14PaYcMX9dfjIQx-gOrJcAUGyYRZ0Ohkbj5lH-GkQs=",time=LocalDateTime.of(2024, Month.JANUARY,30,22,12)), + Unidentified(image ="https://media.istockphoto.com/id/587805156/vector/profile-picture-vector-illustration.jpg?s=1024x1024&w=is&k=20&c=N14PaYcMX9dfjIQx-gOrJcAUGyYRZ0Ohkbj5lH-GkQs=",time=LocalDateTime.of(2024, Month.JANUARY,30,22,12)) + ) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Color.kt b/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Color.kt index 426a764..91825c7 100644 --- a/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Color.kt +++ b/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Color.kt @@ -2,10 +2,67 @@ package com.mrugendra.notificationtest.ui.theme import androidx.compose.ui.graphics.Color -val Purple80 = Color(0xFFD0BCFF) -val PurpleGrey80 = Color(0xFFCCC2DC) -val Pink80 = Color(0xFFEFB8C8) +val md_theme_light_primary = Color(0xFF0059C5) +val md_theme_light_onPrimary = Color(0xFFFFFFFF) +val md_theme_light_primaryContainer = Color(0xFFD8E2FF) +val md_theme_light_onPrimaryContainer = Color(0xFF001A43) +val md_theme_light_secondary = Color(0xFF0061A6) +val md_theme_light_onSecondary = Color(0xFFFFFFFF) +val md_theme_light_secondaryContainer = Color(0xFFD2E4FF) +val md_theme_light_onSecondaryContainer = Color(0xFF001C37) +val md_theme_light_tertiary = Color(0xFF954A05) +val md_theme_light_onTertiary = Color(0xFFFFFFFF) +val md_theme_light_tertiaryContainer = Color(0xFFFFDCC7) +val md_theme_light_onTertiaryContainer = Color(0xFF311300) +val md_theme_light_error = Color(0xFFBA1A1A) +val md_theme_light_errorContainer = Color(0xFFFFDAD6) +val md_theme_light_onError = Color(0xFFFFFFFF) +val md_theme_light_onErrorContainer = Color(0xFF410002) +val md_theme_light_background = Color(0xFFFEFBFF) +val md_theme_light_onBackground = Color(0xFF1B1B1F) +val md_theme_light_surface = Color(0xFFFEFBFF) +val md_theme_light_onSurface = Color(0xFF1B1B1F) +val md_theme_light_surfaceVariant = Color(0xFFE1E2EC) +val md_theme_light_onSurfaceVariant = Color(0xFF44474F) +val md_theme_light_outline = Color(0xFF757780) +val md_theme_light_inverseOnSurface = Color(0xFFF2F0F4) +val md_theme_light_inverseSurface = Color(0xFF303034) +val md_theme_light_inversePrimary = Color(0xFFAEC6FF) +val md_theme_light_shadow = Color(0xFF000000) +val md_theme_light_surfaceTint = Color(0xFF0059C5) +val md_theme_light_outlineVariant = Color(0xFFC5C6D0) +val md_theme_light_scrim = Color(0xFF000000) -val Purple40 = Color(0xFF6650a4) -val PurpleGrey40 = Color(0xFF625b71) -val Pink40 = Color(0xFF7D5260) \ No newline at end of file +val md_theme_dark_primary = Color(0xFFAEC6FF) +val md_theme_dark_onPrimary = Color(0xFF002E6B) +val md_theme_dark_primaryContainer = Color(0xFF004397) +val md_theme_dark_onPrimaryContainer = Color(0xFFD8E2FF) +val md_theme_dark_secondary = Color(0xFFA0C9FF) +val md_theme_dark_onSecondary = Color(0xFF00325A) +val md_theme_dark_secondaryContainer = Color(0xFF00497F) +val md_theme_dark_onSecondaryContainer = Color(0xFFD2E4FF) +val md_theme_dark_tertiary = Color(0xFFFFB787) +val md_theme_dark_onTertiary = Color(0xFF502400) +val md_theme_dark_tertiaryContainer = Color(0xFF723600) +val md_theme_dark_onTertiaryContainer = Color(0xFFFFDCC7) +val md_theme_dark_error = Color(0xFFFFB4AB) +val md_theme_dark_errorContainer = Color(0xFF93000A) +val md_theme_dark_onError = Color(0xFF690005) +val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6) +val md_theme_dark_background = Color(0xFF1B1B1F) +val md_theme_dark_onBackground = Color(0xFFE3E2E6) +val md_theme_dark_surface = Color(0xFF1B1B1F) +val md_theme_dark_onSurface = Color(0xFFE3E2E6) +val md_theme_dark_surfaceVariant = Color(0xFF44474F) +val md_theme_dark_onSurfaceVariant = Color(0xFFC5C6D0) +val md_theme_dark_outline = Color(0xFF8E9099) +val md_theme_dark_inverseOnSurface = Color(0xFF1B1B1F) +val md_theme_dark_inverseSurface = Color(0xFFE3E2E6) +val md_theme_dark_inversePrimary = Color(0xFF0059C5) +val md_theme_dark_shadow = Color(0xFF000000) +val md_theme_dark_surfaceTint = Color(0xFFAEC6FF) +val md_theme_dark_outlineVariant = Color(0xFF44474F) +val md_theme_dark_scrim = Color(0xFF000000) + + +val seed = Color(0xFF2677F3) \ No newline at end of file diff --git a/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Shape.kt b/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Shape.kt new file mode 100644 index 0000000..03dc546 --- /dev/null +++ b/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Shape.kt @@ -0,0 +1,9 @@ +package com.mrugendra.notificationtest.ui.theme +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Shapes +import androidx.compose.ui.unit.dp + +val Shapes = Shapes( + small = RoundedCornerShape(50.dp), + medium = RoundedCornerShape(5.dp) +) \ No newline at end of file diff --git a/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Theme.kt b/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Theme.kt index d8b0ee0..e34ecbb 100644 --- a/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Theme.kt +++ b/app/src/main/java/com/mrugendra/notificationtest/ui/theme/Theme.kt @@ -15,16 +15,71 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.core.view.WindowCompat -private val DarkColorScheme = darkColorScheme( - primary = Purple80, - secondary = PurpleGrey80, - tertiary = Pink80 +private val LightColors = lightColorScheme( + primary = md_theme_light_primary, + onPrimary = md_theme_light_onPrimary, + primaryContainer = md_theme_light_primaryContainer, + onPrimaryContainer = md_theme_light_onPrimaryContainer, + secondary = md_theme_light_secondary, + onSecondary = md_theme_light_onSecondary, + secondaryContainer = md_theme_light_secondaryContainer, + onSecondaryContainer = md_theme_light_onSecondaryContainer, + tertiary = md_theme_light_tertiary, + onTertiary = md_theme_light_onTertiary, + tertiaryContainer = md_theme_light_tertiaryContainer, + onTertiaryContainer = md_theme_light_onTertiaryContainer, + error = md_theme_light_error, + errorContainer = md_theme_light_errorContainer, + onError = md_theme_light_onError, + onErrorContainer = md_theme_light_onErrorContainer, + background = md_theme_light_background, + onBackground = md_theme_light_onBackground, + surface = md_theme_light_surface, + onSurface = md_theme_light_onSurface, + surfaceVariant = md_theme_light_surfaceVariant, + onSurfaceVariant = md_theme_light_onSurfaceVariant, + outline = md_theme_light_outline, + inverseOnSurface = md_theme_light_inverseOnSurface, + inverseSurface = md_theme_light_inverseSurface, + inversePrimary = md_theme_light_inversePrimary, + surfaceTint = md_theme_light_surfaceTint, + outlineVariant = md_theme_light_outlineVariant, + scrim = md_theme_light_scrim, +) + + +private val DarkColors = darkColorScheme( + primary = md_theme_dark_primary, + onPrimary = md_theme_dark_onPrimary, + primaryContainer = md_theme_dark_primaryContainer, + onPrimaryContainer = md_theme_dark_onPrimaryContainer, + secondary = md_theme_dark_secondary, + onSecondary = md_theme_dark_onSecondary, + secondaryContainer = md_theme_dark_secondaryContainer, + onSecondaryContainer = md_theme_dark_onSecondaryContainer, + tertiary = md_theme_dark_tertiary, + onTertiary = md_theme_dark_onTertiary, + tertiaryContainer = md_theme_dark_tertiaryContainer, + onTertiaryContainer = md_theme_dark_onTertiaryContainer, + error = md_theme_dark_error, + errorContainer = md_theme_dark_errorContainer, + onError = md_theme_dark_onError, + onErrorContainer = md_theme_dark_onErrorContainer, + background = md_theme_dark_background, + onBackground = md_theme_dark_onBackground, + surface = md_theme_dark_surface, + onSurface = md_theme_dark_onSurface, + surfaceVariant = md_theme_dark_surfaceVariant, + onSurfaceVariant = md_theme_dark_onSurfaceVariant, + outline = md_theme_dark_outline, + inverseOnSurface = md_theme_dark_inverseOnSurface, + inverseSurface = md_theme_dark_inverseSurface, + inversePrimary = md_theme_dark_inversePrimary, + surfaceTint = md_theme_dark_surfaceTint, + outlineVariant = md_theme_dark_outlineVariant, + scrim = md_theme_dark_scrim, ) -private val LightColorScheme = lightColorScheme( - primary = Purple40, - secondary = PurpleGrey40, - tertiary = Pink40 /* Other default colors to override background = Color(0xFFFFFBFE), @@ -35,7 +90,6 @@ private val LightColorScheme = lightColorScheme( onBackground = Color(0xFF1C1B1F), onSurface = Color(0xFF1C1B1F), */ -) @Composable fun MyApplicationTheme( @@ -50,8 +104,8 @@ fun MyApplicationTheme( if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) } - darkTheme -> DarkColorScheme - else -> LightColorScheme + darkTheme -> DarkColors + else -> LightColors } val view = LocalView.current if (!view.isInEditMode) { @@ -65,6 +119,7 @@ fun MyApplicationTheme( MaterialTheme( colorScheme = colorScheme, typography = Typography, - content = content + content = content, + shapes = Shapes ) } \ No newline at end of file diff --git a/app/src/main/java/com/mrugendra/notificationtest/ui/viewModel.kt b/app/src/main/java/com/mrugendra/notificationtest/ui/viewModel.kt index 7573737..cd85d2a 100644 --- a/app/src/main/java/com/mrugendra/notificationtest/ui/viewModel.kt +++ b/app/src/main/java/com/mrugendra/notificationtest/ui/viewModel.kt @@ -20,7 +20,7 @@ import com.mrugendra.notificationtest.Network.FirebaseAPI import com.mrugendra.notificationtest.Network.NetworkFirebaseAPI import com.mrugendra.notificationtest.data.NetworkTokenRepository import com.mrugendra.notificationtest.data.TokenRepository -import com.mrugendra.notificationtest.data.resident +import com.mrugendra.notificationtest.data.residents import com.mrugendra.notificationtest.data.uiState import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow diff --git a/app/src/main/res/drawable/ic_broken_image.xml b/app/src/main/res/drawable/ic_broken_image.xml new file mode 100644 index 0000000..c3b995b --- /dev/null +++ b/app/src/main/res/drawable/ic_broken_image.xml @@ -0,0 +1,25 @@ + + + + diff --git a/app/src/main/res/drawable/ic_connection_error.xml b/app/src/main/res/drawable/ic_connection_error.xml new file mode 100644 index 0000000..a961d63 --- /dev/null +++ b/app/src/main/res/drawable/ic_connection_error.xml @@ -0,0 +1,25 @@ + + + + diff --git a/app/src/main/res/drawable/loading_img.xml b/app/src/main/res/drawable/loading_img.xml new file mode 100644 index 0000000..0b64932 --- /dev/null +++ b/app/src/main/res/drawable/loading_img.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3129b68..bd2418e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,4 +6,9 @@ Token exist in the database Token Already exist in database with different name Name cannot be null + Identified + Unidentified + Residents + TokenRegistration + back button \ No newline at end of file