From 7d0a594f6254715f36bd1404787cf3195a49b2a0 Mon Sep 17 00:00:00 2001
From: Shubhadeep Karmakar
<99060332+ShubhadeepKarmakar@users.noreply.github.com>
Date: Fri, 6 Oct 2023 22:33:33 +0530
Subject: [PATCH] Fix #3930 Greeting text on home screen should be a single
TextView (#5131)
## Explanation
- 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
- [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
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>
---
.../android/app/home/WelcomeViewModel.kt | 13 +++--
app/src/main/res/layout/welcome.xml | 11 +---
app/src/main/res/values/strings.xml | 2 +-
.../android/app/home/HomeActivityTest.kt | 53 ++++++++-----------
4 files changed, 31 insertions(+), 48 deletions(-)
diff --git a/app/src/main/java/org/oppia/android/app/home/WelcomeViewModel.kt b/app/src/main/java/org/oppia/android/app/home/WelcomeViewModel.kt
index 181f7465bfa..40cf74ec589 100644
--- a/app/src/main/java/org/oppia/android/app/home/WelcomeViewModel.kt
+++ b/app/src/main/java/org/oppia/android/app/home/WelcomeViewModel.kt
@@ -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
diff --git a/app/src/main/res/layout/welcome.xml b/app/src/main/res/layout/welcome.xml
index e4a87b27e94..8fcc751ec56 100644
--- a/app/src/main/res/layout/welcome.xml
+++ b/app/src/main/res/layout/welcome.xml
@@ -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" />
-
-
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0f02760b7ae..081bea57539 100755
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -176,7 +176,7 @@
%s GB
Correct!
Topic: %s
- %s!
+ %s %s!
- 1 Chapter
- %s Chapters
diff --git a/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt
index 55a31dd8066..a0e79d44c34 100644
--- a/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt
+++ b/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt
@@ -246,19 +246,6 @@ class HomeActivityTest {
assertThat(screenName).isEqualTo(ScreenName.HOME_ACTIVITY)
}
- @Test
- fun testHomeActivity_withAdminProfile_profileNameIsDisplayed() {
- launch(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 ->
@@ -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(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(createHomeActivityIntent(internalProfileId1)).use {
+ launch(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(createHomeActivityIntent(internalProfileId1)).use {
+ launch(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(createHomeActivityIntent(internalProfileId1)).use {
+ launch(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
- stringToMatch = "Good evening,"
+ stringToMatch = "Good evening, Admin!"
)
}
}
@@ -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())))
}
@@ -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())))
}
@@ -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())))
}
@@ -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())))
}
@@ -1574,7 +1563,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
- stringToMatch = "Good morning,"
+ stringToMatch = "Good morning, Admin!"
)
}
}
@@ -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).
@@ -1664,7 +1653,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
- stringToMatch = "صباح الخير"
+ stringToMatch = "صباح الخير \u200F\u202AAdmin\u202C\u200F!"
)
}
}
@@ -1734,7 +1723,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
- stringToMatch = "Bom dia,"
+ stringToMatch = "Bom dia, Admin!"
)
}
}