Skip to content

Commit

Permalink
Fix part of #5344: Add coming soon topic list UI & fix recommendation…
Browse files Browse the repository at this point in the history
… logic tests (#5460)

<!-- 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.
  -->

Fixes part of #5344

This PR adds the coming soon topic list UI and fixes previously ignored
promoted stories UI tests by correcting the test setup.

## Screenshots
### Phone
|Portrait|Landscape|
|--|--|

|![image](https://github.com/oppia/oppia-android/assets/84731134/554eeab5-2d9e-40a5-ab01-51c8a0a69661)|![image](https://github.com/oppia/oppia-android/assets/84731134/51a2c638-065e-4d75-92c4-046f8d0609d7)|

### Tablet
|Portrait|Landscape|
|--|--|

|![image](https://github.com/oppia/oppia-android/assets/84731134/1ddd19d6-df04-44dd-8073-f9b77554b2d7)|![image](https://github.com/oppia/oppia-android/assets/84731134/dd680415-c9a5-4996-ae9f-55167cc0f0df)|

## 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:
- Add screenshots for portrait/landscape for both a tablet & phone of
the before & after UI changes
- For the screenshots above, include both English and pseudo-localized
(RTL) screenshots (see [RTL
guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines))
- Add a video showing the full UX flow with a screen reader enabled (see
[accessibility
guide](https://github.com/oppia/oppia-android/wiki/Accessibility-A11y-Guide))
- For PRs introducing new UI elements or color changes, both light and
dark mode screenshots must be included
- Add a screenshot demonstrating that you ran affected Espresso tests
locally & that they're passing

---------

Co-authored-by: Adhiambo Peres <[email protected]>
  • Loading branch information
theMr17 and adhiamboperes authored Jul 24, 2024
1 parent 4b49cd8 commit d2db9df
Show file tree
Hide file tree
Showing 9 changed files with 343 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import org.oppia.android.R
import org.oppia.android.app.classroom.classroomlist.ClassroomList
import org.oppia.android.app.classroom.promotedlist.ComingSoonTopicList
import org.oppia.android.app.classroom.promotedlist.PromotedStoryList
import org.oppia.android.app.classroom.topiclist.AllTopicsHeaderText
import org.oppia.android.app.classroom.topiclist.TopicCard
Expand All @@ -38,6 +39,7 @@ import org.oppia.android.app.home.HomeItemViewModel
import org.oppia.android.app.home.RouteToTopicPlayStoryListener
import org.oppia.android.app.home.WelcomeViewModel
import org.oppia.android.app.home.classroomlist.ClassroomSummaryViewModel
import org.oppia.android.app.home.promotedlist.ComingSoonTopicListViewModel
import org.oppia.android.app.home.promotedlist.PromotedStoryListViewModel
import org.oppia.android.app.home.topiclist.AllTopicsViewModel
import org.oppia.android.app.home.topiclist.TopicSummaryViewModel
Expand Down Expand Up @@ -213,6 +215,14 @@ class ClassroomListFragmentPresenter @Inject constructor(
)
}
}
ComingSoonTopicListViewModel::class -> items.forEach { item ->
item {
ComingSoonTopicList(
comingSoonTopicListViewModel = item as ComingSoonTopicListViewModel,
machineLocale = machineLocale,
)
}
}
ClassroomSummaryViewModel::class -> stickyHeader {
ClassroomList(
classroomSummaryList = items.map { it as ClassroomSummaryViewModel },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package org.oppia.android.app.classroom.promotedlist

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.oppia.android.R
import org.oppia.android.app.classroom.getDrawableResource
import org.oppia.android.app.home.promotedlist.ComingSoonTopicListViewModel
import org.oppia.android.app.home.promotedlist.ComingSoonTopicsViewModel
import org.oppia.android.util.locale.OppiaLocale

/** Test tag for the header of the promoted story list. */
const val COMING_SOON_TOPIC_LIST_HEADER_TEST_TAG = "TEST_TAG.coming_soon_topic_list_header"

/** Test tag for the promoted story list. */
const val COMING_SOON_TOPIC_LIST_TEST_TAG = "TEST_TAG.coming_soon_topic_list"

/** Displays a list of topics to be published soon. */
@Composable
fun ComingSoonTopicList(
comingSoonTopicListViewModel: ComingSoonTopicListViewModel,
machineLocale: OppiaLocale.MachineLocale,
) {
Text(
text = stringResource(id = R.string.coming_soon),
color = colorResource(id = R.color.component_color_shared_primary_text_color),
fontFamily = FontFamily.SansSerif,
fontWeight = FontWeight.Medium,
fontSize = dimensionResource(id = R.dimen.coming_soon_topic_list_header_text_size).value.sp,
modifier = Modifier
.padding(
start = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_start),
top = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_top),
end = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_end),
)
.testTag(COMING_SOON_TOPIC_LIST_HEADER_TEST_TAG),
)
LazyRow(
modifier = Modifier
.padding(
top = dimensionResource(id = R.dimen.coming_soon_topic_list_padding)
)
.testTag(COMING_SOON_TOPIC_LIST_TEST_TAG),
contentPadding = PaddingValues(
start = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_start),
end = dimensionResource(id = R.dimen.home_padding_end),
),
) {
items(comingSoonTopicListViewModel.comingSoonTopicList) {
ComingSoonTopicCard(
comingSoonTopicsViewModel = it,
machineLocale = machineLocale,
)
}
}
}

/** Displays a card with the coming soon topic summary information. */
@Composable
fun ComingSoonTopicCard(
comingSoonTopicsViewModel: ComingSoonTopicsViewModel,
machineLocale: OppiaLocale.MachineLocale,
) {
Card(
modifier = Modifier
.width(dimensionResource(id = R.dimen.coming_soon_topic_card_width))
.padding(
start = dimensionResource(id = R.dimen.coming_soon_topic_card_layout_margin_start),
end = dimensionResource(id = R.dimen.coming_soon_topic_card_layout_margin_end),
bottom = dimensionResource(id = R.dimen.coming_soon_topic_card_layout_margin_bottom),
),
elevation = dimensionResource(id = R.dimen.topic_card_elevation),
) {
Box(
contentAlignment = Alignment.TopEnd
) {
Column(
verticalArrangement = Arrangement.Center,
) {
Image(
painter = painterResource(
id = comingSoonTopicsViewModel.topicSummary.lessonThumbnail.getDrawableResource()
),
contentDescription = "Picture of a " +
"${comingSoonTopicsViewModel.topicSummary.lessonThumbnail.thumbnailGraphic.name}.",
modifier = Modifier
.aspectRatio(4f / 3f)
.background(
Color(
(
0xff000000L or
comingSoonTopicsViewModel
.topicSummary.lessonThumbnail.backgroundColorRgb.toLong()
).toInt()
)
)
)
ComingSoonTopicCardTextSection(comingSoonTopicsViewModel)
}
Text(
text = machineLocale
.run { stringResource(id = R.string.coming_soon).toMachineUpperCase() },
modifier = Modifier
.background(
color = colorResource(
id = R.color.component_color_coming_soon_rect_background_start_color
),
shape = RoundedCornerShape(topEnd = 4.dp, bottomStart = 12.dp),
)
.padding(
horizontal = dimensionResource(id = R.dimen.coming_soon_text_padding_horizontal),
vertical = dimensionResource(id = R.dimen.coming_soon_text_padding_vertical),
),
fontSize = 12.sp,
color = colorResource(id = R.color.component_color_shared_secondary_4_text_color),
fontFamily = FontFamily.SansSerif,
textAlign = TextAlign.End,
)
}
}
}

/** Displays the topic title. */
@Composable
fun ComingSoonTopicCardTextSection(comingSoonTopicsViewModel: ComingSoonTopicsViewModel) {
Column(
modifier = Modifier
.fillMaxWidth()
.background(
color = colorResource(
id = R.color.component_color_shared_topic_card_item_background_color
)
),
verticalArrangement = Arrangement.SpaceBetween,
) {
Text(
text = comingSoonTopicsViewModel.topicTitle,
modifier = Modifier
.fillMaxWidth()
.padding(
start = dimensionResource(id = R.dimen.coming_soon_topic_card_text_padding),
top = dimensionResource(id = R.dimen.coming_soon_topic_card_text_padding),
end = dimensionResource(id = R.dimen.coming_soon_topic_card_text_padding),
bottom = dimensionResource(id = R.dimen.coming_soon_topic_card_text_padding_bottom),
),
color = colorResource(id = R.color.component_color_shared_secondary_4_text_color),
fontFamily = FontFamily.SansSerif,
fontSize = dimensionResource(id = R.dimen.topic_list_item_text_size).value.sp,
textAlign = TextAlign.Start,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/values-land/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@
<dimen name="coming_soon_topic_promoted_list_view_margin_top">16dp</dimen>
<dimen name="coming_soon_topic_promoted_list_view_padding_start">0dp</dimen>
<dimen name="coming_soon_topic_Promoted_list_view_padding_end">0dp</dimen>
<dimen name="coming_soon_topic_list_layout_margin_start">72dp</dimen>
<dimen name="coming_soon_topic_list_layout_margin_end">72dp</dimen>
<dimen name="coming_soon_topic_card_layout_margin_start">8dp</dimen>
<dimen name="coming_soon_topic_card_layout_margin_end">8dp</dimen>

<!-- Completed Story Item -->
<dimen name="completed_story_item_topic_container_margin_start">16dp</dimen>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-sw600dp-land/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@
<dimen name="coming_soon_topic_promoted_list_view_margin_top">20dp</dimen>
<dimen name="coming_soon_topic_promoted_list_view_padding_start">0dp</dimen>
<dimen name="coming_soon_topic_Promoted_list_view_padding_end">0dp</dimen>
<dimen name="coming_soon_topic_list_layout_margin_start">72dp</dimen>
<dimen name="coming_soon_topic_list_layout_margin_end">72dp</dimen>
<dimen name="coming_soon_topic_card_layout_margin_start">0dp</dimen>
<dimen name="coming_soon_topic_card_layout_margin_end">32dp</dimen>

<!-- Topic Practice Footer View -->
<dimen name="topic_practice_footer_view_margin_top">24dp</dimen>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-sw600dp-port/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@
<dimen name="coming_soon_topic_promoted_list_view_margin_top">12dp</dimen>
<dimen name="coming_soon_topic_promoted_list_view_padding_start">0dp</dimen>
<dimen name="coming_soon_topic_Promoted_list_view_padding_end">0dp</dimen>
<dimen name="coming_soon_topic_list_layout_margin_start">60dp</dimen>
<dimen name="coming_soon_topic_list_layout_margin_end">60dp</dimen>
<dimen name="coming_soon_topic_card_layout_margin_start">8dp</dimen>
<dimen name="coming_soon_topic_card_layout_margin_end">24dp</dimen>

<!-- Topic Practice Footer View -->
<dimen name="topic_practice_footer_view_margin_top">24dp</dimen>
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,19 @@
<dimen name="coming_soon_topic_promoted_list_view_margin_top">4dp</dimen>
<dimen name="coming_soon_topic_promoted_list_view_padding_start">28dp</dimen>
<dimen name="coming_soon_topic_Promoted_list_view_padding_end">28dp</dimen>
<dimen name="coming_soon_topic_list_header_text_size">18sp</dimen>
<dimen name="coming_soon_topic_list_layout_margin_start">28dp</dimen>
<dimen name="coming_soon_topic_list_layout_margin_top">24dp</dimen>
<dimen name="coming_soon_topic_list_layout_margin_end">28dp</dimen>
<dimen name="coming_soon_topic_list_padding">12dp</dimen>
<dimen name="coming_soon_topic_card_layout_margin_start">8dp</dimen>
<dimen name="coming_soon_topic_card_layout_margin_end">8dp</dimen>
<dimen name="coming_soon_topic_card_layout_margin_bottom">8dp</dimen>
<dimen name="coming_soon_topic_card_width">160dp</dimen>
<dimen name="coming_soon_topic_card_text_padding">8dp</dimen>
<dimen name="coming_soon_topic_card_text_padding_bottom">30dp</dimen>
<dimen name="coming_soon_text_padding_horizontal">6dp</dimen>
<dimen name="coming_soon_text_padding_vertical">12dp</dimen>

<!-- Topic Practice -->
<dimen name="topic_practice_footer_view_margin_top">36dp</dimen>
Expand Down
Loading

0 comments on commit d2db9df

Please sign in to comment.