Skip to content

Commit

Permalink
Merge pull request #225 from SwEnt-Group8/fix/strings-xml
Browse files Browse the repository at this point in the history
fix: fixed erroneous string.xml use in park overview screen
  • Loading branch information
misterM125 authored Dec 12, 2024
2 parents d7df338 + b33a738 commit f70d621
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.android.streetworkapp.ui.parkoverview

import android.content.Context
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.assertTextEquals
Expand Down Expand Up @@ -143,6 +145,7 @@ class ParkOverviewTest {
it.getArgument<(List<Event>) -> Unit>(1)(listOf(eventList.events.first()))
}
parkViewModel.setCurrentPark(park)
var context: Context? = null

composeTestRule.setContent {
ParkOverviewScreen(
Expand All @@ -151,6 +154,7 @@ class ParkOverviewTest {
navigationActions = navigationActions,
userViewModel = userViewModel,
imageViewModel = imageViewModel)
context = LocalContext.current
}
composeTestRule.waitForIdle()

Expand All @@ -159,9 +163,10 @@ class ParkOverviewTest {
composeTestRule.onNodeWithTag("createEventButton").assertIsDisplayed()
composeTestRule.onNodeWithTag("eventItem").assertTextContains("Group workout")
composeTestRule.onNodeWithTag("participantsText", useUnmergedTree = true)
assert(context != null)
composeTestRule
.onNodeWithTag("dateText", useUnmergedTree = true)
.assertTextContains(dateDifference(eventList.events.first()))
.assertTextContains(dateDifference(context!!, eventList.events.first()))
composeTestRule
.onNodeWithTag("eventButtonText", useUnmergedTree = true)
.assertTextContains("About")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.DirectionsRun
import androidx.compose.material.icons.filled.DirectionsRun
import androidx.compose.material.icons.filled.QuestionMark
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.filled.Timelapse
Expand Down Expand Up @@ -444,7 +443,7 @@ fun EventItem(event: Event, eventViewModel: EventViewModel, navigationActions: N
},
overlineContent = {
Text(
text = dateDifference(event),
text = dateDifference(LocalContext.current, event),
fontWeight = FontWeight.Bold,
modifier = Modifier.testTag("dateText"))
},
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/com/android/streetworkapp/utils/DateUtils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android.streetworkapp.utils

import android.content.Context
import com.android.sample.R
import com.android.streetworkapp.model.event.Event
import com.android.streetworkapp.model.event.EventStatus
Expand Down Expand Up @@ -66,7 +67,7 @@ fun String.toEpochTimestamp(): Long {
* @param event the event to calculate the difference for.
* @return The difference in days or hours.
*/
fun dateDifference(event: Event): String {
fun dateDifference(context: Context, event: Event): String {
val formatter = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN)

val endTimestamp = event.date.toFormattedString()
Expand All @@ -81,16 +82,16 @@ fun dateDifference(event: Event): String {

val statusText =
when (event.status) {
EventStatus.STARTED -> R.string.event_started.toString()
EventStatus.ENDED -> R.string.event_ended.toString()
EventStatus.CREATED -> R.string.event_soon.toString()
EventStatus.STARTED -> R.string.event_started
EventStatus.ENDED -> R.string.event_ended
EventStatus.CREATED -> R.string.event_soon
}

return if (days > 0) {
"in $days day(s)"
} else {
if (hours <= 0) {
statusText
context.getString(statusText)
} else {
"in $hours hour(s)"
}
Expand Down

0 comments on commit f70d621

Please sign in to comment.