Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/timer/extract strings #331

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions app/src/main/java/com/android/periodpals/resources/C.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 !"
}
}
}
35 changes: 15 additions & 20 deletions app/src/main/java/com/android/periodpals/ui/timer/TimerScreen.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
*
Expand All @@ -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")
Expand All @@ -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) },
Expand All @@ -126,7 +119,9 @@ fun TimerScreen(

// Displayed text
Text(
text = activeTimer.value?.instructionText ?: DISPLAYED_TEXT_START,
text =
activeTimer.value?.instructionText
?: context.getString(R.string.timer_displayed_text_start),
modifier = Modifier.testTag(TimerScreen.DISPLAYED_TEXT),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodyMedium,
Expand All @@ -144,23 +139,23 @@ 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(),
)

// 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(),
)
} else {
// Start Button
TimerButton(
text = START,
text = context.getString(R.string.timer_start),
modifier = Modifier.testTag(TimerScreen.START_BUTTON),
onClick = { timerViewModel.startTimer() },
colors = getFilledPrimaryButtonColors(),
Expand All @@ -169,7 +164,7 @@ fun TimerScreen(
}

// Useful tip
UsefulTip()
UsefulTip(context)

// Average time
Text(
Expand Down Expand Up @@ -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)) {
Expand All @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
<resources>
<string name="app_name">PeriodPals</string>
<string name="google_client_id">683519755288-5dhnhoqhelf1lfsdpb9l1a8lghe445c5.apps.googleusercontent.com</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>
<string name="timer_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.
</string>
<string name="timer_start">START</string>
<string name="timer_reset">RESET</string>
<string name="timer_stop">STOP</string>


</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -166,6 +174,7 @@ class TimerScreenTest {
.onNodeWithTag(TimerScreen.START_BUTTON)
.performScrollTo()
.assertIsDisplayed()
.assertTextEquals(getResourceString(R.string.timer_start))
.performClick()
verify(timerViewModel).startTimer(any(), any())
}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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())
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading