Skip to content

Commit

Permalink
Added Theme and Navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
mrugendrakul committed Feb 14, 2024
1 parent e5d95e1 commit 774d264
Show file tree
Hide file tree
Showing 19 changed files with 822 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {

defaultConfig {
applicationId = "com.mrugendra.notificationtest"
minSdk = 24
minSdk = 26
targetSdk = 34
versionCode = 1
versionName = "Testing"
Expand Down Expand Up @@ -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")
Expand Down
154 changes: 126 additions & 28 deletions app/src/main/java/com/mrugendra/notificationtest/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?) {
Expand All @@ -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))
}
}
}
)
}




Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mrugendra.notificationtest.data

import java.time.LocalDateTime

data class Unidentified(
val image:String,
val time:LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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<Identified>
){
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))
)
)
}
}
Loading

0 comments on commit 774d264

Please sign in to comment.