diff --git a/app/src/main/java/app/waste2wealth/com/MainActivity.kt b/app/src/main/java/app/waste2wealth/com/MainActivity.kt index a968bd0..4a44ea9 100644 --- a/app/src/main/java/app/waste2wealth/com/MainActivity.kt +++ b/app/src/main/java/app/waste2wealth/com/MainActivity.kt @@ -1,5 +1,6 @@ package app.waste2wealth.com +import android.Manifest import android.annotation.SuppressLint import android.content.Intent import android.content.IntentFilter @@ -7,16 +8,30 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.animation.ExperimentalAnimationApi +import androidx.compose.material.BottomDrawerValue +import androidx.compose.material.ExperimentalMaterialApi +import androidx.compose.material.Scaffold +import androidx.compose.material.rememberBottomDrawerState import androidx.compose.material.rememberScaffoldState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.ui.ExperimentalComposeUiApi import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.ViewModelProvider +import androidx.navigation.compose.currentBackStackEntryAsState +import app.waste2wealth.com.bottombar.BottomBar +import app.waste2wealth.com.components.permissions.PermissionDrawer import app.waste2wealth.com.location.LocationViewModel import app.waste2wealth.com.login.onboarding.SmsBroadcastReceiver import app.waste2wealth.com.login.onboarding.SmsBroadcastReceiver.SmsBroadcastReceiverListener import app.waste2wealth.com.navigation.NavigationController +import app.waste2wealth.com.navigation.Screens import app.waste2wealth.com.ui.theme.Waste2WealthTheme import app.waste2wealth.com.ui.theme.appBackground import com.google.accompanist.navigation.animation.rememberAnimatedNavController +import com.google.accompanist.permissions.ExperimentalPermissionsApi +import com.google.accompanist.permissions.rememberMultiplePermissionsState import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.android.gms.auth.api.phone.SmsRetriever import dagger.hilt.android.AndroidEntryPoint @@ -27,26 +42,71 @@ class MainActivity : ComponentActivity() { private lateinit var smsBroadcastReceiver: SmsBroadcastReceiver private lateinit var viewModel: LocationViewModel - @OptIn(ExperimentalAnimationApi::class) + @OptIn( + ExperimentalAnimationApi::class, ExperimentalPermissionsApi::class, + ExperimentalMaterialApi::class, ExperimentalComposeUiApi::class + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { Waste2WealthTheme { - val systemUiController = rememberSystemUiController() - systemUiController.setSystemBarsColor(appBackground) - systemUiController.setNavigationBarColor(appBackground) val navController = rememberAnimatedNavController() - viewModel = ViewModelProvider(this)[LocationViewModel::class.java] - - val locationViewModel: LocationViewModel = hiltViewModel() - val scaffoldState = rememberScaffoldState() - val client = SmsRetriever.getClient(this) - client.startSmsUserConsent(null) -// SettingUp(navHostController = navController) - NavigationController(scaffoldState, locationViewModel, navController) -// CompleteProfile() - - + val permissionState = rememberMultiplePermissionsState( + permissions = listOf( + Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.CAMERA, + ) + ) + val permissionDrawerState = rememberBottomDrawerState( + if (permissionState.allPermissionsGranted) BottomDrawerValue.Closed else BottomDrawerValue.Open + ) + val bottomBarState = rememberSaveable { (mutableStateOf(true)) } + val navBackStackEntry by navController.currentBackStackEntryAsState() + when (navBackStackEntry?.destination?.route) { + Screens.Dashboard.route -> { + bottomBarState.value = true + } + Screens.Community.route -> { + bottomBarState.value = true + } + else -> { + bottomBarState.value = false + } + } + PermissionDrawer( + drawerState = permissionDrawerState, + permissionState = permissionState, + rationaleText = "To continue, allow Report Waste2Wealth to access your device's location" + + ". Tap Settings > Permission, and turn \"Access Location On\" on.", + withoutRationaleText = "Location permission required for functionality of this app." + + " Please grant the permission.", + ) { + Scaffold(bottomBar = { + BottomBar( + navController = navController, + bottomBarState = bottomBarState + ) + }) { + + val systemUiController = rememberSystemUiController() + systemUiController.setSystemBarsColor(appBackground) + systemUiController.setNavigationBarColor(appBackground) + + viewModel = ViewModelProvider(this)[LocationViewModel::class.java] + + val locationViewModel: LocationViewModel = hiltViewModel() + val scaffoldState = rememberScaffoldState() + val client = SmsRetriever.getClient(this) + client.startSmsUserConsent(null) + NavigationController( + scaffoldState, + locationViewModel, + navController, + it + ) + } + } } } } @@ -54,13 +114,14 @@ class MainActivity : ComponentActivity() { @SuppressLint("UnspecifiedRegisterReceiverFlag") private fun registerBroadcastReceiver() { smsBroadcastReceiver = SmsBroadcastReceiver() - smsBroadcastReceiver.smsBroadcastReceiverListener = object : SmsBroadcastReceiverListener { - override fun onSuccess(intent: Intent?) { - intent?.let { startActivityForResult(it, 200) } - } + smsBroadcastReceiver.smsBroadcastReceiverListener = + object : SmsBroadcastReceiverListener { + override fun onSuccess(intent: Intent?) { + intent?.let { startActivityForResult(it, 200) } + } - override fun onFailure() {} - } + override fun onFailure() {} + } val intentFilter = IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION) registerReceiver(smsBroadcastReceiver, intentFilter) } diff --git a/app/src/main/java/app/waste2wealth/com/bottombar/BottomBar.kt b/app/src/main/java/app/waste2wealth/com/bottombar/BottomBar.kt index 9a8851a..2dd6ffe 100644 --- a/app/src/main/java/app/waste2wealth/com/bottombar/BottomBar.kt +++ b/app/src/main/java/app/waste2wealth/com/bottombar/BottomBar.kt @@ -1,5 +1,8 @@ package app.waste2wealth.com.bottombar +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.slideInVertically +import androidx.compose.animation.slideOutVertically import androidx.compose.foundation.background import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.fillMaxWidth @@ -13,7 +16,9 @@ import androidx.compose.material.Card import androidx.compose.material.Icon import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color @@ -31,74 +36,84 @@ import app.waste2wealth.com.ui.theme.monteSB import app.waste2wealth.com.ui.theme.textColor @Composable -fun BottomBar(navController: NavController) { - val navBackStackEntry by navController.currentBackStackEntryAsState() - val currentRoute = navBackStackEntry?.destination - Card( - modifier = Modifier - .fillMaxWidth(), - backgroundColor = CardColor, - elevation = 5.dp, - shape = RoundedCornerShape(17.dp) - ) { - BottomNavigation( - modifier = Modifier - .height(80.dp), - elevation = 0.dp, - backgroundColor = CardColor - ) { - items.forEach { - val isYellow = currentRoute?.hierarchy?.any { nav -> - nav.route == it.route - } == true - val myTextColor = if (isSystemInDarkTheme()) { - if (isYellow) Color.Black else Color.White - } else { - if (isYellow) Color.White else Color.Black - } - BottomNavigationItem( - icon = { - it.icon?.let { - Icon( - painter = painterResource(id = it), - contentDescription = "", - modifier = Modifier - .size(35.dp) - .padding(bottom = 5.dp), - tint = if (isYellow) myTextColor else CardTextColor - ) - } - }, - label = { - it.title?.let { - Text( - text = it, - color = if (isYellow) myTextColor else CardTextColor, - softWrap = true, - fontFamily = monteSB, - fontSize = 10.sp - ) - } - }, - selected = isYellow, - selectedContentColor = Color.Yellow, - unselectedContentColor = CardColor, +fun BottomBar( + navController: NavController, + bottomBarState: MutableState = mutableStateOf(true) +) { + AnimatedVisibility( + visible = bottomBarState.value, + enter = slideInVertically(initialOffsetY = { it }), + exit = slideOutVertically(targetOffsetY = { it }), + content = { + val navBackStackEntry by navController.currentBackStackEntryAsState() + val currentRoute = navBackStackEntry?.destination + Card( + modifier = Modifier + .fillMaxWidth(), + backgroundColor = CardColor, + elevation = 5.dp, + shape = RoundedCornerShape(17.dp) + ) { + BottomNavigation( modifier = Modifier - .background(if (isYellow) textColor else myTextColor) - .clip(RoundedCornerShape(17.dp)), - onClick = { - it.route?.let { it1 -> - navController.navigate(it1) { - popUpTo(Screens.Dashboard.route) { - saveState = true + .height(80.dp), + elevation = 0.dp, + backgroundColor = CardColor + ) { + items.forEach { + val isYellow = currentRoute?.hierarchy?.any { nav -> + nav.route == it.route + } == true + val myTextColor = if (isSystemInDarkTheme()) { + if (isYellow) Color.Black else Color.White + } else { + if (isYellow) Color.White else Color.Black + } + BottomNavigationItem( + icon = { + it.icon?.let { + Icon( + painter = painterResource(id = it), + contentDescription = "", + modifier = Modifier + .size(35.dp) + .padding(bottom = 5.dp), + tint = if (isYellow) myTextColor else CardTextColor + ) + } + }, + label = { + it.title?.let { + Text( + text = it, + color = if (isYellow) myTextColor else CardTextColor, + softWrap = true, + fontFamily = monteSB, + fontSize = 10.sp + ) + } + }, + selected = isYellow, + selectedContentColor = Color.Yellow, + unselectedContentColor = CardColor, + modifier = Modifier + .background(if (isYellow) textColor else myTextColor) + .clip(RoundedCornerShape(17.dp)), + onClick = { + it.route?.let { it1 -> + navController.navigate(it1) { + popUpTo(Screens.Dashboard.route) { + saveState = true + } + launchSingleTop = true + restoreState = true + } } - launchSingleTop = true - restoreState = true } - } + ) } - ) + } } } - } -} \ No newline at end of file + ) +} diff --git a/app/src/main/java/app/waste2wealth/com/collectwaste/CollectWasteInfo.kt b/app/src/main/java/app/waste2wealth/com/collectwaste/CollectWasteInfo.kt index 8438ad4..66ffe1e 100644 --- a/app/src/main/java/app/waste2wealth/com/collectwaste/CollectWasteInfo.kt +++ b/app/src/main/java/app/waste2wealth/com/collectwaste/CollectWasteInfo.kt @@ -66,24 +66,12 @@ import kotlin.math.sin import kotlin.math.sqrt -@OptIn( - ExperimentalPermissionsApi::class, ExperimentalComposeUiApi::class, - ExperimentalMaterialApi::class -) @Composable fun CollectWasteInfo( navController: NavHostController, viewModel: LocationViewModel ) { val context = LocalContext.current - val permissionState = rememberMultiplePermissionsState( - permissions = listOf( - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION, - ) - ) - val permissionDrawerState = rememberBottomDrawerState(BottomDrawerValue.Closed) - val gesturesEnabled by remember { derivedStateOf { permissionDrawerState.isOpen } } var isDialogVisible by remember { mutableStateOf(false) } val isWithin = isWithinRadius( viewModel.latitude, @@ -104,153 +92,137 @@ fun CollectWasteInfo( LaunchedEffect(key1 = Unit) { viewModel.getPlaces() } - PermissionDrawer( - drawerState = permissionDrawerState, - permissionState = permissionState, - rationaleText = "To continue, allow Waste2Wealth to access your device's camera" + - ". Tap Settings > Permission, and turn \"Access Camera On\" on.", - withoutRationaleText = "Camera permission required for this feature to be available." + - " Please grant the permission.", - model = R.drawable.camera, - gesturesEnabled = gesturesEnabled, - size = 100.dp + + Column( + modifier = Modifier + .fillMaxSize() + .background(appBackground) ) { - Scaffold(bottomBar = { - BottomBar(navController = navController) - }) { - println(it) - Column( + Row( + modifier = Modifier + .fillMaxWidth() + .padding(top = 30.dp, start = 0.dp), + horizontalArrangement = Arrangement.Start + ) { + Icon( + imageVector = Icons.Filled.ArrowBackIos, + contentDescription = "", + tint = textColor, modifier = Modifier - .fillMaxSize() - .background(appBackground) - ) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(top = 30.dp, start = 0.dp), - horizontalArrangement = Arrangement.Start - ) { - Icon( - imageVector = Icons.Filled.ArrowBackIos, - contentDescription = "", - tint = textColor, - modifier = Modifier - .padding(start = 15.dp) - .size(25.dp) - .clickable { - navController.popBackStack() - } - ) - Row( - modifier = Modifier - .fillMaxWidth() - .offset(x = (-10).dp), - horizontalArrangement = Arrangement.Center - ) { - Text( - text = "Collect Waste", - color = textColor, - fontFamily = monteSB, - fontSize = 25.sp - ) - } - } - - Spacer(modifier = Modifier.height(30.dp)) - WasteItemCard( - locationNo = viewModel.locationNo.value, - address = viewModel.address.value, - distance = viewModel.distance.value, - time = viewModel.time.value, - isCollectedInfo = true, - isEllipsis = false, - onCollected = { - val gmmIntentUri = - Uri.parse( - "google.navigation:q=${viewModel.theirLatitude.value}," + - "${viewModel.theirLongitude.value}" - ) - val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri) - mapIntent.setPackage("com.google.android.apps.maps") - context.startActivity(mapIntent) - + .padding(start = 15.dp) + .size(25.dp) + .clickable { + navController.popBackStack() } + ) + Row( + modifier = Modifier + .fillMaxWidth() + .offset(x = (-10).dp), + horizontalArrangement = Arrangement.Center + ) { + Text( + text = "Collect Waste", + color = textColor, + fontFamily = monteSB, + fontSize = 25.sp ) - Spacer(modifier = Modifier.height(30.dp)) - var imageUrlState by remember { - mutableStateOf("") - } - LaunchedEffect(key1 = Unit) { - val imageUrl = withContext(Dispatchers.IO) { - try { - getDownloadUrlFromPath(viewModel.wastePhoto.value) - } catch (e: Exception) { - "" - } - } - imageUrlState = imageUrl - } - if (imageUrlState != "") { - AsyncImage( - model = imageUrlState, - contentDescription = "", - modifier = Modifier - .fillMaxWidth() - .height(300.dp) - .padding(bottom = 30.dp) - .clip(RoundedCornerShape(30.dp)), - ) - } + } + } - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.Center - ) { - Button( - onClick = { - if (!isWithin) { - isDialogVisible = true - } else { - navController.navigate(Screens.CollectedWasteSuccess.route) - } - }, - colors = ButtonDefaults.buttonColors( - backgroundColor = CardColor, - contentColor = CardTextColor - ), - shape = RoundedCornerShape(35.dp), - modifier = Modifier.padding(start = 10.dp) - ) { - Text( - text = "Collect Waste", - color = CardTextColor, - fontSize = 12.sp, - fontFamily = monteSB, - modifier = Modifier.padding(bottom = 4.dp), - maxLines = 1, - softWrap = true - ) - } - } - if (!isWithin) { - DialogBox( - isVisible = isDialogVisible, - title = "Are You Sure you reached the location?", - description = "It feels like you aren't at the location yet. " + - "Please make sure you are at the location before you collect the waste.", - successRequest = { - isDialogVisible = false - navController.navigate(Screens.CollectedWasteSuccess.route) - }, - dismissRequest = { - isDialogVisible = false - } + Spacer(modifier = Modifier.height(30.dp)) + WasteItemCard( + locationNo = viewModel.locationNo.value, + address = viewModel.address.value, + distance = viewModel.distance.value, + time = viewModel.time.value, + isCollectedInfo = true, + isEllipsis = false, + onCollected = { + val gmmIntentUri = + Uri.parse( + "google.navigation:q=${viewModel.theirLatitude.value}," + + "${viewModel.theirLongitude.value}" ) + val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri) + mapIntent.setPackage("com.google.android.apps.maps") + context.startActivity(mapIntent) + + } + ) + Spacer(modifier = Modifier.height(30.dp)) + var imageUrlState by remember { + mutableStateOf("") + } + LaunchedEffect(key1 = Unit) { + val imageUrl = withContext(Dispatchers.IO) { + try { + getDownloadUrlFromPath(viewModel.wastePhoto.value) + } catch (e: Exception) { + "" } } + imageUrlState = imageUrl + } + if (imageUrlState != "") { + AsyncImage( + model = imageUrlState, + contentDescription = "", + modifier = Modifier + .fillMaxWidth() + .height(300.dp) + .padding(bottom = 30.dp) + .clip(RoundedCornerShape(30.dp)), + ) + } + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.Center + ) { + Button( + onClick = { + if (!isWithin) { + isDialogVisible = true + } else { + navController.navigate(Screens.CollectedWasteSuccess.route) + } + }, + colors = ButtonDefaults.buttonColors( + backgroundColor = CardColor, + contentColor = CardTextColor + ), + shape = RoundedCornerShape(35.dp), + modifier = Modifier.padding(start = 10.dp) + ) { + Text( + text = "Collect Waste", + color = CardTextColor, + fontSize = 12.sp, + fontFamily = monteSB, + modifier = Modifier.padding(bottom = 4.dp), + maxLines = 1, + softWrap = true + ) + } + } + if (!isWithin) { + DialogBox( + isVisible = isDialogVisible, + title = "Are You Sure you reached the location?", + description = "It feels like you aren't at the location yet. " + + "Please make sure you are at the location before you collect the waste.", + successRequest = { + isDialogVisible = false + navController.navigate(Screens.CollectedWasteSuccess.route) + }, + dismissRequest = { + isDialogVisible = false + } + ) } } + } suspend fun getDownloadUrlFromPath(path: String): String { diff --git a/app/src/main/java/app/waste2wealth/com/collectwaste/ListOfCollectWaste.kt b/app/src/main/java/app/waste2wealth/com/collectwaste/ListOfCollectWaste.kt index 9c335f9..ae0bc52 100644 --- a/app/src/main/java/app/waste2wealth/com/collectwaste/ListOfCollectWaste.kt +++ b/app/src/main/java/app/waste2wealth/com/collectwaste/ListOfCollectWaste.kt @@ -73,11 +73,12 @@ import kotlin.math.cos import kotlin.math.sin @OptIn( - ExperimentalPermissionsApi::class, ExperimentalComposeUiApi::class, + ExperimentalPermissionsApi::class, ExperimentalMaterialApi::class ) @Composable fun CollectWaste( + paddingValues: PaddingValues, navController: NavHostController, viewModel: LocationViewModel ) { @@ -93,166 +94,150 @@ fun CollectWaste( LaunchedEffect(key1 = Unit) { viewModel.getPlaces() } - PermissionDrawer( - drawerState = permissionDrawerState, - permissionState = permissionState, - rationaleText = "To continue, allow Waste2Wealth to access your device's camera" + - ". Tap Settings > Permission, and turn \"Access Camera On\" on.", - withoutRationaleText = "Camera permission required for this feature to be available." + - " Please grant the permission.", - model = R.drawable.camera, - gesturesEnabled = gesturesEnabled, - size = 100.dp - ) { - Scaffold(bottomBar = { - BottomBar(navController = navController) - }) { - JetFirestore(path = { - collection("AllWastes") - }, onRealtimeCollectionFetch = { values, _ -> - allWastes = values?.getListOfObjects() - }) { - println(it) - Column( + JetFirestore(path = { + collection("AllWastes") + }, onRealtimeCollectionFetch = { values, _ -> + allWastes = values?.getListOfObjects() + + }) { + Column( + modifier = Modifier + .fillMaxSize() + .background(appBackground) + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(top = 30.dp, start = 0.dp), + horizontalArrangement = Arrangement.Start + ) { + Icon( + imageVector = Icons.Filled.ArrowBackIos, + contentDescription = "", + tint = textColor, + modifier = Modifier + .padding(start = 15.dp) + .size(25.dp) + .clickable { + navController.popBackStack() + } + ) + Row( modifier = Modifier - .fillMaxSize() - .background(appBackground) + .fillMaxWidth() + .offset(x = (-10).dp), + horizontalArrangement = Arrangement.Center ) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(top = 30.dp, start = 0.dp), - horizontalArrangement = Arrangement.Start - ) { - Icon( - imageVector = Icons.Filled.ArrowBackIos, - contentDescription = "", - tint = textColor, - modifier = Modifier - .padding(start = 15.dp) - .size(25.dp) - .clickable { - navController.popBackStack() - } + Text( + text = "Collect Waste", + color = textColor, + fontFamily = monteBold, + fontSize = 25.sp + ) + } + } + + val cList = listOf("List View", "Map View (Beta)") + var tabIndex by remember { mutableStateOf(0) } + Column( + modifier = Modifier + .fillMaxWidth() + .padding(start = 35.dp, end = 35.dp) + ) { + TabRow( + selectedTabIndex = tabIndex, + backgroundColor = appBackground, + contentColor = textColor, + divider = { + TabRowDefaults.Divider( + color = Color(0xFFF37952), + thickness = 1.dp ) - Row( - modifier = Modifier - .fillMaxWidth() - .offset(x = (-10).dp), - horizontalArrangement = Arrangement.Center - ) { + }, + ) { + cList.forEachIndexed { index, title -> + Tab(text = { Text( - text = "Collect Waste", - color = textColor, - fontFamily = monteBold, - fontSize = 25.sp + title, + softWrap = false, + fontSize = 13.sp, ) - } + }, + selected = tabIndex == index, + onClick = { tabIndex = index } + ) } - val cList = listOf("List View", "Map View (Beta)") - var tabIndex by remember { mutableStateOf(0) } - Column( - modifier = Modifier - .fillMaxWidth() - .padding(start = 35.dp, end = 35.dp) - ) { - TabRow( - selectedTabIndex = tabIndex, - backgroundColor = appBackground, - contentColor = textColor, - divider = { - TabRowDefaults.Divider( - color = Color(0xFFF37952), - thickness = 1.dp - ) - }, - ) { - cList.forEachIndexed { index, title -> - Tab(text = { - Text( - title, - softWrap = false, - fontSize = 13.sp, - ) - }, - selected = tabIndex == index, - onClick = { tabIndex = index } - ) - } + } + } + if (tabIndex == 0) { + Spacer(modifier = Modifier.height(30.dp)) + if (allWastes != null) { + LazyColumn( + contentPadding = PaddingValues( + bottom = 150.dp, + top = 40.dp + ) + ) { + allWastes = allWastes?.sortedBy { + distance( + viewModel.latitude, + viewModel.longitude, + it.latitude, + it.longitude + ) } - - } - if (tabIndex == 0) { - Spacer(modifier = Modifier.height(30.dp)) - if (allWastes != null) { - LazyColumn( - contentPadding = PaddingValues( - bottom = 150.dp, - top = 40.dp - ) + itemsIndexed(allWastes ?: emptyList()) { index, wasteItem -> + WasteItemCard( + locationNo = "Location ${index + 1}", + address = wasteItem.address, + distance = "${ + convertDistance( + distance( + viewModel.latitude, + viewModel.longitude, + wasteItem.latitude, + wasteItem.longitude + ) + ) + } away", + time = getTimeAgo(wasteItem.timeStamp), ) { - allWastes = allWastes?.sortedBy { - distance( - viewModel.latitude, - viewModel.longitude, - it.latitude, - it.longitude + viewModel.locationNo.value = "Location ${index + 1}" + viewModel.address.value = wasteItem.address + viewModel.distance.value = "${ + convertDistance( + distance( + viewModel.latitude, + viewModel.longitude, + wasteItem.latitude, + wasteItem.longitude + ) ) - } - itemsIndexed(allWastes ?: emptyList()) { index, wasteItem -> - WasteItemCard( - locationNo = "Location ${index + 1}", - address = wasteItem.address, - distance = "${ - convertDistance( - distance( - viewModel.latitude, - viewModel.longitude, - wasteItem.latitude, - wasteItem.longitude - ) - ) - } away", - time = getTimeAgo(wasteItem.timeStamp), - ) { - viewModel.locationNo.value = "Location ${index + 1}" - viewModel.address.value = wasteItem.address - viewModel.distance.value = "${ - convertDistance( - distance( - viewModel.latitude, - viewModel.longitude, - wasteItem.latitude, - wasteItem.longitude - ) - ) - } away" - viewModel.time.value = getTimeAgo(wasteItem.timeStamp) - viewModel.wastePhoto.value = wasteItem.imagePath - viewModel.theirLatitude.value = wasteItem.latitude - viewModel.theirLongitude.value = wasteItem.longitude - println("Collected time ${viewModel.time.value}") - navController.navigate(Screens.CollectWasteInfo.route) - } - - } + } away" + viewModel.time.value = getTimeAgo(wasteItem.timeStamp) + viewModel.wastePhoto.value = wasteItem.imagePath + viewModel.theirLatitude.value = wasteItem.latitude + viewModel.theirLongitude.value = wasteItem.longitude + println("Collected time ${viewModel.time.value}") + navController.navigate(Screens.CollectWasteInfo.route) } + } - } else { - MapScreen( - navController = navController, - viewModel = viewModel, - ) } - } - - + } else { + MapScreen( + paddingValues = paddingValues, + viewModel = viewModel, + ) } + } + + } } diff --git a/app/src/main/java/app/waste2wealth/com/collectwaste/SuccesfullyCollected.kt b/app/src/main/java/app/waste2wealth/com/collectwaste/SuccesfullyCollected.kt index a1f61fc..e30529a 100644 --- a/app/src/main/java/app/waste2wealth/com/collectwaste/SuccesfullyCollected.kt +++ b/app/src/main/java/app/waste2wealth/com/collectwaste/SuccesfullyCollected.kt @@ -187,22 +187,8 @@ fun SuccessfullyCollected( } } - PermissionDrawer( - drawerState = permissionDrawerState, - permissionState = permissionState, - rationaleText = "To continue, allow Waste2Wealth to access your device's camera" + - ". Tap Settings > Permission, and turn \"Access Camera On\" on.", - withoutRationaleText = "Camera permission required for this feature to be available." + - " Please grant the permission.", - model = R.drawable.camera, - gesturesEnabled = gesturesEnabled, - size = 100.dp - ) { - Scaffold(bottomBar = { - BottomBar(navController = navController) - }) { + Box(modifier = Modifier.fillMaxSize()) { - println(it) Column( modifier = Modifier .fillMaxSize() @@ -574,9 +560,6 @@ fun SuccessfullyCollected( } } } - } - -} fun countWords(text: String): Int { val words = text.trim().split("\\s+".toRegex()) diff --git a/app/src/main/java/app/waste2wealth/com/communities/ui/CommunitiesScreen.kt b/app/src/main/java/app/waste2wealth/com/communities/ui/CommunitiesScreen.kt index 179e5fd..dff0c8c 100644 --- a/app/src/main/java/app/waste2wealth/com/communities/ui/CommunitiesScreen.kt +++ b/app/src/main/java/app/waste2wealth/com/communities/ui/CommunitiesScreen.kt @@ -17,6 +17,7 @@ import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize @@ -64,21 +65,11 @@ import com.jet.firestore.getListOfObjects import app.waste2wealth.com.communities.CommunitiesViewModel import app.waste2wealth.com.profile.ProfileImage -@OptIn( - ExperimentalAnimationApi::class, ExperimentalMaterialApi::class, - ExperimentalPermissionsApi::class, ExperimentalComposeUiApi::class -) @Composable -fun CommunitiesSection(navController: NavController, email: String) { - val permissionState = rememberMultiplePermissionsState( - permissions = listOf( - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION - ) - ) - val permissionDrawerState = rememberBottomDrawerState( - if (permissionState.allPermissionsGranted) BottomDrawerValue.Closed else BottomDrawerValue.Open - ) +fun CommunitiesSection( + paddingValues: PaddingValues, + email: String +) { var profileList by remember { mutableStateOf?>(null) } @@ -129,189 +120,175 @@ fun CommunitiesSection(navController: NavController, email: String) { } } } - PermissionDrawer( - drawerState = permissionDrawerState, - permissionState = permissionState, - rationaleText = "To continue, allow Report Waste2Wealth to access your device's location" + - ". Tap Settings > Permission, and turn \"Access Location On\" on.", - withoutRationaleText = "Location permission required for functionality of this app." + - " Please grant the permission.", - ) { - Scaffold(bottomBar = { - BottomBar(navController = navController) - }) { - println(it) - var progress2 = remember { mutableStateOf(0f) } - val visible = - animateFloatAsState(if (progress2.value > 0.35f) 1f else 0f, label = "").value - val inVisible = - animateFloatAsState(if (progress2.value > 0.35f) 0f else 1f, label = "").value - val color by animateColorAsState( - targetValue = if (progress2.value >= 0.5f) - Color.Transparent else Color.Unspecified, - label = "" - ) + var progress2 = remember { mutableStateOf(0f) } + val visible = + animateFloatAsState(if (progress2.value > 0.35f) 1f else 0f, label = "").value + val inVisible = + animateFloatAsState(if (progress2.value > 0.35f) 0f else 1f, label = "").value + val color by animateColorAsState( + targetValue = if (progress2.value >= 0.5f) + Color.Transparent else Color.Unspecified, + label = "" + ) - val viewModel: CommunitiesViewModel = remember { CommunitiesViewModel() } - Column( + val viewModel: CommunitiesViewModel = remember { CommunitiesViewModel() } + Column( + modifier = Modifier + .background(appBackground) + ) { + AnimatedVisibility( + visible = viewModel.expandedState.value < 0.5f, + enter = expandVertically(tween(400)) + fadeIn(tween(400)), + exit = shrinkVertically(tween(400)) + fadeOut(tween(400)), + modifier = Modifier.background(Color.Transparent) + ) { + Row( modifier = Modifier - .background(appBackground) + .fillMaxWidth() + .padding( + top = 35.dp, + bottom = 35.dp, + start = 20.dp, + end = 20.dp + ), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically ) { + Text( + text = "Community", + color = textColor, + fontSize = 35.sp, + fontFamily = monteBold, + ) + Row( + modifier = Modifier + .fillMaxWidth() + .padding(top = 15.dp, end = 0.dp, start = 20.dp), + horizontalArrangement = Arrangement.End, + verticalAlignment = Alignment.CenterVertically + ) { + Row( + modifier = Modifier.padding(end = 25.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.End + ) { + Icon( + painter = painterResource(id = R.drawable.coins), + contentDescription = "coins", + modifier = Modifier + .size(40.dp) + .padding(end = 5.dp), + tint = Color.Unspecified + ) + Text( + text = pointsEarned.toString(), + color = textColor, + fontSize = 15.sp, + softWrap = true, + fontFamily = monteNormal, + ) + } + + } + } + } + AnimatedVisibility( + visible = viewModel.expandedState.value > 0.5f, + enter = expandVertically() + fadeIn(), + exit = shrinkVertically() + fadeOut(), + modifier = Modifier.background(Color.Transparent) + ) { + if (progress2.value > 0.5f) { AnimatedVisibility( - visible = viewModel.expandedState.value < 0.5f, - enter = expandVertically(tween(400)) + fadeIn(tween(400)), - exit = shrinkVertically(tween(400)) + fadeOut(tween(400)), - modifier = Modifier.background(Color.Transparent) + visible = visible > 0f, + enter = fadeIn() + slideInHorizontally(), + exit = fadeOut() + slideOutHorizontally(), ) { Row( modifier = Modifier .fillMaxWidth() .padding( - top = 35.dp, - bottom = 35.dp, - start = 20.dp, - end = 20.dp - ), + top = 30.dp, + end = 25.dp + ) + .graphicsLayer { + alpha = visible + }, horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { - Text( - text = "Community", - color = textColor, - fontSize = 35.sp, - fontFamily = monteBold, - ) - Row( + Card( + backgroundColor = + communitiesItems[viewModel.currentPage.value].cardColor, + border = BorderStroke( + width = 4.dp, color = communitiesItems[0].borderColor + ), + shape = RoundedCornerShape(30.dp), modifier = Modifier - .fillMaxWidth() - .padding(top = 15.dp, end = 0.dp, start = 20.dp), - horizontalArrangement = Arrangement.End, - verticalAlignment = Alignment.CenterVertically + .width(160.dp) + .height(100.dp) ) { - Row( - modifier = Modifier.padding(end = 25.dp), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.End - ) { - Icon( - painter = painterResource(id = R.drawable.coins), - contentDescription = "coins", - modifier = Modifier - .size(40.dp) - .padding(end = 5.dp), - tint = Color.Unspecified - ) - Text( - text = pointsEarned.toString(), - color = textColor, - fontSize = 15.sp, - softWrap = true, - fontFamily = monteNormal, - ) - } - + ProfileImage( + imageUrl = communitiesItems[viewModel.currentPage.value].image, + modifier = Modifier + .fillMaxSize() + .clip(RoundedCornerShape(30.dp)), + ) } + Text( + text = communitiesItems[viewModel.currentPage.value].title, + fontSize = 21.sp, + fontWeight = FontWeight.Bold, + softWrap = true, + modifier = Modifier.padding(start = 0.dp), + color = textColor, + + ) + } } - AnimatedVisibility( - visible = viewModel.expandedState.value > 0.5f, - enter = expandVertically() + fadeIn(), - exit = shrinkVertically() + fadeOut(), - modifier = Modifier.background(Color.Transparent) - ) { - if (progress2.value > 0.5f) { - AnimatedVisibility( - visible = visible > 0f, - enter = fadeIn() + slideInHorizontally(), - exit = fadeOut() + slideOutHorizontally(), - ) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding( - top = 30.dp, - end = 25.dp - ) - .graphicsLayer { - alpha = visible - }, - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Card( - backgroundColor = - communitiesItems[viewModel.currentPage.value].cardColor, - border = BorderStroke( - width = 4.dp, color = communitiesItems[0].borderColor - ), - shape = RoundedCornerShape(30.dp), - modifier = Modifier - .width(160.dp) - .height(100.dp) - ) { - ProfileImage( - imageUrl = communitiesItems[viewModel.currentPage.value].image, - modifier = Modifier - .fillMaxSize() - .clip(RoundedCornerShape(30.dp)), - ) - } - Text( - text = communitiesItems[viewModel.currentPage.value].title, - fontSize = 21.sp, - fontWeight = FontWeight.Bold, - softWrap = true, - modifier = Modifier.padding(start = 0.dp), - color = textColor, - - ) - } - } + } else { + Column( + modifier = Modifier + .fillMaxWidth() - } else { - Column( + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding( + top = 30.dp, + start = 10.dp, + end = 25.dp + ), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Text( + text = communitiesItems[viewModel.currentPage.value].title, + fontSize = 25.sp, + fontWeight = FontWeight.Bold, + softWrap = true, modifier = Modifier - .fillMaxWidth() - - ) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding( - top = 30.dp, - start = 10.dp, - end = 25.dp - ), - horizontalArrangement = Arrangement.SpaceBetween - ) { - Text( - text = communitiesItems[viewModel.currentPage.value].title, - fontSize = 25.sp, - fontWeight = FontWeight.Bold, - softWrap = true, - modifier = Modifier - .graphicsLayer { - alpha = inVisible - }, - color = textColor, + .graphicsLayer { + alpha = inVisible + }, + color = textColor, - ) + ) - } - Spacer(modifier = Modifier.height(20.dp)) - } } - + Spacer(modifier = Modifier.height(20.dp)) } - Pager2(viewModel, progress2, it) } - Log.i("ExpandedState", "HomeScreen: ${viewModel.expandedState.value}") } + Pager2(viewModel, progress2, paddingValues) } + Log.i("ExpandedState", "HomeScreen: ${viewModel.expandedState.value}") + } } diff --git a/app/src/main/java/app/waste2wealth/com/dashboard/NewDashboard.kt b/app/src/main/java/app/waste2wealth/com/dashboard/NewDashboard.kt index 12d757d..358a864 100644 --- a/app/src/main/java/app/waste2wealth/com/dashboard/NewDashboard.kt +++ b/app/src/main/java/app/waste2wealth/com/dashboard/NewDashboard.kt @@ -156,419 +156,406 @@ fun NewDashboard( } } } - PermissionDrawer( - drawerState = permissionDrawerState, - permissionState = permissionState, - rationaleText = "To continue, allow Report Waste2Wealth to access your device's location" + - ". Tap Settings > Permission, and turn \"Access Location On\" on.", - withoutRationaleText = "Location permission required for functionality of this app." + - " Please grant the permission.", + Column( + modifier = Modifier + .fillMaxSize() + .background(appBackground) ) { - Scaffold(bottomBar = { - BottomBar(navController = navController) - }) { - println(it) - Column( - modifier = Modifier - .fillMaxSize() - .background(appBackground) + Card( + modifier = Modifier + .clip(RoundedCornerShape(0.dp, 0.dp, 50.dp, 50.dp)) + .fillMaxWidth(), + backgroundColor = CardColor, + ) { - Card( + Column { + Row( modifier = Modifier - .clip(RoundedCornerShape(0.dp, 0.dp, 50.dp, 50.dp)) - .fillMaxWidth(), - backgroundColor = CardColor, - - ) { + .fillMaxWidth() + .padding( + top = 45.dp, + bottom = 15.dp, + end = 25.dp, + start = 25.dp + ), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { Column { - Row( + Text( + text = "Welcome Back", + color = Color.Gray, + fontSize = 13.sp, + fontFamily = monteSB, + modifier = Modifier.padding(bottom = 7.dp) + ) + Text( + text = name, + color = CardTextColor, + fontSize = 20.sp, + fontFamily = monteBold, + modifier = Modifier.padding(bottom = 7.dp) + ) + Text( + text = "Start making a difference today!", + color = Color.Gray, + fontSize = 13.sp, + fontFamily = monteSB, + modifier = Modifier.padding(bottom = 7.dp) + ) + } + ProfileImage( + imageUrl = pfp, + modifier = Modifier + .size(70.dp) + .border( + width = 1.dp, + color = textColor, + shape = CircleShape + ) + .padding(2.dp) + .clip(CircleShape) + .clickable { + navController.navigate(Screens.Profile.route) + } + ) + } + LazyVerticalGrid( + columns = GridCells.Fixed(2), + modifier = Modifier + .fillMaxWidth() + .padding(bottom = 20.dp) + ) { + item { + Column( modifier = Modifier - .fillMaxWidth() - .padding( - top = 45.dp, - bottom = 15.dp, - end = 25.dp, - start = 25.dp - ), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically + .padding(top = 15.dp) + .offset(x = (-15).dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center ) { - Column { - Text( - text = "Welcome Back", - color = Color.Gray, - fontSize = 13.sp, - fontFamily = monteSB, - modifier = Modifier.padding(bottom = 7.dp) + Text( + text = "Points Earned", + color = CardTextColor, + fontSize = 14.sp, + fontFamily = monteBold, + softWrap = true, + modifier = Modifier.padding(start = 7.dp) + ) + Row(modifier = Modifier.padding(end = 0.dp, top = 7.dp)) { + Icon( + painter = painterResource(id = R.drawable.coins), + contentDescription = "coins", + modifier = Modifier + .size(20.dp) + .padding(end = 5.dp), + tint = Color.Unspecified ) Text( - text = name, + text = pointsEarned, color = CardTextColor, - fontSize = 20.sp, - fontFamily = monteBold, - modifier = Modifier.padding(bottom = 7.dp) - ) - Text( - text = "Start making a difference today!", - color = Color.Gray, - fontSize = 13.sp, - fontFamily = monteSB, - modifier = Modifier.padding(bottom = 7.dp) + fontSize = 15.sp, + fontFamily = monteNormal, ) } - ProfileImage( - imageUrl = pfp, - modifier = Modifier - .size(70.dp) - .border( - width = 1.dp, - color = textColor, - shape = CircleShape - ) - .padding(2.dp) - .clip(CircleShape) - .clickable { - navController.navigate(Screens.Profile.route) - } - ) + } - LazyVerticalGrid( - columns = GridCells.Fixed(2), + } + item { + Column( modifier = Modifier - .fillMaxWidth() - .padding(bottom = 20.dp) + .padding(top = 15.dp) + .offset(x = (-15).dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center ) { - item { - Column( + Text( + text = "Points Redeemed", + color = CardTextColor, + fontSize = 14.sp, + fontFamily = monteBold, + softWrap = true, + modifier = Modifier.padding(start = 7.dp) + ) + Row(modifier = Modifier.padding(end = 0.dp, top = 7.dp)) { + Icon( + painter = painterResource(id = R.drawable.coins), + contentDescription = "coins", modifier = Modifier - .padding(top = 15.dp) - .offset(x = (-15).dp), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Center - ) { - Text( - text = "Points Earned", - color = CardTextColor, - fontSize = 14.sp, - fontFamily = monteBold, - softWrap = true, - modifier = Modifier.padding(start = 7.dp) - ) - Row(modifier = Modifier.padding(end = 0.dp, top = 7.dp)) { - Icon( - painter = painterResource(id = R.drawable.coins), - contentDescription = "coins", - modifier = Modifier - .size(20.dp) - .padding(end = 5.dp), - tint = Color.Unspecified - ) - Text( - text = pointsEarned, - color = CardTextColor, - fontSize = 15.sp, - fontFamily = monteNormal, - ) - } - - } + .size(20.dp) + .padding(end = 5.dp), + tint = Color.Unspecified + ) + Text( + text = pointsRedeemed, + color = CardTextColor, + fontSize = 15.sp, + fontFamily = monteNormal, + ) } - item { - Column( - modifier = Modifier - .padding(top = 15.dp) - .offset(x = (-15).dp), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Center - ) { - Text( - text = "Points Redeemed", - color = CardTextColor, - fontSize = 14.sp, - fontFamily = monteBold, - softWrap = true, - modifier = Modifier.padding(start = 7.dp) - ) - Row(modifier = Modifier.padding(end = 0.dp, top = 7.dp)) { - Icon( - painter = painterResource(id = R.drawable.coins), - contentDescription = "coins", - modifier = Modifier - .size(20.dp) - .padding(end = 5.dp), - tint = Color.Unspecified - ) - Text( - text = pointsRedeemed, - color = CardTextColor, - fontSize = 15.sp, - fontFamily = monteNormal, - ) - } - } - } } - Spacer(modifier = Modifier.height(15.dp)) } } + Spacer(modifier = Modifier.height(15.dp)) + } + } - Spacer(modifier = Modifier.height(20.dp)) + Spacer(modifier = Modifier.height(20.dp)) - Row( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 10.dp), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Column(horizontalAlignment = Alignment.Start) { - Text( - text = "Current Progress", - color = textColor, - fontSize = 20.sp, - fontFamily = monteBold, - modifier = Modifier.padding(bottom = 7.dp) - ) - Text( - text = "200 more points to reach weekly target", - color = textColor, - fontSize = 9.sp, - fontFamily = monteBold, - modifier = Modifier.padding(start = 0.dp) - ) - } + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 10.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Column(horizontalAlignment = Alignment.Start) { + Text( + text = "Current Progress", + color = textColor, + fontSize = 20.sp, + fontFamily = monteBold, + modifier = Modifier.padding(bottom = 7.dp) + ) + Text( + text = "200 more points to reach weekly target", + color = textColor, + fontSize = 9.sp, + fontFamily = monteBold, + modifier = Modifier.padding(start = 0.dp) + ) + } - ArcComposable( - modifier = Modifier.padding(end = 25.dp), - text = "50%" - ) - } + ArcComposable( + modifier = Modifier.padding(end = 25.dp), + text = "50%" + ) + } - Spacer(modifier = Modifier.height(20.dp)) + Spacer(modifier = Modifier.height(20.dp)) - Row( - modifier = Modifier - .padding(horizontal = 40.dp) - .fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceEvenly + Row( + modifier = Modifier + .padding(horizontal = 40.dp) + .fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceEvenly + ) { + Card( + modifier = Modifier + .padding(5.dp), + backgroundColor = Color.Transparent, + elevation = 0.dp + ) { + Column( + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally ) { - Card( + ProfileImage( + imageUrl = R.drawable.ic_reportwaste, modifier = Modifier - .padding(5.dp), - backgroundColor = Color.Transparent, - elevation = 0.dp - ) { - Column( - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - ProfileImage( - imageUrl = R.drawable.ic_reportwaste, - modifier = Modifier - .size(70.dp) - .border( - width = 1.dp, - color = textColor, - shape = CircleShape - ) - .padding(2.dp) - .clip(CircleShape) - .clickable { - navController.navigate(Screens.ReportWaste.route) - } - ) - Spacer(modifier = Modifier.height(5.dp)) - Text( - text = "Report Waste", + .size(70.dp) + .border( + width = 1.dp, color = textColor, - fontSize = 13.sp, - fontFamily = monteNormal, - softWrap = true + shape = CircleShape ) - } - } + .padding(2.dp) + .clip(CircleShape) + .clickable { + navController.navigate(Screens.ReportWaste.route) + } + ) + Spacer(modifier = Modifier.height(5.dp)) + Text( + text = "Report Waste", + color = textColor, + fontSize = 13.sp, + fontFamily = monteNormal, + softWrap = true + ) + } + } - Card( + Card( + modifier = Modifier + .padding(5.dp), + backgroundColor = Color.Transparent, + elevation = 0.dp + ) { + Column( + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + ProfileImage( + imageUrl = R.drawable.ic_collectwaste, modifier = Modifier - .padding(5.dp), - backgroundColor = Color.Transparent, - elevation = 0.dp - ) { - Column( - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - ProfileImage( - imageUrl = R.drawable.ic_collectwaste, - modifier = Modifier - .size(70.dp) - .border( - width = 1.dp, - color = textColor, - shape = CircleShape - ) - .padding(2.dp) - .clip(CircleShape) - .clickable { - navController.navigate(Screens.CollectWasteLists.route) - } - ) - Spacer(modifier = Modifier.height(5.dp)) - Text( - text = "Collect Waste", + .size(70.dp) + .border( + width = 1.dp, color = textColor, - fontSize = 13.sp, - fontFamily = monteNormal, - softWrap = true + shape = CircleShape ) - } - } + .padding(2.dp) + .clip(CircleShape) + .clickable { + navController.navigate(Screens.CollectWasteLists.route) + } + ) + Spacer(modifier = Modifier.height(5.dp)) + Text( + text = "Collect Waste", + color = textColor, + fontSize = 13.sp, + fontFamily = monteNormal, + softWrap = true + ) + } + } - Card( + Card( + modifier = Modifier + .padding(5.dp), + backgroundColor = Color.Transparent, + elevation = 0.dp + ) { + Column( + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + ProfileImage( + imageUrl = R.drawable.ic_rewards, modifier = Modifier - .padding(5.dp), - backgroundColor = Color.Transparent, - elevation = 0.dp - ) { - Column( - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - ProfileImage( - imageUrl = R.drawable.ic_rewards, - modifier = Modifier - .size(70.dp) - .border( - width = 1.dp, - color = textColor, - shape = CircleShape - ) - .padding(2.dp) - .clip(CircleShape) - .clickable { - navController.navigate(Screens.Rewards.route) - } - ) - Spacer(modifier = Modifier.height(5.dp)) - Text( - text = "Rewards", + .size(70.dp) + .border( + width = 1.dp, color = textColor, - fontSize = 13.sp, - fontFamily = monteNormal, - softWrap = true + shape = CircleShape ) - } - } - + .padding(2.dp) + .clip(CircleShape) + .clickable { + navController.navigate(Screens.Rewards.route) + } + ) + Spacer(modifier = Modifier.height(5.dp)) + Text( + text = "Rewards", + color = textColor, + fontSize = 13.sp, + fontFamily = monteNormal, + softWrap = true + ) } + } + } - Spacer(modifier = Modifier.height(20.dp)) + Spacer(modifier = Modifier.height(20.dp)) - Row( - modifier = Modifier - .fillMaxWidth() - .padding(start = 20.dp, end = 25.dp), - horizontalArrangement = Arrangement.SpaceBetween - ) { - Text( - text = "Upcoming Community Events", - color = textColor, - fontSize = 15.sp) - Text( - text = "All Events", - color = textColor, - fontSize = 15.sp, - modifier = Modifier.clickable { - navController.navigate(Screens.Community.route) - } - ) + Row( + modifier = Modifier + .fillMaxWidth() + .padding(start = 20.dp, end = 25.dp), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Text( + text = "Upcoming Community Events", + color = textColor, + fontSize = 15.sp + ) + + Text( + text = "All Events", + color = textColor, + fontSize = 15.sp, + modifier = Modifier.clickable { + navController.navigate(Screens.Community.route) } + ) + } - LazyRow(contentPadding = PaddingValues(10.dp)) { - items(communitiesItems.take(3)) { item -> - Card( + LazyRow(contentPadding = PaddingValues(10.dp)) { + items(communitiesItems.take(3)) { item -> + Card( + modifier = Modifier + .width(300.dp) + .height(200.dp) + .padding(end = 10.dp), + shape = RoundedCornerShape(10.dp), + elevation = 10.dp, + backgroundColor = CardColor + ) { + Row( + modifier = Modifier.fillMaxSize(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center + ) { + ProfileImage( + imageUrl = item.image, modifier = Modifier - .width(300.dp) - .height(200.dp) - .padding(end = 10.dp), - shape = RoundedCornerShape(10.dp), - elevation = 10.dp, - backgroundColor = CardColor - ) { - Row( - modifier = Modifier.fillMaxSize(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.Center - ) { - ProfileImage( - imageUrl = item.image, - modifier = Modifier - .fillMaxWidth(0.5f) - .fillMaxHeight() + .fillMaxWidth(0.5f) + .fillMaxHeight() + ) + Spacer(modifier = Modifier.width(10.dp)) + Column(modifier = Modifier.fillMaxWidth()) { + Spacer(modifier = Modifier.height(10.dp)) + Text( + text = item.title, + color = CardTextColor, + fontSize = 20.sp, + fontWeight = FontWeight.Bold, + softWrap = true + ) + Spacer(modifier = Modifier.height(10.dp)) + Text( + text = item.time, + color = CardTextColor, + fontSize = 10.sp, + fontWeight = FontWeight.Normal + ) + Spacer(modifier = Modifier.height(10.dp)) + Button( + onClick = { + + }, + shape = RoundedCornerShape(10.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = appBackground ) - Spacer(modifier = Modifier.width(10.dp)) - Column(modifier = Modifier.fillMaxWidth()) { - Spacer(modifier = Modifier.height(10.dp)) - Text( - text = item.title, - color = CardTextColor, - fontSize = 20.sp, - fontWeight = FontWeight.Bold, - softWrap = true + ) { + Row(verticalAlignment = Alignment.CenterVertically) { + Icon( + imageVector = Icons.Filled.LocationOn, + contentDescription = null, + modifier = Modifier.size(20.dp), + tint = CardColor ) - Spacer(modifier = Modifier.height(10.dp)) + Spacer(modifier = Modifier.width(10.dp)) Text( - text = item.time, - color = CardTextColor, + text = "Register", + color = textColor, fontSize = 10.sp, fontWeight = FontWeight.Normal ) - Spacer(modifier = Modifier.height(10.dp)) - Button( - onClick = { - - }, - shape = RoundedCornerShape(10.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = appBackground - ) - ) { - Row(verticalAlignment = Alignment.CenterVertically) { - Icon( - imageVector = Icons.Filled.LocationOn, - contentDescription = null, - modifier = Modifier.size(20.dp), - tint = CardColor - ) - Spacer(modifier = Modifier.width(10.dp)) - Text( - text = "Register", - color = textColor, - fontSize = 10.sp, - fontWeight = FontWeight.Normal - ) - } - } } - Spacer(modifier = Modifier.width(10.dp)) } } + Spacer(modifier = Modifier.width(10.dp)) } - } - - Spacer(modifier = Modifier.height(100.dp)) - } + } + + Spacer(modifier = Modifier.height(100.dp)) + } } } diff --git a/app/src/main/java/app/waste2wealth/com/maps/MapsScreen.kt b/app/src/main/java/app/waste2wealth/com/maps/MapsScreen.kt index d662813..927e6af 100644 --- a/app/src/main/java/app/waste2wealth/com/maps/MapsScreen.kt +++ b/app/src/main/java/app/waste2wealth/com/maps/MapsScreen.kt @@ -66,11 +66,10 @@ import com.mapbox.geojson.* @OptIn( ExperimentalMaterialApi::class, ExperimentalPermissionsApi::class, - ExperimentalComposeUiApi::class ) @Composable -fun MapScreen(viewModel: LocationViewModel, navController: NavController) { - LaunchedEffect(key1 = Unit){ +fun MapScreen(viewModel: LocationViewModel, paddingValues: PaddingValues) { + LaunchedEffect(key1 = Unit) { viewModel.getPlaces() } @@ -109,181 +108,165 @@ fun MapScreen(viewModel: LocationViewModel, navController: NavController) { LaunchedEffect(key1 = Unit) { viewModel.getPlaces() } - PermissionDrawer( - drawerState = permissionDrawerState, - permissionState = permissionState, - rationaleText = "To continue, allow Waste2Wealth to access your device's camera" + - ". Tap Settings > Permission, and turn \"Access Camera On\" on.", - withoutRationaleText = "Camera permission required for this feature to be available." + - " Please grant the permission.", - model = R.drawable.camera, - gesturesEnabled = gesturesEnabled, - size = 100.dp - ) { - Scaffold(bottomBar = { - BottomBar(navController = navController) - }) { - JetFirestore(path = { - collection("AllWastes") - }, onRealtimeCollectionFetch = { values, _ -> - allWastes = values?.getListOfObjects() - }) { - println(it) - Box(modifier = Modifier.fillMaxSize()) { - Column( - modifier = Modifier.fillMaxSize(), + JetFirestore(path = { + collection("AllWastes") + }, onRealtimeCollectionFetch = { values, _ -> + allWastes = values?.getListOfObjects() + + }) { + Box(modifier = Modifier.fillMaxSize()) { + Column( + modifier = Modifier.fillMaxSize(), + ) { + if (mapsItems != null) { + MapBoxMap( + onPointChange = { point = it }, + modifier = Modifier + .fillMaxSize(), + isClicked = isClicked, + points = mapsItems, + currentPoint = currentPoint, + isReset = isReset, + currentLocation = Point.fromLngLat( + viewModel.longitude, viewModel.latitude + ) + ) + } + } + AnimatedVisibility( + visible = !isClicked.value, + enter = slideInVertically(tween(1000), initialOffsetY = { + it + }), + exit = slideOutVertically(tween(1000), targetOffsetY = { + it + }) + ) { + Box( + modifier = Modifier.fillMaxSize(), + contentAlignment = Alignment.BottomCenter + ) { + LazyRow( + modifier = Modifier.fillMaxWidth(), + contentPadding = PaddingValues(30.dp) ) { - if (mapsItems != null) { - MapBoxMap( - onPointChange = { point = it }, + items(mapsItems ?: emptyList()) { item -> + Card( modifier = Modifier - .fillMaxSize(), - isClicked = isClicked, - points = mapsItems, - currentPoint = currentPoint, - isReset = isReset, - currentLocation = Point.fromLngLat( - viewModel.longitude, viewModel.latitude - ) - ) - } - } - AnimatedVisibility( - visible = !isClicked.value, - enter = slideInVertically(tween(1000), initialOffsetY = { - it - }), - exit = slideOutVertically(tween(1000), targetOffsetY = { - it - }) - ) { - Box( - modifier = Modifier.fillMaxSize(), - contentAlignment = Alignment.BottomCenter - ) { - LazyRow( - modifier = Modifier.fillMaxWidth(), - contentPadding = PaddingValues(30.dp) + .width(300.dp) + .height(230.dp) + .padding( + end = 10.dp, bottom = + paddingValues.calculateBottomPadding() + 10.dp + ), + shape = RoundedCornerShape(10.dp), + elevation = 10.dp, + backgroundColor = appBackground ) { - items(mapsItems ?: emptyList()) { item -> - Card( - modifier = Modifier - .width(300.dp) - .height(230.dp) - .padding( - end = 10.dp, bottom = - it.calculateBottomPadding() + 10.dp - ), - shape = RoundedCornerShape(10.dp), - elevation = 10.dp, - backgroundColor = appBackground - ) { + Row( + modifier = Modifier + .fillMaxSize() + .padding(horizontal = 10.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center + ) { + Column(modifier = Modifier.fillMaxWidth()) { + Spacer(modifier = Modifier.height(10.dp)) + Text( + text = item.location, + color = textColor, + fontSize = 15.sp, + fontWeight = FontWeight.Bold, + maxLines = 2, + overflow = TextOverflow.Ellipsis, + softWrap = true + ) + Spacer(modifier = Modifier.height(10.dp)) Row( modifier = Modifier - .fillMaxSize() - .padding(horizontal = 10.dp), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.Center + .fillMaxWidth() + .padding(end = 10.dp), + horizontalArrangement = Arrangement.End ) { - Column(modifier = Modifier.fillMaxWidth()) { - Spacer(modifier = Modifier.height(10.dp)) + Text( + text = getTimeAgo(item.time), + color = textColor, + fontSize = 10.sp, + fontWeight = FontWeight.Normal, + ) + } + Spacer(modifier = Modifier.height(10.dp)) + Button( + onClick = { + isReset.value = false + isClicked.value = true + currentPoint.value = item.point + }, + shape = RoundedCornerShape(10.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = appBackground, + ) + ) { + Row(verticalAlignment = Alignment.CenterVertically) { + Icon( + imageVector = Icons.Filled.LocationOn, + contentDescription = null, + modifier = Modifier.size(20.dp), + tint = textColor + ) + Spacer(modifier = Modifier.width(10.dp)) Text( - text = item.location, + text = "Navigate", color = textColor, - fontSize = 15.sp, - fontWeight = FontWeight.Bold, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - softWrap = true + fontSize = 10.sp, + fontWeight = FontWeight.Normal ) - Spacer(modifier = Modifier.height(10.dp)) - Row( - modifier = Modifier - .fillMaxWidth() - .padding(end = 10.dp), - horizontalArrangement = Arrangement.End - ) { - Text( - text = getTimeAgo(item.time), - color = textColor, - fontSize = 10.sp, - fontWeight = FontWeight.Normal, - ) - } - Spacer(modifier = Modifier.height(10.dp)) - Button( - onClick = { - isReset.value = false - isClicked.value = true - currentPoint.value = item.point - }, - shape = RoundedCornerShape(10.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = appBackground, - ) - ) { - Row(verticalAlignment = Alignment.CenterVertically) { - Icon( - imageVector = Icons.Filled.LocationOn, - contentDescription = null, - modifier = Modifier.size(20.dp), - tint = textColor - ) - Spacer(modifier = Modifier.width(10.dp)) - Text( - text = "Navigate", - color = textColor, - fontSize = 10.sp, - fontWeight = FontWeight.Normal - ) - } - } } - Spacer(modifier = Modifier.width(10.dp)) } } + Spacer(modifier = Modifier.width(10.dp)) } - } } + } } - Box( - modifier = Modifier - .fillMaxSize() - .padding(horizontal = 10.dp, vertical = 25.dp), - contentAlignment = Alignment.TopEnd - ) { - Card( - modifier = Modifier - .padding(end = 10.dp), - shape = RoundedCornerShape(10.dp), - elevation = 10.dp - ) { - Button( - onClick = { - isReset.value = true - isClicked.value = false - - }, - shape = RoundedCornerShape(10.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = CardColor, - contentColor = CardTextColor - ) - ) { - Text( - text = "Reset", - color = CardTextColor, - fontSize = 10.sp, - fontWeight = FontWeight.Normal - ) - } + } + } + Box( + modifier = Modifier + .fillMaxSize() + .padding(horizontal = 10.dp, vertical = 25.dp), + contentAlignment = Alignment.TopEnd + ) { + Card( + modifier = Modifier + .padding(end = 10.dp), + shape = RoundedCornerShape(10.dp), + elevation = 10.dp + ) { + Button( + onClick = { + isReset.value = true + isClicked.value = false - } + }, + shape = RoundedCornerShape(10.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = CardColor, + contentColor = CardTextColor + ) + ) { + Text( + text = "Reset", + color = CardTextColor, + fontSize = 10.sp, + fontWeight = FontWeight.Normal + ) } + } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/waste2wealth/com/navigation/NavigationController.kt b/app/src/main/java/app/waste2wealth/com/navigation/NavigationController.kt index 5b885f1..08d82bc 100644 --- a/app/src/main/java/app/waste2wealth/com/navigation/NavigationController.kt +++ b/app/src/main/java/app/waste2wealth/com/navigation/NavigationController.kt @@ -6,6 +6,7 @@ import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.slideInHorizontally import androidx.compose.animation.slideOutHorizontally +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.ScaffoldState import androidx.compose.runtime.Composable @@ -49,7 +50,8 @@ import com.google.accompanist.navigation.animation.composable fun NavigationController( scaffoldState: ScaffoldState, locationViewModel: LocationViewModel, - navController: NavHostController + navController: NavHostController, + paddingValues: PaddingValues ) { val viewModel: LocationViewModel = hiltViewModel() val context = LocalContext.current @@ -151,7 +153,7 @@ fun NavigationController( } composable(Screens.Community.route) { CommunitiesSection( - navController = navController, + paddingValues = paddingValues, email = email.value ) } @@ -164,7 +166,7 @@ fun NavigationController( ) } composable(Screens.CollectWasteLists.route) { - CollectWaste(navController = navController, viewModel = viewModel) + CollectWaste(navController = navController, viewModel = viewModel, paddingValues = paddingValues) } composable(Screens.CollectWasteInfo.route) { CollectWasteInfo(navController = navController, viewModel = viewModel) diff --git a/app/src/main/java/app/waste2wealth/com/profile/NewProfileScreen.kt b/app/src/main/java/app/waste2wealth/com/profile/NewProfileScreen.kt index 29e80d3..237c047 100644 --- a/app/src/main/java/app/waste2wealth/com/profile/NewProfileScreen.kt +++ b/app/src/main/java/app/waste2wealth/com/profile/NewProfileScreen.kt @@ -98,176 +98,164 @@ fun NewProfileScreen( .requestEmail().requestProfile() .build() val googleSignInClient = GoogleSignIn.getClient(context, gso) - PermissionDrawer( - drawerState = permissionDrawerState, - permissionState = permissionState, - rationaleText = "To continue, allow Report Waste2Wealth to access your device's location" + - ". Tap Settings > Permission, and turn \"Access Location On\" on.", - withoutRationaleText = "Location permission required for functionality of this app." + - " Please grant the permission.", + + Column( + modifier = Modifier + .fillMaxSize() + .background(appBackground) ) { - Scaffold(bottomBar = { - BottomBar(navController = navController) + var profileList by remember { + mutableStateOf?>(null) + } + var myPhoneNumber by remember { + mutableStateOf("") + } + JetFirestore(path = { + collection("ProfileInfo") + }, onRealtimeCollectionFetch = { value, _ -> + profileList = value?.getListOfObjects() }) { - println(it) - Column( - modifier = Modifier - .fillMaxSize() - .background(appBackground) - ) { - var profileList by remember { - mutableStateOf?>(null) - } - var myPhoneNumber by remember { - mutableStateOf("") - } - JetFirestore(path = { - collection("ProfileInfo") - }, onRealtimeCollectionFetch = { value, _ -> - profileList = value?.getListOfObjects() - }) { - if (profileList != null) { - for (i in profileList!!) { - if (i.email == email) { - myPhoneNumber = i.phoneNumber ?: "" - } - } + if (profileList != null) { + for (i in profileList!!) { + if (i.email == email) { + myPhoneNumber = i.phoneNumber ?: "" } + } + } - Row( - modifier = Modifier - .fillMaxWidth() - .padding(top = 35.dp, bottom = 7.dp), - horizontalArrangement = Arrangement.Center - ) { - ProfileImage( - imageUrl = pfp, - modifier = Modifier - .size(100.dp) - .border( - width = 1.dp, - color = appBackground, - shape = CircleShape - ) - .padding(3.dp) - .clip(CircleShape), - ) - } - Row( - modifier = Modifier - .fillMaxWidth() - .padding(bottom = 7.dp), - horizontalArrangement = Arrangement.Center - ) { - Text( - text = name ?: "User Name", - color = textColor, - fontSize = 20.sp, - fontFamily = monteBold, - ) - } - Row( - modifier = Modifier - .fillMaxWidth() - .padding(bottom = 7.dp), - horizontalArrangement = Arrangement.Center - ) { - Text( - text = "${email ?: "User Email"} | $myPhoneNumber", - color = textColor, - fontSize = 12.sp, - fontFamily = monteSB, - softWrap = true, - modifier = Modifier.padding(end = 7.dp) + Row( + modifier = Modifier + .fillMaxWidth() + .padding(top = 35.dp, bottom = 7.dp), + horizontalArrangement = Arrangement.Center + ) { + ProfileImage( + imageUrl = pfp, + modifier = Modifier + .size(100.dp) + .border( + width = 1.dp, + color = appBackground, + shape = CircleShape ) - } - Spacer(modifier = Modifier.height(30.dp)) + .padding(3.dp) + .clip(CircleShape), + ) + } + Row( + modifier = Modifier + .fillMaxWidth() + .padding(bottom = 7.dp), + horizontalArrangement = Arrangement.Center + ) { + Text( + text = name ?: "User Name", + color = textColor, + fontSize = 20.sp, + fontFamily = monteBold, + ) + } + Row( + modifier = Modifier + .fillMaxWidth() + .padding(bottom = 7.dp), + horizontalArrangement = Arrangement.Center + ) { + Text( + text = "${email ?: "User Email"} | $myPhoneNumber", + color = textColor, + fontSize = 12.sp, + fontFamily = monteSB, + softWrap = true, + modifier = Modifier.padding(end = 7.dp) + ) + } + Spacer(modifier = Modifier.height(30.dp)) - Card( - backgroundColor = appBackground, - elevation = 10.dp, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 20.dp) - ) { - Column { + Card( + backgroundColor = appBackground, + elevation = 10.dp, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp) + ) { + Column { - RepeatedProfileInfo( - icon = Icons.Filled.EditNote, - text = "Edit Profile" - ) - RepeatedProfileInfo( - icon = Icons.Filled.Notifications, - text = "Notifications" - ) - } + RepeatedProfileInfo( + icon = Icons.Filled.EditNote, + text = "Edit Profile" + ) + RepeatedProfileInfo( + icon = Icons.Filled.Notifications, + text = "Notifications" + ) + } - } + } - Spacer(modifier = Modifier.height(30.dp)) + Spacer(modifier = Modifier.height(30.dp)) - Card( - backgroundColor = appBackground, - elevation = 10.dp, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 20.dp) - ) { - Column { + Card( + backgroundColor = appBackground, + elevation = 10.dp, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp) + ) { + Column { - RepeatedProfileInfo( - icon = Icons.Filled.SupportAgent, - text = "Help and Support" - ) - RepeatedProfileInfo( - icon = Icons.Filled.ContactPage, - text = "Contact Us" - ) - RepeatedProfileInfo( - icon = Icons.Filled.PrivacyTip, - text = "Privacy Policy" - ) - } + RepeatedProfileInfo( + icon = Icons.Filled.SupportAgent, + text = "Help and Support" + ) + RepeatedProfileInfo( + icon = Icons.Filled.ContactPage, + text = "Contact Us" + ) + RepeatedProfileInfo( + icon = Icons.Filled.PrivacyTip, + text = "Privacy Policy" + ) + } - } + } - Button( - onClick = { - coroutineScope.launch { - dataStore.saveEmail("") - dataStore.savePfp("") - dataStore.saveName("") - } - Firebase.auth.signOut() - googleSignInClient.signOut() - navController.navigate(Screens.Onboarding.route) - }, - colors = ButtonDefaults.buttonColors( - backgroundColor = Color(0xFFFD5065), - contentColor = Color.White - ), - shape = RoundedCornerShape(35.dp), - modifier = Modifier - .fillMaxWidth() - .padding(50.dp) - ) { - Text( - text = "Logout", - color = Color.White, - fontSize = 18.sp, - fontFamily = monteSB, - modifier = Modifier.padding(bottom = 4.dp), - maxLines = 1, - softWrap = true - ) + Button( + onClick = { + coroutineScope.launch { + dataStore.saveEmail("") + dataStore.savePfp("") + dataStore.saveName("") } - - } + Firebase.auth.signOut() + googleSignInClient.signOut() + navController.navigate(Screens.Onboarding.route) + }, + colors = ButtonDefaults.buttonColors( + backgroundColor = Color(0xFFFD5065), + contentColor = Color.White + ), + shape = RoundedCornerShape(35.dp), + modifier = Modifier + .fillMaxWidth() + .padding(50.dp) + ) { + Text( + text = "Logout", + color = Color.White, + fontSize = 18.sp, + fontFamily = monteSB, + modifier = Modifier.padding(bottom = 4.dp), + maxLines = 1, + softWrap = true + ) } + } } } + @Composable fun RepeatedProfileInfo( icon: ImageVector, diff --git a/app/src/main/java/app/waste2wealth/com/reportwaste/ReportWaste.kt b/app/src/main/java/app/waste2wealth/com/reportwaste/ReportWaste.kt index 9378f12..879cc17 100644 --- a/app/src/main/java/app/waste2wealth/com/reportwaste/ReportWaste.kt +++ b/app/src/main/java/app/waste2wealth/com/reportwaste/ReportWaste.kt @@ -202,381 +202,375 @@ fun ReportWaste( gesturesEnabled = gesturesEnabled, size = 100.dp ) { - Scaffold(bottomBar = { - BottomBar(navController = navController) - }) { - var isCOinVisible by remember { - mutableStateOf(false) - } + var isCOinVisible by remember { + mutableStateOf(false) + } - val context = LocalContext.current - val launcher = rememberLauncherForActivityResult( - contract = ActivityResultContracts.TakePicturePreview(), - onResult = { - println("Bitmaps is ${it?.asImageBitmap()}") - imageBitmap = it?.asImageBitmap() - viewModel.getPlaces() - bitmap = it + val context = LocalContext.current + val launcher = rememberLauncherForActivityResult( + contract = ActivityResultContracts.TakePicturePreview(), + onResult = { + println("Bitmaps is ${it?.asImageBitmap()}") + imageBitmap = it?.asImageBitmap() + viewModel.getPlaces() + bitmap = it - } - ) - println(it) - Box(modifier = Modifier.fillMaxSize()) { - Column( + + } + ) + Box(modifier = Modifier.fillMaxSize()) { + Column( + modifier = Modifier + .fillMaxSize() + .background(appBackground) + .verticalScroll(rememberScrollState()) + ) { + Row( modifier = Modifier - .fillMaxSize() - .background(appBackground) - .verticalScroll(rememberScrollState()) + .fillMaxWidth() + .padding(top = 30.dp, start = 0.dp) + .clickable { + navController.popBackStack() + }, + horizontalArrangement = Arrangement.Start ) { - Row( + Icon( + imageVector = Icons.Filled.ArrowBackIos, + contentDescription = "", + tint = textColor, modifier = Modifier - .fillMaxWidth() - .padding(top = 30.dp, start = 0.dp) - .clickable { - navController.popBackStack() - }, - horizontalArrangement = Arrangement.Start - ) { - Icon( - imageVector = Icons.Filled.ArrowBackIos, - contentDescription = "", - tint = textColor, - modifier = Modifier - .padding(start = 15.dp) - .size(25.dp) - ) + .padding(start = 15.dp) + .size(25.dp) + ) - Row( - modifier = Modifier - .fillMaxWidth() - .offset(x = (-10).dp), - horizontalArrangement = Arrangement.Center - ) { - Text( - text = "Report Waste", - color = textColor, - fontFamily = monteBold, - fontSize = 25.sp - ) - } - } Row( modifier = Modifier .fillMaxWidth() - .padding(start = 10.dp, top = 30.dp) + .offset(x = (-10).dp), + horizontalArrangement = Arrangement.Center ) { Text( - text = "Waste Photograph", + text = "Report Waste", color = textColor, - fontSize = 15.sp, - fontFamily = monteSB + fontFamily = monteBold, + fontSize = 25.sp ) } - Card( - backgroundColor = appBackground, - shape = RoundedCornerShape(7.dp), - elevation = 5.dp, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 7.dp, vertical = 10.dp) - - .clickable { - if (imageBitmap == null) { - coroutineScope.launch { - if (!permissionState.allPermissionsGranted) { - permissionDrawerState.open() - } else { - launcher.launch( - ActivityOptionsCompat.makeBasic() - ) - } + } + Row( + modifier = Modifier + .fillMaxWidth() + .padding(start = 10.dp, top = 30.dp) + ) { + Text( + text = "Waste Photograph", + color = textColor, + fontSize = 15.sp, + fontFamily = monteSB + ) + } + Card( + backgroundColor = appBackground, + shape = RoundedCornerShape(7.dp), + elevation = 5.dp, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 7.dp, vertical = 10.dp) + + .clickable { + if (imageBitmap == null) { + coroutineScope.launch { + if (!permissionState.allPermissionsGranted) { + permissionDrawerState.open() + } else { + launcher.launch( + ActivityOptionsCompat.makeBasic() + ) } } } - ) { - if (imageBitmap == null) { - Column( - modifier = Modifier.fillMaxWidth(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Icon( - imageVector = Icons.Filled.UploadFile, - contentDescription = "", - tint = Color(0xFFCFDCFE), - modifier = Modifier.size(100.dp) - ) - Text( - text = "Upload Photo of Waste", - color = textColor, - fontSize = 16.sp, - fontFamily = monteSB - ) - Spacer(modifier = Modifier.height(30.dp)) - } - } else { - Image( - bitmap = imageBitmap!!, + } + ) { + if (imageBitmap == null) { + Column( + modifier = Modifier.fillMaxWidth(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Icon( + imageVector = Icons.Filled.UploadFile, contentDescription = "", - modifier = Modifier - .fillMaxWidth() - .height(200.dp), - contentScale = ContentScale.Fit + tint = Color(0xFFCFDCFE), + modifier = Modifier.size(100.dp) ) - + Text( + text = "Upload Photo of Waste", + color = textColor, + fontSize = 16.sp, + fontFamily = monteSB + ) + Spacer(modifier = Modifier.height(30.dp)) } - - } - Row( - modifier = Modifier - .fillMaxWidth() - .padding(start = 10.dp, top = 30.dp) - .clickable { - } - ) { - Text( - text = "Type Your Location", - color = textColor, - fontSize = 15.sp, - fontFamily = monteSB + } else { + Image( + bitmap = imageBitmap!!, + contentDescription = "", + modifier = Modifier + .fillMaxWidth() + .height(200.dp), + contentScale = ContentScale.Fit ) + } - Row( - modifier = Modifier - .fillMaxWidth() - .padding(start = 10.dp, top = 10.dp) + + } + Row( + modifier = Modifier + .fillMaxWidth() + .padding(start = 10.dp, top = 30.dp) + .clickable { + } + ) { + Text( + text = "Type Your Location", + color = textColor, + fontSize = 15.sp, + fontFamily = monteSB + ) + } + Row( + modifier = Modifier + .fillMaxWidth() + .padding(start = 10.dp, top = 10.dp) + ) { + ExposedDropdownMenuBox( + expanded = isExpanded, + onExpandedChange = { + isExpanded = it + } ) { - ExposedDropdownMenuBox( - expanded = isExpanded, - onExpandedChange = { - isExpanded = it - } - ) { - OutlinedTextField( - value = address, - onValueChange = { - if (it.length <= 200) { - address = it - } else { - Toast.makeText( - context, - "Maximum 200 words", - Toast.LENGTH_SHORT - ).show() - } - }, - colors = TextFieldDefaults.textFieldColors( - textColor = textColor, backgroundColor = appBackground - ), - textStyle = TextStyle( - color = textColor, - fontFamily = monteSB, - fontSize = 16.sp - ), - modifier = Modifier - .fillMaxWidth() - .padding(15.dp) - .onFocusEvent { focusState -> - if (focusState.isFocused) { - coroutineScope.launch { - bringIntoViewRequester.bringIntoView() - } - } - } - .border(1.dp, textColor), - - ) - ExposedDropdownMenu( - expanded = isExpanded, - onDismissRequest = { - isExpanded = false - }) { - viewModel.listOfAddresses.forEach { - if (it != null) { - DropdownMenuItem(onClick = { - address = it - isExpanded = false - }) { - Text(text = it) + OutlinedTextField( + value = address, + onValueChange = { + if (it.length <= 200) { + address = it + } else { + Toast.makeText( + context, + "Maximum 200 words", + Toast.LENGTH_SHORT + ).show() + } + }, + colors = TextFieldDefaults.textFieldColors( + textColor = textColor, backgroundColor = appBackground + ), + textStyle = TextStyle( + color = textColor, + fontFamily = monteSB, + fontSize = 16.sp + ), + modifier = Modifier + .fillMaxWidth() + .padding(15.dp) + .onFocusEvent { focusState -> + if (focusState.isFocused) { + coroutineScope.launch { + bringIntoViewRequester.bringIntoView() } } } + .border(1.dp, textColor), - + ) + ExposedDropdownMenu( + expanded = isExpanded, + onDismissRequest = { + isExpanded = false + }) { + viewModel.listOfAddresses.forEach { + if (it != null) { + DropdownMenuItem(onClick = { + address = it + isExpanded = false + }) { + Text(text = it) + } + } } - } - } - Row( - modifier = Modifier - .fillMaxWidth() - .padding(top = 15.dp), - horizontalArrangement = Arrangement.Start, - verticalAlignment = Alignment.CenterVertically - ) { - Text( - text = "Points you can Earn", - color = textColor, - fontSize = 16.sp, - fontFamily = monteBold, - modifier = Modifier.padding(start = 45.dp, end = 60.dp) - ) - Row(modifier = Modifier.padding(end = 25.dp)) { - Icon( - painter = painterResource(id = R.drawable.coins), - contentDescription = "coins", - modifier = Modifier - .size(20.dp) - .padding(end = 5.dp), - tint = Color.Unspecified - ) - Text( - text = "20", - color = textColor, - fontSize = 15.sp, - fontFamily = monteNormal, - ) + } } - - Spacer(modifier = Modifier.height(100.dp)) } Row( modifier = Modifier - .fillMaxSize() - .padding(bottom = 100.dp), - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.Bottom + .fillMaxWidth() + .padding(top = 15.dp), + horizontalArrangement = Arrangement.Start, + verticalAlignment = Alignment.CenterVertically ) { - Button( - onClick = { - isDialogVisible = true - }, colors = ButtonDefaults.buttonColors( - backgroundColor = CardColor, - contentColor = CardTextColor - ), - shape = RoundedCornerShape(35.dp), - modifier = Modifier.padding(start = 0.dp) - ) { + Text( + text = "Points you can Earn", + color = textColor, + fontSize = 16.sp, + fontFamily = monteBold, + modifier = Modifier.padding(start = 45.dp, end = 60.dp) + ) + Row(modifier = Modifier.padding(end = 25.dp)) { + Icon( + painter = painterResource(id = R.drawable.coins), + contentDescription = "coins", + modifier = Modifier + .size(20.dp) + .padding(end = 5.dp), + tint = Color.Unspecified + ) Text( - text = "Report Waste", - color = Color.White, + text = "20", + color = textColor, + fontSize = 15.sp, fontFamily = monteNormal, - fontSize = 15.sp ) - } + } - DialogBox( - isVisible = isDialogVisible, - successRequest = { - Toast.makeText(context, "Please Wait", Toast.LENGTH_SHORT) - .show() - if (bitmap != null) { - val storageRef = FirebaseStorage.getInstance().reference - val allowedChars = ('A'..'Z') + ('a'..'z') + ('0'..'9') - var imageName = (1..10) - .map { allowedChars.random() } - .joinToString("") - imageName = "Reported/${email}/${imageName}.jpg" - - val imageRef = - storageRef.child(imageName) // Set desired storage location - - val baos = ByteArrayOutputStream() - bitmap?.compress(Bitmap.CompressFormat.JPEG, 100, baos) - val imageData = baos.toByteArray() - - val uploadTask = imageRef.putBytes(imageData) - uploadTask.addOnSuccessListener { taskSnapshot -> - }.addOnFailureListener { exception -> - println("Firebase storage exception $exception") - }.addOnCompleteListener { task -> - if (task.isSuccessful) { - imageRef.downloadUrl.addOnSuccessListener { - println("Download url is $it") - updateWasteToFirebase( - context = context, - address = address, - latitude = viewModel.latitude, - longitude = viewModel.longitude, - imagePath = imageName, - timeStamp = System.currentTimeMillis(), - userEmail = email ?: "", - ) - updateInfoToFirebase( - context, - name = name, - email = email, - phoneNumber = phoneNumber, - gender = gender, - organization = organization, - address = userAddress, - pointsEarned = pointsEarned + calculatePointsEarned( - noOfTimesReported, - noOfTimesCollected, - noOfTimesActivity - ), - pointsRedeemed = pointsRedeemed, - noOfTimesReported = noOfTimesReported + 1, - noOfTimesCollected = noOfTimesCollected, - noOfTimesActivity = noOfTimesActivity, - ) - isCOinVisible = true - } - } + Spacer(modifier = Modifier.height(100.dp)) + } + Row( + modifier = Modifier + .fillMaxSize() + .padding(bottom = 100.dp), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.Bottom + ) { + Button( + onClick = { + isDialogVisible = true + }, colors = ButtonDefaults.buttonColors( + backgroundColor = CardColor, + contentColor = CardTextColor + ), + shape = RoundedCornerShape(35.dp), + modifier = Modifier.padding(start = 0.dp) + ) { + Text( + text = "Report Waste", + color = Color.White, + fontFamily = monteNormal, + fontSize = 15.sp + ) + + } + } + DialogBox( + isVisible = isDialogVisible, + successRequest = { + Toast.makeText(context, "Please Wait", Toast.LENGTH_SHORT) + .show() + if (bitmap != null) { + val storageRef = FirebaseStorage.getInstance().reference + val allowedChars = ('A'..'Z') + ('a'..'z') + ('0'..'9') + var imageName = (1..10) + .map { allowedChars.random() } + .joinToString("") + imageName = "Reported/${email}/${imageName}.jpg" + + val imageRef = + storageRef.child(imageName) // Set desired storage location + + val baos = ByteArrayOutputStream() + bitmap?.compress(Bitmap.CompressFormat.JPEG, 100, baos) + val imageData = baos.toByteArray() + + val uploadTask = imageRef.putBytes(imageData) + uploadTask.addOnSuccessListener { taskSnapshot -> + }.addOnFailureListener { exception -> + println("Firebase storage exception $exception") + }.addOnCompleteListener { task -> + if (task.isSuccessful) { + imageRef.downloadUrl.addOnSuccessListener { + println("Download url is $it") + updateWasteToFirebase( + context = context, + address = address, + latitude = viewModel.latitude, + longitude = viewModel.longitude, + imagePath = imageName, + timeStamp = System.currentTimeMillis(), + userEmail = email ?: "", + ) + updateInfoToFirebase( + context, + name = name, + email = email, + phoneNumber = phoneNumber, + gender = gender, + organization = organization, + address = userAddress, + pointsEarned = pointsEarned + calculatePointsEarned( + noOfTimesReported, + noOfTimesCollected, + noOfTimesActivity + ), + pointsRedeemed = pointsRedeemed, + noOfTimesReported = noOfTimesReported + 1, + noOfTimesCollected = noOfTimesCollected, + noOfTimesActivity = noOfTimesActivity, + ) + isCOinVisible = true + } } } - isDialogVisible = false - }) { - isDialogVisible = !isDialogVisible - } - } - - if (isCOinVisible) { - Box( - modifier = Modifier.fillMaxSize(), - contentAlignment = Alignment.BottomCenter - ) { - val currenanim by rememberLottieComposition( - spec = LottieCompositionSpec.Asset("coins.json") - ) - LottieAnimation( - composition = currenanim, - iterations = 1, - contentScale = ContentScale.Crop, - speed = 1f, - modifier = Modifier - .fillMaxSize() - .size(250.dp) - ) - } - LaunchedEffect(key1 = isCOinVisible) { - if (isCOinVisible) { - delay(4000) - navController.navigate(Screens.Dashboard.route) } - } + isDialogVisible = false + }) { + isDialogVisible = !isDialogVisible } + } + if (isCOinVisible) { + Box( + modifier = Modifier.fillMaxSize(), + contentAlignment = Alignment.BottomCenter + ) { + val currenanim by rememberLottieComposition( + spec = LottieCompositionSpec.Asset("coins.json") + ) + LottieAnimation( + composition = currenanim, + iterations = 1, + contentScale = ContentScale.Crop, + speed = 1f, + modifier = Modifier + .fillMaxSize() + .size(250.dp) + ) + } + LaunchedEffect(key1 = isCOinVisible) { + if (isCOinVisible) { + delay(4000) + navController.navigate(Screens.Dashboard.route) + } + } } - } + } } -} +} @Composable fun DialogBox(