Skip to content

Commit

Permalink
Merge branch 'develop' into combining_'_time_ago_'_and_plurals_in_one
Browse files Browse the repository at this point in the history
  • Loading branch information
adhiamboperes authored Sep 24, 2023
2 parents a947f8f + cfce93c commit 4cbd6fb
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,40 @@ class NavigationDrawerHeaderViewModel @Inject constructor(
val profile = ObservableField(Profile.getDefaultInstance())
private var ongoingTopicCount = DEFAULT_ONGOING_TOPIC_COUNT
private var completedStoryCount = DEFAULT_COMPLETED_STORY_COUNT
val profileProgressText: ObservableField<String> = ObservableField(computeProfileProgressText())
val profileTopicProgressText: ObservableField<String> =
ObservableField(computeProfileTopicProgressText())
val profileStoryProgressText: ObservableField<String> =
ObservableField(computeProfileStoryProgressText())

fun onHeaderClicked() {
routeToProfileProgressListener.routeToProfileProgress(profile.get()!!.id.internalId)
}

fun setOngoingTopicProgress(ongoingTopicCount: Int) {
this.ongoingTopicCount = ongoingTopicCount
profileProgressText.set(computeProfileProgressText())
profileTopicProgressText.set(computeProfileTopicProgressText())
}

fun setCompletedStoryProgress(completedStoryCount: Int) {
this.completedStoryCount = completedStoryCount
profileProgressText.set(computeProfileProgressText())
profileStoryProgressText.set(computeProfileStoryProgressText())
}

private fun computeProfileProgressText(): String {
// TODO(#3843): Either combine these strings into one or use separate views to display them.
val completedStoryCountText =
resourceHandler.getQuantityStringInLocaleWithWrapping(
R.plurals.completed_story_count, completedStoryCount, completedStoryCount.toString()
)
val ongoingTopicCountText =
resourceHandler.getQuantityStringInLocaleWithWrapping(
R.plurals.ongoing_topic_count, ongoingTopicCount, ongoingTopicCount.toString()
)
val barSeparator = resourceHandler.getStringInLocale(R.string.bar_separator)
return "$completedStoryCountText$barSeparator$ongoingTopicCountText"
private fun computeProfileStoryProgressText(): String {
return resourceHandler.getQuantityStringInLocaleWithWrapping(
R.plurals.completed_story_count,
completedStoryCount,
completedStoryCount.toString()
)
}

fun getBarSeparator() = resourceHandler.getStringInLocale(R.string.bar_separator)

private fun computeProfileTopicProgressText(): String {
return resourceHandler.getQuantityStringInLocaleWithWrapping(
R.plurals.ongoing_topic_count,
ongoingTopicCount,
ongoingTopicCount.toString()
)
}
}
51 changes: 41 additions & 10 deletions app/src/main/res/layout/nav_header_navigation_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="64dp"
android:layout_height="64dp"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.RoundedShape"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.RoundedShape"
profile:src="@{viewModel.profile.avatar}" />

<TextView
Expand All @@ -44,16 +44,47 @@
android:textColor="@color/component_color_shared_secondary_4_text_color"
android:textSize="14sp" />

<TextView
android:id="@+id/profile_progress_text_view"
style="@style/TextViewStart"
<LinearLayout
android:id="@+id/progress_linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
android:fontFamily="sans-serif"
android:text="@{viewModel.profileProgressText}"
android:textColor="@color/component_color_shared_secondary_4_text_color"
android:textSize="14sp" />
android:orientation="horizontal">

<TextView
android:id="@+id/profile_story_progress_text_view"
style="@style/TextViewStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
android:fontFamily="sans-serif"
android:text="@{viewModel.profileStoryProgressText}"
android:textColor="@color/component_color_shared_secondary_4_text_color"
android:textSize="14sp" />

<TextView
android:id="@+id/profile_topic_separator"
style="@style/TextViewStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
android:fontFamily="sans-serif"
android:text="@{viewModel.getBarSeparator()}"
android:textColor="@color/component_color_shared_secondary_4_text_color"
android:textSize="14sp" />

<TextView
android:id="@+id/profile_topic_progress_text_view"
style="@style/TextViewStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
android:fontFamily="sans-serif"
android:text="@{viewModel.profileTopicProgressText}"
android:textColor="@color/component_color_shared_secondary_4_text_color"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class NavigationDrawerActivityProdTest {
}

@Test
fun testNavDrawer_openNavDrawer_oneTopicInProgress_profileProgressIsDisplayedCorrectly() {
fun testNavDrawer_openNavDrawer_oneTopicInProgress_profileStoryProgressIsDisplayedCorrectly() {
storyProfileTestHelper.markCompletedRatiosStory1Exp0(
ProfileId.newBuilder().setInternalId(
internalProfileId
Expand All @@ -270,10 +270,32 @@ class NavigationDrawerActivityProdTest {
it.openNavigationDrawer()
onView(
allOf(
withId(R.id.profile_progress_text_view),
isDescendantOfA(withId(R.id.header_linear_layout))
withId(R.id.profile_story_progress_text_view),
isDescendantOfA(withId(R.id.progress_linear_layout))
)
).check(matches(withText("1 Story Completed")))
}
}

@Test
fun testNavDrawer_openNavDrawer_oneTopicInProgress_profileTopicProgressIsDisplayedCorrectly() {
storyProfileTestHelper.markCompletedRatiosStory1Exp0(
ProfileId.newBuilder().setInternalId(
internalProfileId
).build(),
timestampOlderThanOneWeek = false
)
launch<NavigationDrawerTestActivity>(
createNavigationDrawerActivityIntent(internalProfileId)
).use {
testCoroutineDispatchers.runCurrent()
it.openNavigationDrawer()
onView(
allOf(
withId(R.id.profile_topic_progress_text_view),
isDescendantOfA(withId(R.id.progress_linear_layout))
)
).check(matches(withText("1 Story Completed | 1 Topic in Progress")))
).check(matches(withText("1 Topic in Progress")))
}
}

Expand Down

0 comments on commit 4cbd6fb

Please sign in to comment.