Skip to content

Commit

Permalink
Release - 1.4.0 (fix Bottom Bars )
Browse files Browse the repository at this point in the history
release: 1.4.0 ( Bottom Bars Fix)
  • Loading branch information
thekaailashsharma authored Sep 14, 2023
2 parents 8de8895 + 19b7c31 commit f72e72d
Show file tree
Hide file tree
Showing 11 changed files with 1,485 additions and 1,538 deletions.
103 changes: 82 additions & 21 deletions app/src/main/java/app/waste2wealth/com/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
package app.waste2wealth.com

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.IntentFilter
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
Expand All @@ -27,40 +42,86 @@ 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
)
}
}
}
}
}

@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)
}
Expand Down
145 changes: 80 additions & 65 deletions app/src/main/java/app/waste2wealth/com/bottombar/BottomBar.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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<Boolean> = 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
}
}
)
}
)
}
}
}
}
}
)
}
Loading

0 comments on commit f72e72d

Please sign in to comment.