From dc12bd0db4e33761497b9e4f69553eb1669016dd Mon Sep 17 00:00:00 2001 From: taghizadlaura Date: Tue, 17 Dec 2024 19:23:08 +0100 Subject: [PATCH 1/3] fix: add TimerScreen strings to strings.xml - Add string resources for TimerScreen including title, start text, useful tip, and button labels (START, RESET, STOP). - Adapt TimerScreen to use the new string resources. --- .../periodpals/ui/timer/TimerScreen.kt | 35 ++++++++----------- app/src/main/res/values/strings.xml | 14 ++++++++ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/android/periodpals/ui/timer/TimerScreen.kt b/app/src/main/java/com/android/periodpals/ui/timer/TimerScreen.kt index 53abeb665..0842f9ff3 100644 --- a/app/src/main/java/com/android/periodpals/ui/timer/TimerScreen.kt +++ b/app/src/main/java/com/android/periodpals/ui/timer/TimerScreen.kt @@ -1,5 +1,6 @@ package com.android.periodpals.ui.timer +import android.content.Context import android.util.Log import androidx.compose.animation.core.LinearEasing import androidx.compose.animation.core.TweenSpec @@ -40,8 +41,10 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.rotate import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.StrokeCap +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.model.timer.COUNTDOWN_DURATION import com.android.periodpals.model.timer.HOUR @@ -59,20 +62,8 @@ import com.android.periodpals.ui.navigation.TopAppBar import com.android.periodpals.ui.theme.dimens import kotlin.math.abs -private const val SCREEN_TITLE = "Tampon Timer" private const val TAG = "TimerScreen" -private const val DISPLAYED_TEXT_START = - "Start your tampon timer.\n" + "You’ll be reminded to change it !" -private const val USEFUL_TIP_TEXT = - "Leaving a tampon in for over 3-4 hours too often can cause irritation and infections." + - " Regular changes are essential to avoid risks." + - " Choosing cotton or natural tampons helps reduce irritation and improve hygiene." - -private const val RESET = "RESET" -private const val STOP = "STOP" -private const val START = "START" - /** * Composable function for the Timer screen. * @@ -92,6 +83,8 @@ fun TimerScreen( val isRunning by remember { mutableStateOf(timerViewModel.isRunning) } val userAverageTimer by remember { mutableStateOf(timerViewModel.userAverageTimer) } + val context = LocalContext.current + authenticationViewModel.loadAuthenticationUserData( onSuccess = { Log.d(TAG, "Successfully loaded user data") @@ -100,7 +93,7 @@ fun TimerScreen( Scaffold( modifier = Modifier.fillMaxSize().testTag(TimerScreen.SCREEN), - topBar = { TopAppBar(title = SCREEN_TITLE) }, + topBar = { TopAppBar(title = context.getString(R.string.timer_screen_title)) }, bottomBar = { BottomNavigationMenu( onTabSelect = { route -> navigationActions.navigateTo(route) }, @@ -126,7 +119,9 @@ fun TimerScreen( // Displayed text Text( - text = activeTimer.value?.instructionText ?: DISPLAYED_TEXT_START, + text = + activeTimer.value?.instructionText + ?: context.getString(R.string.displayed_text_start), modifier = Modifier.testTag(TimerScreen.DISPLAYED_TEXT), textAlign = TextAlign.Center, style = MaterialTheme.typography.bodyMedium, @@ -144,7 +139,7 @@ fun TimerScreen( if (isRunning.value) { // Reset Button TimerButton( - text = RESET, + text = context.getString(R.string.timer_reset), modifier = Modifier.testTag(TimerScreen.RESET_BUTTON), onClick = { timerViewModel.resetTimer() }, colors = getInverseSurfaceButtonColors(), @@ -152,7 +147,7 @@ fun TimerScreen( // Stop Button TimerButton( - text = STOP, + text = context.getString(R.string.timer_stop), modifier = Modifier.testTag(TimerScreen.STOP_BUTTON), onClick = { timerViewModel.stopTimer(uid = authUserData.value?.uid ?: "") }, colors = getErrorButtonColors(), @@ -160,7 +155,7 @@ fun TimerScreen( } else { // Start Button TimerButton( - text = START, + text = context.getString(R.string.timer_start), modifier = Modifier.testTag(TimerScreen.START_BUTTON), onClick = { timerViewModel.startTimer() }, colors = getFilledPrimaryButtonColors(), @@ -169,7 +164,7 @@ fun TimerScreen( } // Useful tip - UsefulTip() + UsefulTip(context) // Average time Text( @@ -334,7 +329,7 @@ fun TimerButton( * - Icon: `TimerScreen.USEFUL_TIP` */ @Composable -fun UsefulTip() { +fun UsefulTip(context: Context) { Row( modifier = Modifier.testTag(TimerScreen.USEFUL_TIP), horizontalArrangement = Arrangement.spacedBy(MaterialTheme.dimens.small2)) { @@ -355,7 +350,7 @@ fun UsefulTip() { thickness = MaterialTheme.dimens.borderLine, color = MaterialTheme.colorScheme.outlineVariant) Text( - text = USEFUL_TIP_TEXT, + text = context.getString(R.string.timer_useful_tip_text), modifier = Modifier.testTag(TimerScreen.USEFUL_TIP_TEXT), textAlign = TextAlign.Center, style = MaterialTheme.typography.bodyMedium, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 110e9e6a0..9deab8b91 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,18 @@ PeriodPals 683519755288-5dhnhoqhelf1lfsdpb9l1a8lghe445c5.apps.googleusercontent.com + + + Tampon Timer + Start your tampon timer.\nYou’ll be reminded to change it! + + Leaving a tampon in for over 3-4 hours too often can cause irritation and infections. + Regular changes are essential to avoid risks. + Choosing cotton or natural tampons helps reduce irritation and improve hygiene. + + START + RESET + STOP + + \ No newline at end of file From 43c822d37d9f08e342d55d39fe62c019e4cce832 Mon Sep 17 00:00:00 2001 From: taghizadlaura Date: Tue, 17 Dec 2024 20:15:12 +0100 Subject: [PATCH 2/3] test: update TimerScreenTest to ensure the correct string resources are being used. Also refactor `displayed_text_start` into `timer_displayed_text_start` for better consistency. --- .../periodpals/ui/timer/TimerScreen.kt | 2 +- app/src/main/res/values/strings.xml | 2 +- .../periodpals/ui/timer/TimerScreenTest.kt | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/android/periodpals/ui/timer/TimerScreen.kt b/app/src/main/java/com/android/periodpals/ui/timer/TimerScreen.kt index 0842f9ff3..add22f6a8 100644 --- a/app/src/main/java/com/android/periodpals/ui/timer/TimerScreen.kt +++ b/app/src/main/java/com/android/periodpals/ui/timer/TimerScreen.kt @@ -121,7 +121,7 @@ fun TimerScreen( Text( text = activeTimer.value?.instructionText - ?: context.getString(R.string.displayed_text_start), + ?: context.getString(R.string.timer_displayed_text_start), modifier = Modifier.testTag(TimerScreen.DISPLAYED_TEXT), textAlign = TextAlign.Center, style = MaterialTheme.typography.bodyMedium, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9deab8b91..625774b06 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,7 +4,7 @@ Tampon Timer - Start your tampon timer.\nYou’ll be reminded to change it! + Start your tampon timer.\nYou’ll be reminded to change it! Leaving a tampon in for over 3-4 hours too often can cause irritation and infections. Regular changes are essential to avoid risks. diff --git a/app/src/test/java/com/android/periodpals/ui/timer/TimerScreenTest.kt b/app/src/test/java/com/android/periodpals/ui/timer/TimerScreenTest.kt index 2c7f32f4b..d207766db 100644 --- a/app/src/test/java/com/android/periodpals/ui/timer/TimerScreenTest.kt +++ b/app/src/test/java/com/android/periodpals/ui/timer/TimerScreenTest.kt @@ -10,6 +10,7 @@ import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollTo import androidx.lifecycle.MutableLiveData +import com.android.periodpals.R import com.android.periodpals.model.authentication.AuthenticationViewModel import com.android.periodpals.model.timer.COUNTDOWN_DURATION import com.android.periodpals.model.timer.Timer @@ -19,6 +20,7 @@ import com.android.periodpals.resources.C.Tag.TimerScreen import com.android.periodpals.resources.C.Tag.TopAppBar import com.android.periodpals.ui.navigation.NavigationActions import com.android.periodpals.ui.navigation.Route +import io.github.kakaocup.kakao.common.utilities.getResourceString import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Rule @@ -77,7 +79,7 @@ class TimerScreenTest { composeTestRule .onNodeWithTag(TopAppBar.TITLE_TEXT) .assertIsDisplayed() - .assertTextEquals("Tampon Timer") + .assertTextEquals(getResourceString(R.string.timer_screen_title)) composeTestRule.onNodeWithTag(TopAppBar.GO_BACK_BUTTON).assertIsNotDisplayed() composeTestRule.onNodeWithTag(TopAppBar.SETTINGS_BUTTON).assertIsNotDisplayed() composeTestRule.onNodeWithTag(TopAppBar.CHAT_BUTTON).assertIsNotDisplayed() @@ -93,10 +95,16 @@ class TimerScreenTest { .onNodeWithTag(TimerScreen.START_BUTTON) .performScrollTo() .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_start)) .assertHasClickAction() composeTestRule.onNodeWithTag(TimerScreen.RESET_BUTTON).assertIsNotDisplayed() composeTestRule.onNodeWithTag(TimerScreen.STOP_BUTTON).assertIsNotDisplayed() composeTestRule.onNodeWithTag(TimerScreen.USEFUL_TIP).performScrollTo().assertIsDisplayed() + composeTestRule + .onNodeWithTag(TimerScreen.USEFUL_TIP_TEXT) + .performScrollTo() + .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_useful_tip_text)) } @Test @@ -166,6 +174,7 @@ class TimerScreenTest { .onNodeWithTag(TimerScreen.START_BUTTON) .performScrollTo() .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_start)) .performClick() verify(timerViewModel).startTimer(any(), any()) } @@ -183,6 +192,7 @@ class TimerScreenTest { .onNodeWithTag(TimerScreen.START_BUTTON) .performScrollTo() .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_start)) .performClick() verify(timerViewModel).startTimer(any(), any()) assertEquals(false, timerViewModel.isRunning.value) @@ -200,6 +210,7 @@ class TimerScreenTest { .onNodeWithTag(TimerScreen.START_BUTTON) .performScrollTo() .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_start)) .assertHasClickAction() verify(timerViewModel, never()).startTimer(any(), any()) assertEquals(false, isRunning.value) @@ -220,6 +231,7 @@ class TimerScreenTest { .onNodeWithTag(TimerScreen.RESET_BUTTON) .performScrollTo() .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_reset)) .performClick() verify(timerViewModel).resetTimer(any(), any()) assertEquals(false, isRunning.value) @@ -239,6 +251,7 @@ class TimerScreenTest { .onNodeWithTag(TimerScreen.RESET_BUTTON) .performScrollTo() .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_reset)) .performClick() verify(timerViewModel).resetTimer(any(), any()) assertEquals(true, isRunning.value) @@ -257,6 +270,7 @@ class TimerScreenTest { .onNodeWithTag(TimerScreen.RESET_BUTTON) .performScrollTo() .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_reset)) .assertHasClickAction() verify(timerViewModel, never()).resetTimer(any(), any()) assertEquals(true, isRunning.value) @@ -277,6 +291,7 @@ class TimerScreenTest { .onNodeWithTag(TimerScreen.STOP_BUTTON) .performScrollTo() .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_stop)) .performClick() verify(timerViewModel).stopTimer(eq(UID), any(), any()) @@ -297,6 +312,7 @@ class TimerScreenTest { .onNodeWithTag(TimerScreen.STOP_BUTTON) .performScrollTo() .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_stop)) .performClick() verify(timerViewModel).stopTimer(eq(UID), any(), any()) assertEquals(true, isRunning.value) @@ -315,6 +331,7 @@ class TimerScreenTest { .onNodeWithTag(TimerScreen.STOP_BUTTON) .performScrollTo() .assertIsDisplayed() + .assertTextEquals(getResourceString(R.string.timer_stop)) .assertHasClickAction() verify(timerViewModel, never()).stopTimer(any(), any(), any()) assertEquals(true, isRunning.value) From 3b6ef671ace246d26f6db4622777f6ac39c96c1f Mon Sep 17 00:00:00 2001 From: taghizadlaura Date: Wed, 18 Dec 2024 20:38:54 +0100 Subject: [PATCH 3/3] refactor: remove unused Timer tags in `C.kt` --- app/src/main/java/com/android/periodpals/resources/C.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/main/java/com/android/periodpals/resources/C.kt b/app/src/main/java/com/android/periodpals/resources/C.kt index 90c285407..7ca7405b2 100644 --- a/app/src/main/java/com/android/periodpals/resources/C.kt +++ b/app/src/main/java/com/android/periodpals/resources/C.kt @@ -213,12 +213,6 @@ object C { const val STOP_BUTTON = "Stop button" const val USEFUL_TIP = "usefulTip" const val USEFUL_TIP_TEXT = "usefulTipText" - - // Displayed texts - const val DISPLAYED_TEXT_ONE = - "Start your tampon timer.\n" + "You’ll be reminded to change it !" - const val DISPLAYED_TEXT_TWO = - "You’ve got this. Stay strong !\n" + "Don’t forget to stay hydrated !" } } }