Skip to content

Commit

Permalink
Merge pull request #337 from PeriodPals/fix/misc/profile-settings-ext…
Browse files Browse the repository at this point in the history
…ract-strings

Fix/misc/profile settings extract strings
  • Loading branch information
taghizadlaura authored Dec 19, 2024
2 parents 79a35a1 + 3c821d6 commit 0c3cc37
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ import com.android.periodpals.ui.theme.dimens
import com.dsc.form_builder.TextFieldState
import kotlin.math.roundToInt

private const val SCREEN_TITLE = "Create Your Account"
private const val RADIUS_EXPLANATION_TEXT =
"By specifying this radius, " +
"you can control the geographical range for receiving alerts from other users."
private val DEFAULT_PROFILE_PICTURE =
Uri.parse("android.resource://com.android.periodpals/${R.drawable.generic_avatar}")
private const val DEFAULT_RADIUS = 500F
Expand Down Expand Up @@ -86,7 +82,7 @@ fun CreateProfileScreen(userViewModel: UserViewModel, navigationActions: Navigat

Scaffold(
modifier = Modifier.fillMaxSize().testTag(CreateProfileScreen.SCREEN),
topBar = { TopAppBar(title = SCREEN_TITLE) },
topBar = { TopAppBar(title = context.getString(R.string.create_profile_screen_title)) },
containerColor = MaterialTheme.colorScheme.surface,
contentColor = MaterialTheme.colorScheme.onSurface,
) { paddingValues ->
Expand Down Expand Up @@ -133,7 +129,7 @@ fun CreateProfileScreen(userViewModel: UserViewModel, navigationActions: Navigat
SliderMenu(sliderPosition) { sliderPosition = (it / 100).roundToInt() * 100f }

Text(
text = RADIUS_EXPLANATION_TEXT,
text = context.getString(R.string.create_profile_radius_explanation_text),
style = MaterialTheme.typography.labelMedium,
modifier =
Modifier.wrapContentHeight()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import com.android.periodpals.ui.navigation.TopAppBar
import com.android.periodpals.ui.theme.dimens
import com.dsc.form_builder.TextFieldState

private const val SCREEN_TITLE = "Edit Your Profile"
private const val TAG = "EditProfile"
private val DEFAULT_PROFILE_PICTURE =
"android.resource://com.android.periodpals/${R.drawable.generic_avatar}"

Expand Down Expand Up @@ -98,7 +96,7 @@ fun EditProfileScreen(userViewModel: UserViewModel, navigationActions: Navigatio
modifier = Modifier.fillMaxSize().testTag(EditProfileScreen.SCREEN),
topBar = {
TopAppBar(
title = SCREEN_TITLE,
title = context.getString(R.string.edit_profile_screen_title),
true,
onBackButtonClick = { navigationActions.navigateTo(Screen.PROFILE) },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,11 @@ import com.android.periodpals.ui.navigation.Screen
import com.android.periodpals.ui.navigation.TopAppBar
import com.android.periodpals.ui.theme.dimens

private const val SCREEN_TITLE = "Your Profile"
private const val TAG = "ProfileScreen"
private const val DEFAULT_NAME = "Error loading name, try again later."
private const val DEFAULT_DESCRIPTION = "Error loading description, try again later."

private val DEFAULT_PROFILE_PICTURE =
Uri.parse("android.resource://com.android.periodpals/${R.drawable.generic_avatar}")

private const val NEW_USER_TEXT = "New user"
private const val NUMBER_INTERACTION_TEXT = "Number of interactions: "
private const val REVIEWS_TITLE = "Reviews"
private const val NO_REVIEWS_TEXT = "No reviews yet..."

/**
* A composable function that displays the user's profile screen.
*
Expand Down Expand Up @@ -112,7 +105,7 @@ fun ProfileScreen(
modifier = Modifier.fillMaxSize().testTag(ProfileScreen.SCREEN),
topBar = {
TopAppBar(
title = SCREEN_TITLE,
title = context.getString(R.string.profile_screen_title),
settingsButton = true,
onSettingsButtonClick = { navigationActions.navigateTo(Screen.SETTINGS) },
editButton = true,
Expand Down Expand Up @@ -148,7 +141,7 @@ fun ProfileScreen(
// Name
Text(
modifier = Modifier.fillMaxWidth().wrapContentHeight().testTag(ProfileScreen.NAME_FIELD),
text = userState?.name ?: DEFAULT_NAME,
text = userState?.name ?: context.getString(R.string.profile_default_name),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleSmall,
)
Expand All @@ -157,7 +150,7 @@ fun ProfileScreen(
Text(
modifier =
Modifier.fillMaxWidth().wrapContentHeight().testTag(ProfileScreen.DESCRIPTION_FIELD),
text = userState?.description ?: DEFAULT_DESCRIPTION,
text = userState?.description ?: context.getString(R.string.profile_default_description),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodyMedium,
)
Expand All @@ -167,14 +160,16 @@ fun ProfileScreen(
modifier =
Modifier.fillMaxWidth().wrapContentHeight().testTag(ProfileScreen.CONTRIBUTION_FIELD),
text =
if (numberInteractions == 0) NEW_USER_TEXT
else NUMBER_INTERACTION_TEXT + numberInteractions,
if (numberInteractions == 0) context.getString(R.string.profile_new_user)
else context.getString(R.string.profile_number_interaction_text) + numberInteractions,
textAlign = TextAlign.Left,
style = MaterialTheme.typography.bodyMedium,
)

// Review section text
ProfileSection(text = REVIEWS_TITLE, testTag = ProfileScreen.REVIEWS_SECTION)
ProfileSection(
text = context.getString(R.string.profile_reviews_title),
testTag = ProfileScreen.REVIEWS_SECTION)

// Reviews or no reviews card
if (numberInteractions == 0) {
Expand All @@ -195,6 +190,7 @@ fun ProfileScreen(
*/
@Composable
private fun NoReviewCard() {
val context = LocalContext.current
Card(
modifier = Modifier.wrapContentSize().testTag(ProfileScreen.NO_REVIEWS_CARD),
shape = RoundedCornerShape(size = MaterialTheme.dimens.cardRoundedSize),
Expand All @@ -215,7 +211,7 @@ private fun NoReviewCard() {
)
Text(
modifier = Modifier.wrapContentSize().testTag(ProfileScreen.NO_REVIEWS_TEXT),
text = NO_REVIEWS_TEXT,
text = context.getString(R.string.profile_no_reviews_text),
style = MaterialTheme.typography.bodyMedium,
)
}
Expand Down
108 changes: 43 additions & 65 deletions app/src/main/java/com/android/periodpals/ui/settings/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.android.periodpals.R
import com.android.periodpals.model.authentication.AuthenticationViewModel
import com.android.periodpals.model.user.UserViewModel
import com.android.periodpals.resources.C.Tag.SettingsScreen
Expand All @@ -69,32 +70,11 @@ import com.android.periodpals.ui.navigation.Screen
import com.android.periodpals.ui.navigation.TopAppBar
import com.android.periodpals.ui.theme.dimens

private const val SCREEN_TITLE = "My Settings"

// Comments
private const val COMMENT_NOTIFICATIONS = "Notify me when a pal needs ..."
private const val COMMENT_ORGANIC = "Which are ..."

// Notifications
private const val NOTIF_PALS = "Pals’ Notifications"
private const val NOTIF_PADS = "Pads"
private const val NOTIF_TAMPONS = "Tampons"
private const val NOTIF_ORGANIC = "Organic"

// Themes
private const val THEME_LABEL = "Theme"
private const val THEME_SYSTEM = "System"
private const val THEME_LIGHT = "Light Mode"
private const val THEME_DARK = "Dark Mode"

// account management
private const val ACCOUNT_PASSWORD = "Change Password"
private const val ACCOUNT_SIGN_OUT = "Sign Out"
private const val ACCOUNT_DELETE = "Delete Account"

// Dialog
private const val DIALOG_TEXT = "Are you sure you want to delete your account?"

// Dropdown choices
private val THEME_DROPDOWN_CHOICES =
listOf(
Expand All @@ -105,26 +85,6 @@ private val THEME_DROPDOWN_CHOICES =
// Log messages
private const val LOG_SETTINGS_TAG = "SettingsScreen"

private const val LOG_SETTINGS_SUCCESS_SIGN_OUT = "Sign out successful"
private const val LOG_SETTINGS_FAILURE_SIGN_OUT = "Failed to sign out"

private const val LOG_SETTINGS_SUCCESS_DELETE = "Account deleted successfully"
private const val LOG_SETTINGS_FAILURE_DELETE = "Failed to delete account"

private const val LOG_SETTINGS_SUCCESS_LOAD_DATA =
"user data loaded successfully, deleting the user"
private const val LOG_SETTINGS_FAILURE_LOAD_DATA = "failed to load user data, can't delete the user"

// Toast messages

private const val TOAST_SETTINGS_SUCCESS_SIGN_OUT = "Sign out successful"
private const val TOAST_SETTINGS_FAILURE_SIGN_OUT = "Failed to sign out"

private const val TOAST_SETTINGS_SUCCESS_DELETE = "Account deleted successfully"
private const val TOAST_SETTINGS_FAILURE_DELETE = "Failed to delete account"

private const val TOAST_LOAD_DATA_FAILURE = "Failed loading user authentication data"

/**
* A composable function that displays the Settings screen, where users can manage their
* notifications, themes, and account settings.
Expand All @@ -143,7 +103,7 @@ private const val TOAST_LOAD_DATA_FAILURE = "Failed loading user authentication
fun SettingsScreen(
userViewModel: UserViewModel,
authenticationViewModel: AuthenticationViewModel,
navigationActions: NavigationActions
navigationActions: NavigationActions,
) {

// notifications states
Expand Down Expand Up @@ -176,7 +136,7 @@ fun SettingsScreen(
modifier = Modifier.fillMaxSize().testTag(SettingsScreen.SCREEN),
topBar = {
TopAppBar(
title = SCREEN_TITLE,
title = context.getString(R.string.settings_screen_title),
true,
onBackButtonClick = { navigationActions.goBack() },
)
Expand All @@ -201,7 +161,7 @@ fun SettingsScreen(
// notification section
SettingsContainer(testTag = SettingsScreen.NOTIFICATIONS_CONTAINER) {
SettingsSwitchRow(
text = NOTIF_PALS,
text = context.getString(R.string.settings_notif_pals),
isChecked = receiveNotifications,
onCheckedChange = { receiveNotifications = it },
textTestTag = SettingsScreen.PALS_TEXT,
Expand All @@ -211,22 +171,25 @@ fun SettingsScreen(
color = MaterialTheme.colorScheme.outlineVariant,
modifier = Modifier.testTag(SettingsScreen.HORIZONTAL_DIVIDER))
SettingsDescription(
text = COMMENT_NOTIFICATIONS, testTag = SettingsScreen.NOTIFICATIONS_DESCRIPTION)
text = context.getString(R.string.settings_comment_notifications),
testTag = SettingsScreen.NOTIFICATIONS_DESCRIPTION)
SettingsSwitchRow(
text = NOTIF_PADS,
text = context.getString(R.string.settings_notif_pads),
isChecked = receiveNotifications && padsNotifications,
onCheckedChange = { padsNotifications = it },
textTestTag = SettingsScreen.PADS_TEXT,
switchTestTag = SettingsScreen.PADS_SWITCH)
SettingsSwitchRow(
text = NOTIF_TAMPONS,
text = context.getString(R.string.settings_notif_tampons),
isChecked = receiveNotifications && tamponsNotifications,
onCheckedChange = { tamponsNotifications = it },
textTestTag = SettingsScreen.TAMPONS_TEXT,
switchTestTag = SettingsScreen.TAMPONS_SWITCH)
SettingsDescription(COMMENT_ORGANIC, SettingsScreen.ORGANIC_DESCRIPTION)
SettingsDescription(
context.getString(R.string.settings_comment_organic),
SettingsScreen.ORGANIC_DESCRIPTION)
SettingsSwitchRow(
text = NOTIF_ORGANIC,
text = context.getString(R.string.settings_notif_organic),
isChecked = receiveNotifications && organicNotifications,
onCheckedChange = { organicNotifications = it },
textTestTag = SettingsScreen.ORGANIC_TEXT,
Expand All @@ -245,7 +208,11 @@ fun SettingsScreen(
textStyle = MaterialTheme.typography.labelLarge,
value = theme,
onValueChange = {},
label = { Text(THEME_LABEL, style = MaterialTheme.typography.labelMedium) },
label = {
Text(
context.getString(R.string.settings_theme_label),
style = MaterialTheme.typography.labelMedium)
},
singleLine = true,
readOnly = true,
leadingIcon = { Icon(icon, contentDescription = null) },
Expand Down Expand Up @@ -292,42 +259,46 @@ fun SettingsScreen(
// account management section
SettingsContainer(testTag = SettingsScreen.ACCOUNT_MANAGEMENT_CONTAINER) {
SettingsIconRow(
text = ACCOUNT_PASSWORD,
text = context.getString(R.string.settings_account_password),
onClick = {},
icon = Icons.Outlined.Key,
textTestTag = SettingsScreen.PASSWORD_TEXT,
iconTestTag = SettingsScreen.PASSWORD_ICON,
)
SettingsIconRow(
text = ACCOUNT_SIGN_OUT,
text = context.getString(R.string.settings_account_sign_out),
onClick = {
authenticationViewModel.logOut(
onSuccess = {
Handler(Looper.getMainLooper())
.post { // used to show the Toast on the main thread
Toast.makeText(
context, TOAST_SETTINGS_SUCCESS_SIGN_OUT, Toast.LENGTH_SHORT)
context,
context.getString(R.string.settings_toast_success_sign_out),
Toast.LENGTH_SHORT)
.show()
}
Log.d(LOG_SETTINGS_TAG, LOG_SETTINGS_SUCCESS_SIGN_OUT)
Log.d(LOG_SETTINGS_TAG, "Sign out successful")
navigationActions.navigateTo(Screen.SIGN_IN)
},
onFailure = {
Handler(Looper.getMainLooper())
.post { // used to show the Toast on the main thread
Toast.makeText(
context, TOAST_SETTINGS_FAILURE_SIGN_OUT, Toast.LENGTH_SHORT)
context,
context.getString(R.string.settings_toast_failure_sign_out),
Toast.LENGTH_SHORT)
.show()
}
Log.d(LOG_SETTINGS_TAG, LOG_SETTINGS_FAILURE_SIGN_OUT)
Log.d(LOG_SETTINGS_TAG, "Failed to sign out")
})
},
icon = Icons.AutoMirrored.Outlined.Logout,
textTestTag = SettingsScreen.SIGN_OUT_TEXT,
iconTestTag = SettingsScreen.SIGN_OUT_ICON,
)
SettingsIconRow(
text = ACCOUNT_DELETE,
text = context.getString(R.string.settings_account_delete),
onClick = { showDialog = true },
icon = Icons.Outlined.Delete,
textTestTag = SettingsScreen.DELETE_ACCOUNT_TEXT,
Expand Down Expand Up @@ -502,7 +473,7 @@ private fun DeleteAccountDialog(
)
Text(
modifier = Modifier.wrapContentSize().testTag(SettingsScreen.CARD_TEXT),
text = DIALOG_TEXT,
text = context.getString(R.string.settings_dialog_text),
style = MaterialTheme.typography.bodyMedium,
textAlign = TextAlign.Center,
)
Expand All @@ -511,40 +482,47 @@ private fun DeleteAccountDialog(
onClick = {
authenticationViewModel.loadAuthenticationUserData(
onSuccess = {
Log.d(LOG_SETTINGS_TAG, LOG_SETTINGS_SUCCESS_LOAD_DATA)
Log.d(
LOG_SETTINGS_TAG, "user data loaded successfully, deleting the user")
userViewModel.deleteUser(
authenticationViewModel.authUserData.value!!.uid,
onSuccess = {
Handler(Looper.getMainLooper())
.post { // used to show the Toast on the main thread
Toast.makeText(
context,
TOAST_SETTINGS_SUCCESS_DELETE,
context.getString(
R.string.settings_toast_success_delete),
Toast.LENGTH_SHORT)
.show()
}
Log.d(LOG_SETTINGS_TAG, LOG_SETTINGS_SUCCESS_DELETE)
Log.d(LOG_SETTINGS_TAG, "Account deleted successfully")
navigationActions.navigateTo(Screen.SIGN_IN)
},
onFailure = {
Handler(Looper.getMainLooper())
.post { // used to show the Toast on the main thread
Toast.makeText(
context,
TOAST_SETTINGS_FAILURE_DELETE,
context.getString(
R.string.settings_toast_failure_delete),
Toast.LENGTH_SHORT)
.show()
}
Log.d(LOG_SETTINGS_TAG, LOG_SETTINGS_FAILURE_DELETE)
Log.d(LOG_SETTINGS_TAG, "Failed to delete account")
})
},
onFailure = {
Handler(Looper.getMainLooper())
.post { // used to show the Toast on the main thread
Toast.makeText(context, TOAST_LOAD_DATA_FAILURE, Toast.LENGTH_SHORT)
Toast.makeText(
context,
context.getString(
R.string.settings_toast_load_data_failure),
Toast.LENGTH_SHORT)
.show()
}
Log.d(LOG_SETTINGS_TAG, LOG_SETTINGS_FAILURE_LOAD_DATA)
Log.d(LOG_SETTINGS_TAG, "failed to load user data, can't delete the user")
})
},
colors =
Expand Down
Loading

0 comments on commit 0c3cc37

Please sign in to comment.