Skip to content

Commit

Permalink
V1 Bug fixes and improvements (#16)
Browse files Browse the repository at this point in the history
* Show members on map

* Add permission banner on home screen

* Refactor permissions screen

* Map dark theme

* Minor fix

* Onboard screen fixes

* Fix onboard screen

* Fix location permission

* Add sign-out and delete account options

* Lint fix
  • Loading branch information
cp-radhika-s authored Feb 6, 2024
1 parent 4b54dbc commit e62fcd6
Show file tree
Hide file tree
Showing 44 changed files with 1,329 additions and 624 deletions.
4 changes: 0 additions & 4 deletions app/src/main/java/com/canopas/catchme/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.canopas.catchme.ui.flow.auth.verification.PhoneVerificationScreen
import com.canopas.catchme.ui.flow.home.home.HomeScreen
import com.canopas.catchme.ui.flow.intro.IntroScreen
import com.canopas.catchme.ui.flow.onboard.OnboardScreen
import com.canopas.catchme.ui.flow.permission.EnablePermissionsScreen
import com.canopas.catchme.ui.navigation.AppDestinations
import com.canopas.catchme.ui.navigation.AppNavigator
import com.canopas.catchme.ui.navigation.KEY_RESULT
Expand Down Expand Up @@ -93,9 +92,6 @@ fun MainApp() {
slideComposable(AppDestinations.OtpVerificationNavigation.path) {
PhoneVerificationScreen()
}
slideComposable(AppDestinations.enablePermissions.path) {
EnablePermissionsScreen()
}

slideComposable(AppDestinations.home.path) {
HomeScreen()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.canopas.catchme.ui.component

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import com.canopas.catchme.ui.theme.AppTheme

@Composable
fun AppAlertDialog(
title: String?,
subTitle: String,
confirmBtnText: String?,
dismissBtnText: String?,
onConfirmClick: (() -> Unit)? = null,
onDismissClick: (() -> Unit)? = null,
isConfirmDestructive: Boolean = false
) {
AlertDialog(
onDismissRequest = {},
containerColor = AppTheme.colorScheme.containerNormalOnSurface,
title = {
if (title != null) {
Text(
text = title,
style = AppTheme.appTypography.header3
)
}
},
text = {
Text(
text = subTitle,
style = AppTheme.appTypography.body1
)
},
confirmButton = {
if (confirmBtnText != null && onConfirmClick != null) {
TextButton(
onClick = (onConfirmClick)
) {
Text(
text = confirmBtnText,
style = AppTheme.appTypography.subTitle2,
color = if (isConfirmDestructive) AppTheme.colorScheme.alertColor else AppTheme.colorScheme.primary
)
}
}
},
dismissButton = {
if (dismissBtnText != null && onDismissClick != null) {
TextButton(onClick = (onDismissClick)) {
Text(
text = dismissBtnText,
style = AppTheme.appTypography.subTitle2,
color = if (isConfirmDestructive) AppTheme.colorScheme.textSecondary else AppTheme.colorScheme.primary
)
}
}
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fun ShowBackgroundLocationRequestDialog(
) {
Column(
Modifier
.background(AppTheme.colorScheme.surface)
.background(AppTheme.colorScheme.containerNormalOnSurface)
.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -43,7 +44,9 @@ fun CreateSpace(
val keyboardController = LocalSoftwareKeyboardController.current
val scrollState = rememberScrollState()
Column(
modifier = modifier.verticalScroll(scrollState)
modifier = modifier
.fillMaxSize()
.verticalScroll(scrollState)
) {
Spacer(modifier = Modifier.height(20.dp))
Text(
Expand Down Expand Up @@ -85,7 +88,7 @@ fun CreateSpace(
onSpaceNameChanged(it)
keyboardController?.hide()
}
Spacer(modifier = Modifier.height(40.dp))
Spacer(modifier = Modifier.weight(1f))

PrimaryButton(
label = stringResource(R.string.common_btn_next),
Expand All @@ -97,6 +100,7 @@ fun CreateSpace(
enabled = spaceName.trim().isNotEmpty(),
showLoader = showLoader
)
Spacer(modifier = Modifier.height(40.dp))
}
}

Expand Down Expand Up @@ -146,7 +150,7 @@ private fun PickNameTextField(title: String, value: String, onValueChanged: (Str
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 14.dp),
textStyle = AppTheme.appTypography.header4,
textStyle = AppTheme.appTypography.header4.copy(AppTheme.colorScheme.textPrimary),
onValueChange = { value ->
onValueChanged(value)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,30 @@ fun PrimaryButton(
label: String,
onClick: () -> Unit,
enabled: Boolean = true,
showLoader: Boolean = false
showLoader: Boolean = false,
containerColor: Color = AppTheme.colorScheme.primary,
contentColor: Color = AppTheme.colorScheme.onPrimary
) {
Button(
onClick = onClick,
modifier = modifier
.fillMaxWidth(fraction = 0.9f),
shape = RoundedCornerShape(50),
colors = ButtonDefaults.buttonColors(
containerColor = AppTheme.colorScheme.primary
containerColor = containerColor
),
enabled = enabled
) {
if (showLoader) {
AppProgressIndicator(color = AppTheme.colorScheme.onPrimary)
AppProgressIndicator(color = contentColor)
Spacer(modifier = Modifier.width(4.dp))
}

Text(
text = label,
style = AppTheme.appTypography.subTitle2.copy(color = AppTheme.colorScheme.onPrimary),
textAlign = TextAlign.Center
style = AppTheme.appTypography.subTitle2.copy(color = contentColor),
textAlign = TextAlign.Center,
modifier = Modifier.padding(vertical = 6.dp)
)
}
}
Expand All @@ -54,7 +57,9 @@ fun PrimaryTextButton(
modifier: Modifier = Modifier,
label: String,
onClick: () -> Unit,
enabled: Boolean = true
enabled: Boolean = true,
showLoader: Boolean = false,
contentColor: Color = AppTheme.colorScheme.primary
) {
TextButton(
onClick = onClick,
Expand All @@ -63,10 +68,14 @@ fun PrimaryTextButton(
shape = RoundedCornerShape(50),
colors = ButtonDefaults.buttonColors(
containerColor = AppTheme.colorScheme.surface,
contentColor = AppTheme.colorScheme.primary
contentColor = contentColor
),
enabled = enabled
) {
if (showLoader) {
AppProgressIndicator(color = contentColor)
Spacer(modifier = Modifier.width(4.dp))
}
Text(
text = label,
style = AppTheme.appTypography.subTitle2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun UserProfile(
shape = RoundedCornerShape(16.dp)
)
.background(
AppTheme.colorScheme.primary.copy(alpha = 0.7f),
AppTheme.colorScheme.primary,
shape = RoundedCornerShape(16.dp)
),
contentAlignment = Alignment.Center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SignInMethodViewModel @Inject constructor(
} else {
userPreferences.setOnboardShown(true)
navigator.navigateTo(
AppDestinations.enablePermissions.path,
AppDestinations.home.path,
popUpToRoute = AppDestinations.signIn.path,
inclusive = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import androidx.navigation.compose.rememberNavController
import com.canopas.catchme.R
import com.canopas.catchme.data.utils.isBackgroundLocationPermissionGranted
import com.canopas.catchme.ui.component.AppProgressIndicator
import com.canopas.catchme.ui.component.CheckBackgroundLocationPermission
import com.canopas.catchme.ui.flow.home.activity.ActivityScreen
import com.canopas.catchme.ui.flow.home.home.component.SpaceSelectionMenu
import com.canopas.catchme.ui.flow.home.home.component.SpaceSelectionPopup
Expand All @@ -54,6 +53,8 @@ import com.canopas.catchme.ui.flow.home.places.PlacesScreen
import com.canopas.catchme.ui.flow.home.space.create.CreateSpaceHomeScreen
import com.canopas.catchme.ui.flow.home.space.create.SpaceInvite
import com.canopas.catchme.ui.flow.home.space.join.JoinSpaceScreen
import com.canopas.catchme.ui.flow.permission.EnablePermissionsScreen
import com.canopas.catchme.ui.flow.settings.SettingsScreen
import com.canopas.catchme.ui.navigation.AppDestinations
import com.canopas.catchme.ui.navigation.AppNavigator
import com.canopas.catchme.ui.navigation.slideComposable
Expand All @@ -67,15 +68,11 @@ fun HomeScreen() {
val context = LocalContext.current

LaunchedEffect(Unit) {
if (!context.isBackgroundLocationPermissionGranted) {
viewModel.shouldAskForBackgroundLocationPermission(true)
} else {
if (context.isBackgroundLocationPermissionGranted) {
viewModel.startTracking()
}
}

PermissionChecker()

AppNavigator(navController = navController, viewModel.navActions)
val navBackStackEntry by navController.currentBackStackEntryAsState()

Expand Down Expand Up @@ -108,16 +105,16 @@ fun HomeScreen() {
HomeTopBar()
}
}
},
bottomBar = {
}
/* bottomBar = {
AnimatedVisibility(
visible = !hideBottomBar,
enter = slideInVertically(tween(100)) { it },
exit = slideOutVertically(tween(100)) { it }
) {
HomeBottomBar(navController)
}
}
}*/
)
}

Expand Down Expand Up @@ -151,6 +148,7 @@ fun HomeTopBar() {
modifier = Modifier,
visible = !state.showSpaceSelectionPopup
) {
viewModel.navigateToSettings()
}

SpaceSelectionMenu(modifier = Modifier.weight(1f))
Expand Down Expand Up @@ -208,20 +206,6 @@ private fun MapControl(
}
}

@Composable
private fun PermissionChecker() {
val viewModel = hiltViewModel<HomeScreenViewModel>()
val state by viewModel.state.collectAsState()

if (state.shouldAskForBackgroundLocationPermission) {
CheckBackgroundLocationPermission(onDismiss = {
viewModel.shouldAskForBackgroundLocationPermission(false)
}, onGranted = {
viewModel.startTracking()
})
}
}

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun HomeScreenContent(navController: NavHostController) {
Expand Down Expand Up @@ -252,6 +236,14 @@ fun HomeScreenContent(navController: NavHostController) {
slideComposable(AppDestinations.SpaceInvitation.path) {
SpaceInvite()
}

slideComposable(AppDestinations.enablePermissions.path) {
EnablePermissionsScreen()
}

slideComposable(AppDestinations.settings.path) {
SettingsScreen()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.canopas.catchme.data.models.space.SpaceInfo
import com.canopas.catchme.data.repository.SpaceRepository
import com.canopas.catchme.data.service.auth.AuthService
import com.canopas.catchme.data.service.location.LocationManager
import com.canopas.catchme.data.storage.UserPreferences
import com.canopas.catchme.data.utils.AppDispatcher
import com.canopas.catchme.ui.navigation.AppDestinations
import com.canopas.catchme.ui.navigation.HomeNavigator
import com.canopas.catchme.ui.navigation.MainNavigator
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -20,9 +22,11 @@ import javax.inject.Inject
@HiltViewModel
class HomeScreenViewModel @Inject constructor(
private val navigator: HomeNavigator,
private val mainNavigator: MainNavigator,
private val locationManager: LocationManager,
private val spaceRepository: SpaceRepository,
private val userPreferences: UserPreferences,
private val authService: AuthService,
private val appDispatcher: AppDispatcher
) : ViewModel() {

Expand All @@ -32,19 +36,29 @@ class HomeScreenViewModel @Inject constructor(
val state: StateFlow<HomeScreenState> = _state

init {
updateUser()
getAllSpaces()
}

fun onTabChange(index: Int) {
_state.value = _state.value.copy(currentTab = index)
private fun updateUser() = viewModelScope.launch(appDispatcher.IO) {
val user = authService.getUser()
if (user == null) {
authService.signOut()
mainNavigator.navigateTo(
AppDestinations.signIn.path,
AppDestinations.home.path,
true
)
} else {
authService.saveUser(user)
}
}

fun shouldAskForBackgroundLocationPermission(ask: Boolean) {
_state.value = _state.value.copy(shouldAskForBackgroundLocationPermission = ask)
fun onTabChange(index: Int) {
_state.value = _state.value.copy(currentTab = index)
}

fun startTracking() {
shouldAskForBackgroundLocationPermission(false)
locationManager.startService()
}

Expand Down Expand Up @@ -147,11 +161,14 @@ class HomeScreenViewModel @Inject constructor(
_state.emit(_state.value.copy(error = e.message))
}
}

fun navigateToSettings() {
navigator.navigateTo(AppDestinations.settings.path)
}
}

data class HomeScreenState(
val currentTab: Int = 0,
val shouldAskForBackgroundLocationPermission: Boolean = false,
val spaces: List<SpaceInfo> = emptyList(),
val selectedSpaceId: String = "",
val selectedSpace: SpaceInfo? = null,
Expand Down
Loading

0 comments on commit e62fcd6

Please sign in to comment.