Skip to content

Commit

Permalink
Merge pull request #335 from PeriodPals/fix/misc/auth-map-extract-str…
Browse files Browse the repository at this point in the history
…ings

Fix/misc/auth map extract strings
  • Loading branch information
taghizadlaura authored Dec 19, 2024
2 parents b8f3902 + 3f31a69 commit 3969efc
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ import kotlinx.coroutines.launch

private const val DEFAULT_IS_PASSWORD_VISIBLE = false

private const val SIGN_IN_INSTRUCTION = "Sign in to your account"
private const val SIGN_IN_BUTTON_TEXT = "Sign in"
private const val CONTINUE_WITH_TEXT = "Or continue with"
private const val SIGN_UP_WITH_GOOGLE = "Sign in with Google"
private const val NO_ACCOUNT_TEXT = "Not registered yet? "
private const val SIGN_UP_TEXT = "Sign up here!"

private const val SUCCESSFUL_SIGN_IN_TOAST = "Login Successful"
private const val FAILED_SIGN_IN_TOAST = "Login Failed"
private const val INVALID_ATTEMPT_TOAST = "Invalid email or password."

/**
* Composable function that displays the Sign In screen.
*
Expand Down Expand Up @@ -116,7 +105,7 @@ fun SignInScreen(
Text(
modifier =
Modifier.fillMaxWidth().wrapContentHeight().testTag(SignInScreen.INSTRUCTION_TEXT),
text = SIGN_IN_INSTRUCTION,
text = context.getString(R.string.sign_in_instruction),
color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodyLarge,
Expand All @@ -137,7 +126,7 @@ fun SignInScreen(
)

AuthenticationSubmitButton(
text = SIGN_IN_BUTTON_TEXT,
text = context.getString(R.string.sign_in_button_text),
onClick = {
attemptSignIn(
emailState = emailState,
Expand All @@ -155,7 +144,7 @@ fun SignInScreen(
Modifier.fillMaxWidth()
.wrapContentHeight()
.testTag(SignInScreen.CONTINUE_WITH_TEXT),
text = CONTINUE_WITH_TEXT,
text = context.getString(R.string.sign_in_continue_with_text),
color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodyLarge,
Expand All @@ -165,8 +154,8 @@ fun SignInScreen(
}

NavigateBetweenAuthScreens(
NO_ACCOUNT_TEXT,
SIGN_UP_TEXT,
context.getString(R.string.sign_in_no_account_text),
context.getString(R.string.sign_in_sign_up_text),
Screen.SIGN_UP,
SignInScreen.NOT_REGISTERED_NAV_LINK,
navigationActions)
Expand Down Expand Up @@ -214,7 +203,7 @@ fun AuthenticationGoogleButton(
)
Text(
modifier = Modifier.wrapContentSize(),
text = SIGN_UP_WITH_GOOGLE,
text = context.getString(R.string.sign_in_sign_up_with_google),
fontWeight = FontWeight.Medium,
style = MaterialTheme.typography.bodyMedium,
)
Expand All @@ -240,7 +229,9 @@ private fun attemptSignIn(
navigationActions: NavigationActions,
) {
if (!emailState.validate() || !passwordState.validate()) {
Toast.makeText(context, INVALID_ATTEMPT_TOAST, Toast.LENGTH_SHORT).show()
Toast.makeText(
context, context.getString(R.string.sign_in_toast_invalid_attempt), Toast.LENGTH_SHORT)
.show()
return
}

Expand All @@ -249,14 +240,22 @@ private fun attemptSignIn(
userPassword = passwordState.value,
onSuccess = {
Handler(Looper.getMainLooper()).post {
Toast.makeText(context, SUCCESSFUL_SIGN_IN_TOAST, Toast.LENGTH_SHORT).show()
Toast.makeText(
context,
context.getString(R.string.sign_in_toast_successful_sign_in),
Toast.LENGTH_SHORT)
.show()
}
PushNotificationsServiceImpl().createDeviceToken()
navigationActions.navigateTo(Screen.PROFILE)
},
onFailure = {
Handler(Looper.getMainLooper()).post {
Toast.makeText(context, FAILED_SIGN_IN_TOAST, Toast.LENGTH_SHORT).show()
Toast.makeText(
context,
context.getString(R.string.sign_in_toast_failed_sign_in),
Toast.LENGTH_SHORT)
.show()
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
import com.android.periodpals.R
import com.android.periodpals.model.authentication.AuthenticationViewModel
import com.android.periodpals.resources.C.Tag.AuthenticationScreens.SignUpScreen
import com.android.periodpals.services.PushNotificationsServiceImpl
Expand All @@ -43,18 +44,6 @@ import com.dsc.form_builder.TextFieldState

private const val DEFAULT_IS_PASSWORD_VISIBLE = false

private const val SIGN_UP_INSTRUCTION = "Create your account"
private const val CONFIRM_PASSWORD_INSTRUCTION = "Confirm your password"
private const val SIGN_UP_BUTTON_TEXT = "Sign up"

private const val NOT_MATCHING_PASSWORD_ERROR_MESSAGE = "Passwords do not match"
private const val ALREADY_ACCOUNT_TEXT = "Already registered ? "
private const val SIGN_IN_TEXT = "Sign in!"

private const val SUCCESSFUL_SIGN_UP_TOAST = "Account Creation Successful"
private const val FAILED_SIGN_UP_TOAST = "Account Creation Failed"
private const val INVALID_ATTEMPT_TOAST = "Invalid email or password"

/**
* A composable function that displays the sign-up screen.
*
Expand Down Expand Up @@ -101,7 +90,7 @@ fun SignUpScreen(
Text(
modifier =
Modifier.fillMaxWidth().wrapContentHeight().testTag(SignUpScreen.INSTRUCTION_TEXT),
text = SIGN_UP_INSTRUCTION,
text = context.getString(R.string.sign_up_instruction),
color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodyLarge,
Expand All @@ -126,7 +115,7 @@ fun SignUpScreen(
Modifier.fillMaxWidth()
.wrapContentHeight()
.testTag(SignUpScreen.CONFIRM_PASSWORD_TEXT),
text = CONFIRM_PASSWORD_INSTRUCTION,
text = context.getString(R.string.sign_up_confirm_password_instruction),
color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodyLarge,
Expand All @@ -146,7 +135,7 @@ fun SignUpScreen(
)

AuthenticationSubmitButton(
text = SIGN_UP_BUTTON_TEXT,
text = context.getString(R.string.sign_up_button_text),
onClick = {
attemptSignUp(
emailState = emailState,
Expand All @@ -162,8 +151,8 @@ fun SignUpScreen(
}

NavigateBetweenAuthScreens(
ALREADY_ACCOUNT_TEXT,
SIGN_IN_TEXT,
context.getString(R.string.sign_up_already_account_text),
context.getString(R.string.sign_up_sign_in_text),
Screen.SIGN_IN,
SignUpScreen.ALREADY_REGISTERED_NAV_LINK,
navigationActions)
Expand Down Expand Up @@ -191,12 +180,17 @@ private fun attemptSignUp(
) {
// strange if statements, but necessary to show the proper error messages
if (!emailState.validate() || !passwordState.validate()) {
Toast.makeText(context, INVALID_ATTEMPT_TOAST, Toast.LENGTH_SHORT).show()
Toast.makeText(
context, context.getString(R.string.sign_up_toast_invalid_attempt), Toast.LENGTH_SHORT)
.show()
return
}
if (!confirmPasswordState.validate() || passwordState.value != confirmPasswordState.value) {
confirmPasswordState.errorMessage = NOT_MATCHING_PASSWORD_ERROR_MESSAGE
Toast.makeText(context, INVALID_ATTEMPT_TOAST, Toast.LENGTH_SHORT).show()
confirmPasswordState.errorMessage =
context.getString(R.string.sign_up_not_matching_password_error_message)
Toast.makeText(
context, context.getString(R.string.sign_up_toast_invalid_attempt), Toast.LENGTH_SHORT)
.show()
return
}

Expand All @@ -205,14 +199,22 @@ private fun attemptSignUp(
userPassword = passwordState.value,
onSuccess = {
Handler(Looper.getMainLooper()).post {
Toast.makeText(context, SUCCESSFUL_SIGN_UP_TOAST, Toast.LENGTH_SHORT).show()
Toast.makeText(
context,
context.getString(R.string.sign_up_toast_successful_sign_up),
Toast.LENGTH_SHORT)
.show()
}
PushNotificationsServiceImpl().createDeviceToken()
navigationActions.navigateTo(Screen.CREATE_PROFILE)
},
onFailure = { _: Exception ->
Handler(Looper.getMainLooper()).post {
Toast.makeText(context, FAILED_SIGN_UP_TOAST, Toast.LENGTH_SHORT).show()
Toast.makeText(
context,
context.getString(R.string.sign_up_toast_failed_sign_up),
Toast.LENGTH_SHORT)
.show()
}
},
)
Expand Down
39 changes: 22 additions & 17 deletions app/src/main/java/com/android/periodpals/ui/map/Map.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,11 @@ import org.osmdroid.views.overlay.Marker
import org.osmdroid.views.overlay.Polygon

private const val TAG = "MapScreen"
private const val SCREEN_TITLE = "Map"
private const val YOUR_LOCATION_MARKER_TITLE = "Your location"

private const val MIN_ZOOM_LEVEL = 5.0
private const val MAX_ZOOM_LEVEL = 19.0
private const val INITIAL_ZOOM_LEVEL = 17.0

private const val LIGHT_TILES_URL = "https://tiles.stadiamaps.com/tiles/alidade_smooth/"
private const val DARK_TILES_URL = "https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/"
private const val DARK_TILES_NAME = "dark_tiles"
private const val LIGHT_TILES_NAME = "light_tiles"

/**
* Screen that displays the top app bar, bottom navigation bar and a map. The map contains:
* - the location of the user, along a translucent confidence circle representing the accuracy of
Expand Down Expand Up @@ -93,7 +86,8 @@ fun MapScreen(
myLocationOverlay = myLocationOverlay,
alertsOverlay = alertOverlay,
location = myLocation,
isDarkTheme = isDarkTheme)
isDarkTheme = isDarkTheme,
context = context)
}

FetchAlertsAndDrawMarkers(
Expand All @@ -111,7 +105,7 @@ fun MapScreen(
tabList = LIST_TOP_LEVEL_DESTINATION,
selectedItem = navigationActions.currentRoute())
},
topBar = { TopAppBar(title = SCREEN_TITLE) },
topBar = { TopAppBar(title = context.getString(R.string.map_screen_title)) },
floatingActionButton = {
FloatingActionButton(
onClick = { recenterOnMyLocation(mapView, myLocation) },
Expand Down Expand Up @@ -178,16 +172,22 @@ private fun FetchAlertsAndDrawMarkers(
}

/**
* Initializes the map to a given zoom level at the user's location.
* Initializes the map with the given parameters.
*
* @param mapView primary view for `osmdroid`.
* @param mapView The primary view for `osmdroid`.
* @param myLocationOverlay The overlay for the user's location.
* @param alertsOverlay The overlay for the alerts.
* @param location The initial location to center the map on.
* @param isDarkTheme True if the device is in dark theme.
* @param context The context of the activity.
*/
private fun initializeMap(
mapView: MapView,
myLocationOverlay: FolderOverlay,
alertsOverlay: FolderOverlay,
location: Location,
isDarkTheme: Boolean
isDarkTheme: Boolean,
context: Context
) {
mapView.apply {
setMultiTouchControls(true)
Expand All @@ -199,7 +199,7 @@ private fun initializeMap(
this.overlays.add(myLocationOverlay)
this.overlays.add(alertsOverlay)
}
setTileSource(mapView = mapView, isDarkTheme = isDarkTheme)
setTileSource(mapView = mapView, isDarkTheme = isDarkTheme, context = context)
}

/**
Expand Down Expand Up @@ -256,7 +256,7 @@ private fun updateMyLocationMarker(
Marker(mapView).apply {
position = myLocation.toGeoPoint()
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
title = YOUR_LOCATION_MARKER_TITLE
title = context.getString(R.string.map_your_location_marker_title)
icon = ContextCompat.getDrawable(context, R.drawable.location)
infoWindow = null // Hide the pop-up that appears when you click on a marker
setOnMarkerClickListener { marker, mapView ->
Expand Down Expand Up @@ -289,14 +289,19 @@ private fun updateMyLocationMarker(
*
* @param mapView The view of the map in which the tile source will be used
* @param isDarkTheme True if the device is in dark theme
* @param context The context of the activity
*/
private fun setTileSource(mapView: MapView, isDarkTheme: Boolean) {
private fun setTileSource(mapView: MapView, isDarkTheme: Boolean, context: Context) {

val fileNameExtension = ".png"
val tileSize = 256

val tileName = if (isDarkTheme) DARK_TILES_NAME else LIGHT_TILES_NAME
val tileUrl = if (isDarkTheme) DARK_TILES_URL else LIGHT_TILES_URL
val tileName =
if (isDarkTheme) context.getString(R.string.dark_tiles_name)
else context.getString(R.string.light_tiles_name)
val tileUrl =
if (isDarkTheme) context.getString(R.string.dark_tiles_url)
else context.getString(R.string.light_tiles_url)

val customTileSource =
object :
Expand Down
38 changes: 37 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@
<string name="app_name">PeriodPals</string>
<string name="google_client_id">683519755288-5dhnhoqhelf1lfsdpb9l1a8lghe445c5.apps.googleusercontent.com</string>

<!-- Sign In Screen -->
<string name="sign_in_instruction">Sign in to your account</string>
<string name="sign_in_button_text">Sign in</string>
<string name="sign_in_continue_with_text">Or continue with</string>
<string name="sign_in_sign_up_with_google">Sign in with Google</string>
<string name="sign_in_no_account_text">Not registered yet?\u00A0</string>
<string name="sign_in_sign_up_text">Sign up here!</string>

<string name="sign_in_toast_successful_sign_in">Login Successful</string>
<string name="sign_in_toast_failed_sign_in">Login Failed</string>
<string name="sign_in_toast_invalid_attempt">Invalid email or password.</string>

<!-- Sign Up Screen -->
<string name="sign_up_instruction">Create your account</string>
<string name="sign_up_confirm_password_instruction">Confirm your password</string>
<string name="sign_up_button_text">Sign up</string>
<string name="sign_up_already_account_text">Already registered?\u00A0</string>
<string name="sign_up_sign_in_text">Sign in!</string>

<string name="sign_up_toast_successful_sign_up">Account Creation Successful</string>
<string name="sign_up_toast_failed_sign_up">Account Creation Failed</string>
<string name="sign_up_toast_invalid_attempt">Invalid email or password</string>

<string name="sign_up_not_matching_password_error_message">Passwords do not match</string>

<!-- Create Profile Screen -->
<string name="create_profile_screen_title">Create Your Account</string>
<string name="create_profile_radius_explanation_text">
Expand Down Expand Up @@ -85,6 +110,18 @@

<string name="alert_lists_filter_default">No Preference</string>

<!-- Map Screen -->
<string name="map_screen_title">Map</string>
<string name="map_your_location_marker_title">Your location</string>

<!-- Tile URLs -->
<string name="light_tiles_url">https://tiles.stadiamaps.com/tiles/alidade_smooth/</string>
<string name="dark_tiles_url">https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/</string>

<!-- Tile Names -->
<string name="light_tiles_name">light_tiles</string>
<string name="dark_tiles_name">dark_tiles</string>

<!-- Timer Screen -->
<string name="timer_screen_title">Tampon Timer</string>
<string name="timer_displayed_text_start">Start your tampon timer.\nYou’ll be reminded to change it!</string>
Expand All @@ -97,5 +134,4 @@
<string name="timer_reset">RESET</string>
<string name="timer_stop">STOP</string>


</resources>
Loading

0 comments on commit 3969efc

Please sign in to comment.