Skip to content

Commit

Permalink
Fix #3930 Greeting text on home screen should be a single TextView (#…
Browse files Browse the repository at this point in the history
…5131)

<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->
 - Fix #3930 
 
Removes `profile_name_text_view` and combines the greeting text and
profile name using one string template, `welcome_profile_name` in
`WelcomeViewModel.computeWelcomeText()`

In the `testHomeActivity_initialArabicContext_displaysStringsInArabic`
test, unicode characters `\u200F\u202A...\u202C\u200F!` are introduced
to allow bidirectional reading.

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

## For UI-specific PRs only
<!-- Delete these section if this PR does not include UI-related
changes. -->
If your PR includes UI-related changes, then:
- For the screenshots above, include both English and pseudo-localized
(RTL) screenshots (see [RTL
guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines))

### RTL:
![arabic
rtl](https://github.com/oppia/oppia-android/assets/99060332/df2d28ab-edd0-491f-9426-6c3ef69b135b)

### LTR:

![ltr](https://github.com/oppia/oppia-android/assets/99060332/1bab89aa-430d-4129-a9ae-0b34d8536f05)

---------

Co-authored-by: Adhiambo Peres <59600948+adhiamboperes@users.noreply.github.com>
  • Loading branch information
ShubhadeepKarmakar and adhiamboperes authored Oct 6, 2023
1 parent 4680a5d commit 7d0a594
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 48 deletions.
13 changes: 8 additions & 5 deletions app/src/main/java/org/oppia/android/app/home/WelcomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ class WelcomeViewModel(
dateTimeUtil: DateTimeUtil
) : HomeItemViewModel() {

/** Text [String] to greet the learner and display on-screen when launching the home activity. */
/** Text [String] to greet the learner. */
val greeting: String = dateTimeUtil.getGreetingMessage()

/**
* Returns the user-readable portion of the welcome screen greeting that contains the user's name.
* Returns the string which contains greeting message with user's name and
* display on-screen when launching the home activity.
*/
fun computeProfileNameText(): String {
return resourceHandler.getStringInLocaleWithWrapping(R.string.welcome_profile_name, profileName)
}
fun computeWelcomeText(): String = resourceHandler.getStringInLocaleWithWrapping(
R.string.welcome_profile_name,
greeting,
profileName
)

// Overriding equals is needed so that DataProvider combine functions used in the HomeViewModel
// will only rebind when the actual data in the data list changes, rather than when the ViewModel
Expand Down
11 changes: 1 addition & 10 deletions app/src/main/res/layout/welcome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/home_welcome_text_view_margin_end"
android:fontFamily="sans-serif"
android:text="@{viewModel.greeting}"
android:textColor="@color/component_color_shared_primary_text_color"
android:textSize="24sp" />

<TextView
android:id="@+id/profile_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:text="@{viewModel.computeProfileNameText()}"
android:text="@{viewModel.computeWelcomeText}"
android:textColor="@color/component_color_shared_primary_text_color"
android:textSize="24sp" />
</com.google.android.flexbox.FlexboxLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<string name="size_gb">%s GB</string>
<string name="correct">Correct!</string>
<string name="topic_prefix">Topic: %s</string>
<string name="welcome_profile_name">%s!</string>
<string name="welcome_profile_name">%s %s!</string>
<plurals name="chapter_count">
<item quantity="one">1 Chapter</item>
<item quantity="other">%s Chapters</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,6 @@ class HomeActivityTest {
assertThat(screenName).isEqualTo(ScreenName.HOME_ACTIVITY)
}

@Test
fun testHomeActivity_withAdminProfile_profileNameIsDisplayed() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.profile_name_text_view,
stringToMatch = "Admin!"
)
}
}

@Test
fun testHomeActivity_hasCorrectActivityLabel() {
launch(HomeActivity::class.java).use { scenario ->
Expand All @@ -271,59 +258,61 @@ class HomeActivityTest {

@Test
fun testHomeActivity_withAdminProfile_configChange_profileNameIsDisplayed() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(EVENING_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.profile_name_text_view,
stringToMatch = "Admin!"
targetViewId = R.id.welcome_text_view,
stringToMatch = "Good evening, Admin!"
)
}
}

@Test
fun testHomeActivity_morningTimestamp_goodMorningMessageIsDisplayed() {
fun testHomeActivity_morningTimestamp_goodMorningMessageIsDisplayed_withAdminProfileName() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(MORNING_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId1)).use {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Good morning,"
stringToMatch = "Good morning, Admin!"
)
}
}

@Test
fun testHomeActivity_afternoonTimestamp_goodAfternoonMessageIsDisplayed() {
fun testHomeActivity_afternoonTimestamp_goodAfternoonMessageIsDisplayed_withAdminProfileName() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(AFTERNOON_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId1)).use {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Good afternoon,"
stringToMatch = "Good afternoon, Admin!"
)
}
}

@Test
fun testHomeActivity_eveningTimestamp_goodEveningMessageIsDisplayed() {
fun testHomeActivity_eveningTimestamp_goodEveningMessageIsDisplayed_withAdminProfileName() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(EVENING_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId1)).use {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Good evening,"
stringToMatch = "Good evening, Admin!"
)
}
}
Expand Down Expand Up @@ -1094,7 +1083,7 @@ class HomeActivityTest {
atPositionOnView(
R.id.home_recycler_view,
0,
R.id.profile_name_text_view
R.id.welcome_text_view
)
).check(matches(not(isEllipsized())))
}
Expand All @@ -1113,7 +1102,7 @@ class HomeActivityTest {
atPositionOnView(
R.id.home_recycler_view,
0,
R.id.profile_name_text_view
R.id.welcome_text_view
)
).check(matches(not(isEllipsized())))
}
Expand All @@ -1131,7 +1120,7 @@ class HomeActivityTest {
atPositionOnView(
R.id.home_recycler_view,
0,
R.id.profile_name_text_view
R.id.welcome_text_view
)
).check(matches(not(isEllipsized())))
}
Expand All @@ -1150,7 +1139,7 @@ class HomeActivityTest {
atPositionOnView(
R.id.home_recycler_view,
0,
R.id.profile_name_text_view
R.id.welcome_text_view
)
).check(matches(not(isEllipsized())))
}
Expand Down Expand Up @@ -1574,7 +1563,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Good morning,"
stringToMatch = "Good morning, Admin!"
)
}
}
Expand Down Expand Up @@ -1634,7 +1623,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Bom dia,"
stringToMatch = "Bom dia, Admin!"
)
assertThat(testActivityRecreator.getRecreateCount()).isEqualTo(1)
// Verify that the display locale is set up correctly (for string formatting).
Expand Down Expand Up @@ -1664,7 +1653,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "صباح الخير"
stringToMatch = "صباح الخير \u200F\u202AAdmin\u202C\u200F!"
)
}
}
Expand Down Expand Up @@ -1734,7 +1723,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Bom dia,"
stringToMatch = "Bom dia, Admin!"
)
}
}
Expand Down

0 comments on commit 7d0a594

Please sign in to comment.