Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5631: Fix thumbnail loading for multiple classrooms #5642

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.locale.OppiaLocale
import org.oppia.android.util.parser.html.ClassroomHtmlParserEntityType
import org.oppia.android.util.parser.html.StoryHtmlParserEntityType
import org.oppia.android.util.parser.html.TopicHtmlParserEntityType
import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2
Expand All @@ -84,6 +85,7 @@ class ClassroomListFragmentPresenter @Inject constructor(
private val topicListController: TopicListController,
private val classroomController: ClassroomController,
private val oppiaLogger: OppiaLogger,
@ClassroomHtmlParserEntityType private val classroomEntityType: String,
@TopicHtmlParserEntityType private val topicEntityType: String,
@StoryHtmlParserEntityType private val storyEntityType: String,
private val resourceHandler: AppLanguageResourceHandler,
Expand Down Expand Up @@ -120,6 +122,7 @@ class ClassroomListFragmentPresenter @Inject constructor(
profileManagementController,
topicListController,
classroomController,
classroomEntityType,
topicEntityType,
storyEntityType,
resourceHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProvider
import org.oppia.android.util.data.DataProviders.Companion.combineWith
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.parser.html.ClassroomHtmlParserEntityType
import org.oppia.android.util.parser.html.StoryHtmlParserEntityType
import org.oppia.android.util.parser.html.TopicHtmlParserEntityType

Expand All @@ -57,6 +58,7 @@ class ClassroomListViewModel(
private val profileManagementController: ProfileManagementController,
private val topicListController: TopicListController,
private val classroomController: ClassroomController,
@ClassroomHtmlParserEntityType private val classroomEntityType: String,
@TopicHtmlParserEntityType private val topicEntityType: String,
@StoryHtmlParserEntityType private val storyEntityType: String,
private val resourceHandler: AppLanguageResourceHandler,
Expand Down Expand Up @@ -270,6 +272,7 @@ class ClassroomListViewModel(
ClassroomSummaryViewModel(
fragment as ClassroomSummaryClickListener,
ephemeralClassroomSummary,
classroomEntityType,
translationController
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.oppia.android.app.classroom

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
import org.oppia.android.app.customview.LessonThumbnailImageView
import org.oppia.android.app.model.LessonThumbnail

/**
* A composable function that displays a lesson thumbnail image using a custom Android view.
*
* This function integrates the [LessonThumbnailImageView] within a Compose layout, allowing it
* to render a lesson thumbnail image based on the provided parameters. The implementation
* currently relies on a traditional Android View approach due to compatibility issues with the
* Glide Compose library.
*
* @param entityId The unique identifier for the entity associated with the thumbnail.
* @param entityType The type of the entity (e.g., classroom, topic, story).
* @param lessonThumbnail The [LessonThumbnail] containing metadata required to load the image.
* @param modifier The [Modifier] to be applied to the layout, defaulting to [Modifier].
*/
@Composable
fun ThumbnailImage(
entityId: String,
entityType: String,
lessonThumbnail: LessonThumbnail?,
modifier: Modifier = Modifier,
) {
// TODO(#5422): Migrate to Jetpack Compose once the Glide Compose library becomes compatible.
AndroidView(
modifier = modifier.fillMaxSize(),
factory = { context ->
LessonThumbnailImageView(context).apply {
setLessonThumbnail(lessonThumbnail)
setEntityId(entityId)
setEntityType(entityType)
}
},
update = { view ->
view.setLessonThumbnail(lessonThumbnail)
view.setEntityId(entityId)
view.setEntityType(entityType)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.oppia.android.app.classroom.classroomlist

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -23,14 +22,13 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.integerResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
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.classroom.ThumbnailImage
import org.oppia.android.app.home.classroomlist.ClassroomSummaryViewModel

/** Test tag for the classroom list. */
Expand Down Expand Up @@ -103,14 +101,10 @@ fun ClassroomCard(
horizontalAlignment = Alignment.CenterHorizontally,
) {
AnimatedVisibility(visible = !isSticky) {
Image(
painter = painterResource(
id = classroomSummaryViewModel
.classroomSummary
.classroomThumbnail
.getDrawableResource()
),
contentDescription = classroomSummaryViewModel.title,
ThumbnailImage(
entityId = classroomSummaryViewModel.classroomSummary.classroomId,
entityType = classroomSummaryViewModel.entityType,
lessonThumbnail = classroomSummaryViewModel.classroomSummary.classroomThumbnail,
modifier = Modifier
.testTag("${CLASSROOM_CARD_ICON_TEST_TAG}_${classroomSummaryViewModel.title}")
.padding(bottom = dimensionResource(id = R.dimen.classrooms_card_icon_padding_bottom))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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
Expand All @@ -18,11 +17,9 @@ 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
Expand All @@ -31,7 +28,7 @@ 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.classroom.ThumbnailImage
import org.oppia.android.app.home.promotedlist.ComingSoonTopicListViewModel
import org.oppia.android.app.home.promotedlist.ComingSoonTopicsViewModel
import org.oppia.android.util.locale.OppiaLocale
Expand Down Expand Up @@ -104,23 +101,11 @@ fun ComingSoonTopicCard(
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()
)
)
ThumbnailImage(
entityId = comingSoonTopicsViewModel.topicSummary.topicId,
entityType = comingSoonTopicsViewModel.entityType,
lessonThumbnail = comingSoonTopicsViewModel.topicSummary.lessonThumbnail,
modifier = Modifier.aspectRatio(4f / 3f)
)
ComingSoonTopicCardTextSection(comingSoonTopicsViewModel)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package org.oppia.android.app.classroom.promotedlist

import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -23,11 +21,9 @@ 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
Expand All @@ -36,7 +32,7 @@ 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.classroom.ThumbnailImage
import org.oppia.android.app.home.promotedlist.PromotedStoryListViewModel
import org.oppia.android.app.home.promotedlist.PromotedStoryViewModel
import org.oppia.android.util.locale.OppiaLocale
Expand Down Expand Up @@ -141,21 +137,11 @@ fun PromotedStoryCard(
Column(
modifier = cardColumnModifier
) {
Image(
painter = painterResource(
id = promotedStoryViewModel.promotedStory.lessonThumbnail.getDrawableResource()
),
contentDescription = promotedStoryViewModel.storyTitle,
modifier = Modifier
.aspectRatio(16f / 9f)
.background(
Color(
(
0xff000000L or
promotedStoryViewModel.promotedStory.lessonThumbnail.backgroundColorRgb.toLong()
).toInt()
)
)
ThumbnailImage(
entityId = promotedStoryViewModel.promotedStory.storyId,
entityType = promotedStoryViewModel.entityType,
lessonThumbnail = promotedStoryViewModel.promotedStory.lessonThumbnail,
modifier = Modifier.aspectRatio(16f / 9f)
)
Text(
text = promotedStoryViewModel.nextChapterTitle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.oppia.android.app.classroom.topiclist

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -12,18 +11,16 @@ import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
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.sp
import org.oppia.android.R
import org.oppia.android.app.classroom.getDrawableResource
import org.oppia.android.app.classroom.ThumbnailImage
import org.oppia.android.app.home.topiclist.TopicSummaryViewModel

/** Displays a card with the topic summary information. */
Expand All @@ -41,22 +38,11 @@ fun TopicCard(topicSummaryViewModel: TopicSummaryViewModel) {
Column(
verticalArrangement = Arrangement.Center,
) {
Image(
painter = painterResource(
id = topicSummaryViewModel.topicSummary.topicThumbnail.getDrawableResource()
),
contentDescription = "Picture of a " +
"${topicSummaryViewModel.topicSummary.topicThumbnail.thumbnailGraphic.name}.",
modifier = Modifier
.aspectRatio(4f / 3f)
.background(
Color(
(
0xff000000L or
topicSummaryViewModel.topicSummary.topicThumbnail.backgroundColorRgb.toLong()
).toInt()
)
)
ThumbnailImage(
entityId = topicSummaryViewModel.topicSummary.topicId,
entityType = topicSummaryViewModel.entityType,
lessonThumbnail = topicSummaryViewModel.topicSummary.topicThumbnail,
modifier = Modifier.aspectRatio(4f / 3f)
)
TopicCardTextSection(topicSummaryViewModel)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ class LessonThumbnailImageView @JvmOverloads constructor(
R.drawable.topic_fractions_03
LessonThumbnailGraphic.MIXED_NUMBERS ->
R.drawable.topic_fractions_04
LessonThumbnailGraphic.SCIENCE_CLASSROOM ->
R.drawable.ic_science
LessonThumbnailGraphic.MATHS_CLASSROOM ->
R.drawable.ic_maths
LessonThumbnailGraphic.ENGLISH_CLASSROOM ->
R.drawable.ic_english
else ->
R.drawable.topic_fractions_01
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.util.Objects
class ClassroomSummaryViewModel(
private val classroomSummaryClickListener: ClassroomSummaryClickListener,
ephemeralClassroomSummary: EphemeralClassroomSummary,
val entityType: String,
translationController: TranslationController,
) : HomeItemViewModel() {
/** The [ClassroomSummary] retrieved from the [EphemeralClassroomSummary]. */
Expand Down
4 changes: 4 additions & 0 deletions scripts/assets/test_file_exemptions.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ test_file_exemption {
exempted_file_path: "app/src/main/java/org/oppia/android/app/classroom/promotedlist/PromotedStoryList.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "app/src/main/java/org/oppia/android/app/classroom/ThumbnailImage.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "app/src/main/java/org/oppia/android/app/classroom/topiclist/AllTopicsHeaderText.kt"
test_file_not_required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ annotation class ExplorationHtmlParserEntityType
@Qualifier
annotation class ConceptCardHtmlParserEntityType

/** Qualifier for injecting the entity type for classroom card. */
@Qualifier
annotation class ClassroomHtmlParserEntityType

/** Qualifier for injecting the entity type for review card. */
@Qualifier
annotation class TopicHtmlParserEntityType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class HtmlParserEntityTypeModule {
return "skill"
}

@Provides
@ClassroomHtmlParserEntityType
fun provideClassroomCardHtmlParserEntityType(): String {
return "classroom"
}

@Provides
@TopicHtmlParserEntityType
fun provideReviewCardHtmlParserEntityType(): String {
Expand Down
Loading