|
| 1 | +package org.oppia.android.app.classroom.promotedlist |
| 2 | + |
| 3 | +import androidx.compose.foundation.Image |
| 4 | +import androidx.compose.foundation.background |
| 5 | +import androidx.compose.foundation.layout.Arrangement |
| 6 | +import androidx.compose.foundation.layout.Box |
| 7 | +import androidx.compose.foundation.layout.Column |
| 8 | +import androidx.compose.foundation.layout.PaddingValues |
| 9 | +import androidx.compose.foundation.layout.aspectRatio |
| 10 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 11 | +import androidx.compose.foundation.layout.padding |
| 12 | +import androidx.compose.foundation.layout.width |
| 13 | +import androidx.compose.foundation.lazy.LazyRow |
| 14 | +import androidx.compose.foundation.lazy.items |
| 15 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 16 | +import androidx.compose.material.Card |
| 17 | +import androidx.compose.material.Text |
| 18 | +import androidx.compose.runtime.Composable |
| 19 | +import androidx.compose.ui.Alignment |
| 20 | +import androidx.compose.ui.Modifier |
| 21 | +import androidx.compose.ui.graphics.Color |
| 22 | +import androidx.compose.ui.platform.testTag |
| 23 | +import androidx.compose.ui.res.colorResource |
| 24 | +import androidx.compose.ui.res.dimensionResource |
| 25 | +import androidx.compose.ui.res.painterResource |
| 26 | +import androidx.compose.ui.res.stringResource |
| 27 | +import androidx.compose.ui.text.font.FontFamily |
| 28 | +import androidx.compose.ui.text.font.FontWeight |
| 29 | +import androidx.compose.ui.text.style.TextAlign |
| 30 | +import androidx.compose.ui.text.style.TextOverflow |
| 31 | +import androidx.compose.ui.unit.dp |
| 32 | +import androidx.compose.ui.unit.sp |
| 33 | +import org.oppia.android.R |
| 34 | +import org.oppia.android.app.classroom.getDrawableResource |
| 35 | +import org.oppia.android.app.home.promotedlist.ComingSoonTopicListViewModel |
| 36 | +import org.oppia.android.app.home.promotedlist.ComingSoonTopicsViewModel |
| 37 | +import org.oppia.android.util.locale.OppiaLocale |
| 38 | + |
| 39 | +/** Test tag for the header of the promoted story list. */ |
| 40 | +const val COMING_SOON_TOPIC_LIST_HEADER_TEST_TAG = "TEST_TAG.coming_soon_topic_list_header" |
| 41 | + |
| 42 | +/** Test tag for the promoted story list. */ |
| 43 | +const val COMING_SOON_TOPIC_LIST_TEST_TAG = "TEST_TAG.coming_soon_topic_list" |
| 44 | + |
| 45 | +/** Displays a list of topics to be published soon. */ |
| 46 | +@Composable |
| 47 | +fun ComingSoonTopicList( |
| 48 | + comingSoonTopicListViewModel: ComingSoonTopicListViewModel, |
| 49 | + machineLocale: OppiaLocale.MachineLocale, |
| 50 | +) { |
| 51 | + Text( |
| 52 | + text = stringResource(id = R.string.coming_soon), |
| 53 | + color = colorResource(id = R.color.component_color_shared_primary_text_color), |
| 54 | + fontFamily = FontFamily.SansSerif, |
| 55 | + fontWeight = FontWeight.Medium, |
| 56 | + fontSize = dimensionResource(id = R.dimen.coming_soon_topic_list_header_text_size).value.sp, |
| 57 | + modifier = Modifier |
| 58 | + .padding( |
| 59 | + start = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_start), |
| 60 | + top = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_top), |
| 61 | + end = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_end), |
| 62 | + ) |
| 63 | + .testTag(COMING_SOON_TOPIC_LIST_HEADER_TEST_TAG), |
| 64 | + ) |
| 65 | + LazyRow( |
| 66 | + modifier = Modifier |
| 67 | + .padding( |
| 68 | + top = dimensionResource(id = R.dimen.coming_soon_topic_list_padding) |
| 69 | + ) |
| 70 | + .testTag(COMING_SOON_TOPIC_LIST_TEST_TAG), |
| 71 | + contentPadding = PaddingValues( |
| 72 | + start = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_start), |
| 73 | + end = dimensionResource(id = R.dimen.home_padding_end), |
| 74 | + ), |
| 75 | + ) { |
| 76 | + items(comingSoonTopicListViewModel.comingSoonTopicList) { |
| 77 | + ComingSoonTopicCard( |
| 78 | + comingSoonTopicsViewModel = it, |
| 79 | + machineLocale = machineLocale, |
| 80 | + ) |
| 81 | + } |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +/** Displays a card with the coming soon topic summary information. */ |
| 86 | +@Composable |
| 87 | +fun ComingSoonTopicCard( |
| 88 | + comingSoonTopicsViewModel: ComingSoonTopicsViewModel, |
| 89 | + machineLocale: OppiaLocale.MachineLocale, |
| 90 | +) { |
| 91 | + Card( |
| 92 | + modifier = Modifier |
| 93 | + .width(dimensionResource(id = R.dimen.coming_soon_topic_card_width)) |
| 94 | + .padding( |
| 95 | + start = dimensionResource(id = R.dimen.coming_soon_topic_card_layout_margin_start), |
| 96 | + end = dimensionResource(id = R.dimen.coming_soon_topic_card_layout_margin_end), |
| 97 | + bottom = dimensionResource(id = R.dimen.coming_soon_topic_card_layout_margin_bottom), |
| 98 | + ), |
| 99 | + elevation = dimensionResource(id = R.dimen.topic_card_elevation), |
| 100 | + ) { |
| 101 | + Box( |
| 102 | + contentAlignment = Alignment.TopEnd |
| 103 | + ) { |
| 104 | + Column( |
| 105 | + verticalArrangement = Arrangement.Center, |
| 106 | + ) { |
| 107 | + Image( |
| 108 | + painter = painterResource( |
| 109 | + id = comingSoonTopicsViewModel.topicSummary.lessonThumbnail.getDrawableResource() |
| 110 | + ), |
| 111 | + contentDescription = "Picture of a " + |
| 112 | + "${comingSoonTopicsViewModel.topicSummary.lessonThumbnail.thumbnailGraphic.name}.", |
| 113 | + modifier = Modifier |
| 114 | + .aspectRatio(4f / 3f) |
| 115 | + .background( |
| 116 | + Color( |
| 117 | + ( |
| 118 | + 0xff000000L or |
| 119 | + comingSoonTopicsViewModel |
| 120 | + .topicSummary.lessonThumbnail.backgroundColorRgb.toLong() |
| 121 | + ).toInt() |
| 122 | + ) |
| 123 | + ) |
| 124 | + ) |
| 125 | + ComingSoonTopicCardTextSection(comingSoonTopicsViewModel) |
| 126 | + } |
| 127 | + Text( |
| 128 | + text = machineLocale |
| 129 | + .run { stringResource(id = R.string.coming_soon).toMachineUpperCase() }, |
| 130 | + modifier = Modifier |
| 131 | + .background( |
| 132 | + color = colorResource( |
| 133 | + id = R.color.component_color_coming_soon_rect_background_start_color |
| 134 | + ), |
| 135 | + shape = RoundedCornerShape(topEnd = 4.dp, bottomStart = 12.dp), |
| 136 | + ) |
| 137 | + .padding( |
| 138 | + horizontal = dimensionResource(id = R.dimen.coming_soon_text_padding_horizontal), |
| 139 | + vertical = dimensionResource(id = R.dimen.coming_soon_text_padding_vertical), |
| 140 | + ), |
| 141 | + fontSize = 12.sp, |
| 142 | + color = colorResource(id = R.color.component_color_shared_secondary_4_text_color), |
| 143 | + fontFamily = FontFamily.SansSerif, |
| 144 | + textAlign = TextAlign.End, |
| 145 | + ) |
| 146 | + } |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +/** Displays the topic title. */ |
| 151 | +@Composable |
| 152 | +fun ComingSoonTopicCardTextSection(comingSoonTopicsViewModel: ComingSoonTopicsViewModel) { |
| 153 | + Column( |
| 154 | + modifier = Modifier |
| 155 | + .fillMaxWidth() |
| 156 | + .background( |
| 157 | + color = colorResource( |
| 158 | + id = R.color.component_color_shared_topic_card_item_background_color |
| 159 | + ) |
| 160 | + ), |
| 161 | + verticalArrangement = Arrangement.SpaceBetween, |
| 162 | + ) { |
| 163 | + Text( |
| 164 | + text = comingSoonTopicsViewModel.topicTitle, |
| 165 | + modifier = Modifier |
| 166 | + .fillMaxWidth() |
| 167 | + .padding( |
| 168 | + start = dimensionResource(id = R.dimen.coming_soon_topic_card_text_padding), |
| 169 | + top = dimensionResource(id = R.dimen.coming_soon_topic_card_text_padding), |
| 170 | + end = dimensionResource(id = R.dimen.coming_soon_topic_card_text_padding), |
| 171 | + bottom = dimensionResource(id = R.dimen.coming_soon_topic_card_text_padding_bottom), |
| 172 | + ), |
| 173 | + color = colorResource(id = R.color.component_color_shared_secondary_4_text_color), |
| 174 | + fontFamily = FontFamily.SansSerif, |
| 175 | + fontSize = dimensionResource(id = R.dimen.topic_list_item_text_size).value.sp, |
| 176 | + textAlign = TextAlign.Start, |
| 177 | + maxLines = 1, |
| 178 | + overflow = TextOverflow.Ellipsis, |
| 179 | + ) |
| 180 | + } |
| 181 | +} |
0 commit comments