Skip to content

Commit

Permalink
Add sign-out and delete account options
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-radhika-s committed Feb 6, 2024
1 parent 20be806 commit 13a8f5d
Show file tree
Hide file tree
Showing 18 changed files with 546 additions and 27 deletions.
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 @@ -24,26 +24,28 @@ 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),
style = AppTheme.appTypography.subTitle2.copy(color = contentColor),
textAlign = TextAlign.Center,
modifier = Modifier.padding(vertical = 6.dp)
)
Expand All @@ -55,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 @@ -64,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 @@ -54,6 +54,7 @@ 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 Down Expand Up @@ -147,6 +148,7 @@ fun HomeTopBar() {
modifier = Modifier,
visible = !state.showSpaceSelectionPopup
) {
viewModel.navigateToSettings()
}

SpaceSelectionMenu(modifier = Modifier.weight(1f))
Expand Down Expand Up @@ -238,6 +240,10 @@ fun HomeScreenContent(navController: NavHostController) {
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,9 +36,24 @@ class HomeScreenViewModel @Inject constructor(
val state: StateFlow<HomeScreenState> = _state

init {
updateUser()
getAllSpaces()
}

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 onTabChange(index: Int) {
_state.value = _state.value.copy(currentTab = index)
}
Expand Down Expand Up @@ -142,6 +161,10 @@ class HomeScreenViewModel @Inject constructor(
_state.emit(_state.value.copy(error = e.message))
}
}

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

data class HomeScreenState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import com.canopas.catchme.R
import com.canopas.catchme.data.utils.hasAllPermission
import com.canopas.catchme.data.utils.hasFineLocationPermission
import com.canopas.catchme.data.utils.hasNotificationPermission
import com.canopas.catchme.ui.flow.home.map.component.AddMemberBtn
import com.canopas.catchme.ui.flow.home.map.component.MapMarker
import com.canopas.catchme.ui.flow.home.map.component.MapUserItem
Expand Down Expand Up @@ -234,8 +235,9 @@ fun MapScreenContent(modifier: Modifier) {
fun PermissionFooter(onClick: () -> Unit) {
val context = LocalContext.current
val hasLocationPermission = context.hasFineLocationPermission
val hasNotificationPermission = context.hasNotificationPermission

val title = if (!hasLocationPermission) {
val title = if (!hasLocationPermission || !hasNotificationPermission) {
stringResource(id = R.string.home_permission_footer_title)
} else {
stringResource(id = R.string.home_permission_footer_missing_location_permission_title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import androidx.compose.ui.window.DialogProperties
import androidx.hilt.navigation.compose.hiltViewModel
import com.canopas.catchme.R
import com.canopas.catchme.data.utils.openAppSettings
import com.canopas.catchme.ui.component.PrimaryButton
import com.canopas.catchme.ui.theme.AppTheme
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.PermissionStatus
Expand Down Expand Up @@ -126,7 +125,7 @@ fun EnablePermissionsContent(modifier: Modifier) {
.fillMaxSize()
.verticalScroll(scrollState)
.background(AppTheme.colorScheme.surface)
.padding(vertical = 40.dp),
.padding(vertical = 10.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
Expand Down Expand Up @@ -171,26 +170,18 @@ fun EnablePermissionsContent(modifier: Modifier) {
description = stringResource(R.string.enable_permission_notification_access_desc),
isGranted = notificationPermissionStates?.status == PermissionStatus.Granted,
onClick = {
if (notificationPermissionStates?.status != PermissionStatus.Granted) {
if (notificationPermissionStates?.status is PermissionStatus.Denied ||
notificationPermissionStates?.status?.shouldShowRationale == true
) {
showNotificationRational = true
} else if (notificationPermissionStates?.status != PermissionStatus.Granted) {
notificationPermissionStates?.launchPermissionRequest()
}
}
)
}

Spacer(modifier = Modifier.weight(1f))
PrimaryButton(
label = stringResource(id = R.string.common_btn_continue),
onClick = {
if (notificationPermissionStates?.status != null && notificationPermissionStates.status != PermissionStatus.Granted) {
showNotificationRational = true
} else {
viewModel.popBack()
}
}
)

Spacer(modifier = Modifier.height(20.dp))
Text(
text = stringResource(R.string.enable_permission_footer),
style = AppTheme.appTypography.label3,
Expand All @@ -209,7 +200,13 @@ fun EnablePermissionsContent(modifier: Modifier) {
},
onContinue = {
showNotificationRational = false
notificationPermissionStates?.launchPermissionRequest()
if (notificationPermissionStates?.status is PermissionStatus.Denied &&
!notificationPermissionStates.status.shouldShowRationale
) {
(context as Activity).openAppSettings()
} else {
notificationPermissionStates?.launchPermissionRequest()
}
}
)
}
Expand Down
Loading

0 comments on commit 13a8f5d

Please sign in to comment.