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 part of #5344: Refactor Classroom List Screen UI #5462

Merged
merged 25 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
936809d
Add collapsible functionality to classroom cards
theMr17 Jul 13, 2024
1b7ed1c
Rename shadowed variable
theMr17 Jul 13, 2024
7e5b1c2
Refactor card collapse logic
theMr17 Jul 13, 2024
f011cc8
Update dark mode colors
theMr17 Jul 13, 2024
235c551
Fix ktlint check
theMr17 Jul 13, 2024
8169c13
Separate classroom header from ClassroomList
theMr17 Jul 14, 2024
72256a3
Fix static checks
theMr17 Jul 14, 2024
871ff72
Add test to verify the card collapse behavior
theMr17 Jul 14, 2024
acf97c5
Merge branch 'develop' into multiple-classrooms-refactor-ui
theMr17 Jul 17, 2024
df600aa
Calculate ClassroomList index dynamically
theMr17 Jul 17, 2024
1ccadd3
Align all topics heading vertically
theMr17 Jul 21, 2024
a168b57
Dynamically compute classroom card width
theMr17 Jul 24, 2024
083ec70
Fix script checks
theMr17 Jul 24, 2024
33f61a4
Update header font style
theMr17 Jul 24, 2024
efdd85e
Merge branch 'develop' into multiple-classrooms-refactor-ui
theMr17 Jul 24, 2024
066dfe5
Update kdoc
theMr17 Jul 26, 2024
043628b
Update classroomListIndex for coming soon topics carousel
theMr17 Jul 26, 2024
f333672
Calculate the classroomListIndex dynamically
theMr17 Jul 31, 2024
f4edd47
Fix kdoc
theMr17 Jul 31, 2024
41cbb0b
Merge branch 'develop' into multiple-classrooms-refactor-ui
theMr17 Jul 31, 2024
3aaecc1
Update dark mode classroom card colours
theMr17 Aug 2, 2024
b247622
Merge branch 'develop' into multiple-classrooms-refactor-ui
theMr17 Aug 2, 2024
c7860ad
Merge branch 'develop' into multiple-classrooms-refactor-ui
theMr17 Aug 7, 2024
740ad7e
Update colors
theMr17 Aug 8, 2024
ed32003
Fix ktlint check
theMr17 Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand All @@ -29,6 +30,7 @@ import androidx.databinding.ObservableList
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import org.oppia.android.R
import org.oppia.android.app.classroom.classroomlist.AllClassroomsHeaderText
import org.oppia.android.app.classroom.classroomlist.ClassroomList
import org.oppia.android.app.classroom.promotedlist.ComingSoonTopicList
import org.oppia.android.app.classroom.promotedlist.PromotedStoryList
Expand All @@ -38,6 +40,7 @@ import org.oppia.android.app.classroom.welcome.WelcomeText
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.AllClassroomsViewModel
import org.oppia.android.app.home.classroomlist.ClassroomSummaryViewModel
import org.oppia.android.app.home.promotedlist.ComingSoonTopicListViewModel
import org.oppia.android.app.home.promotedlist.PromotedStoryListViewModel
Expand Down Expand Up @@ -197,8 +200,15 @@ class ClassroomListFragmentPresenter @Inject constructor(
?.plus(classroomListViewModel.topicList)
?.groupBy { it::class }
val topicListSpanCount = integerResource(id = R.integer.home_span_count)
val listState = rememberLazyListState()
val classroomListIndex = groupedItems
?.flatMap { (type, items) -> items.map { type to it } }
?.indexOfFirst { it.first == AllClassroomsViewModel::class }
?: -1

LazyColumn(
modifier = Modifier.testTag(CLASSROOM_LIST_SCREEN_TEST_TAG)
modifier = Modifier.testTag(CLASSROOM_LIST_SCREEN_TEST_TAG),
state = listState
) {
groupedItems?.forEach { (type, items) ->
when (type) {
Expand All @@ -223,10 +233,16 @@ class ClassroomListFragmentPresenter @Inject constructor(
)
}
}
ClassroomSummaryViewModel::class -> stickyHeader {
AllClassroomsViewModel::class -> items.forEach { _ ->
item {
AllClassroomsHeaderText()
}
}
ClassroomSummaryViewModel::class -> stickyHeader() {
ClassroomList(
classroomSummaryList = items.map { it as ClassroomSummaryViewModel },
classroomListViewModel.selectedClassroomId.get() ?: ""
selectedClassroomId = classroomListViewModel.selectedClassroomId.get() ?: "",
isSticky = listState.firstVisibleItemIndex >= classroomListIndex
)
}
AllTopicsViewModel::class -> items.forEach { _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.lifecycle.Transformations
import org.oppia.android.R
import org.oppia.android.app.home.HomeItemViewModel
import org.oppia.android.app.home.WelcomeViewModel
import org.oppia.android.app.home.classroomlist.AllClassroomsViewModel
import org.oppia.android.app.home.classroomlist.ClassroomSummaryClickListener
import org.oppia.android.app.home.classroomlist.ClassroomSummaryViewModel
import org.oppia.android.app.home.promotedlist.ComingSoonTopicListViewModel
Expand Down Expand Up @@ -264,13 +265,14 @@ class ClassroomListViewModel(
private fun computeClassroomItemViewModelList(
classroomList: ClassroomList
): List<HomeItemViewModel> {
return classroomList.classroomSummaryList.map { ephemeralClassroomSummary ->
ClassroomSummaryViewModel(
fragment as ClassroomSummaryClickListener,
ephemeralClassroomSummary,
translationController
)
}
return listOf(AllClassroomsViewModel) +
classroomList.classroomSummaryList.map { ephemeralClassroomSummary ->
ClassroomSummaryViewModel(
fragment as ClassroomSummaryClickListener,
ephemeralClassroomSummary,
translationController
)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.oppia.android.app.classroom.classroomlist

import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import org.oppia.android.R

/** Test tag for the all classrooms section header. */
const val ALL_CLASSROOMS_HEADER_TEST_TAG = "TEST_TAG.all_classrooms_header"

/** Displays the header text for the classroom list section. */
@Composable
fun AllClassroomsHeaderText() {
Text(
text = stringResource(id = R.string.classrooms_list_activity_section_header),
color = colorResource(id = R.color.component_color_classroom_shared_header_text_color),
fontFamily = FontFamily.SansSerif,
fontWeight = FontWeight.Normal,
fontSize = dimensionResource(id = R.dimen.classrooms_list_header_text_size).value.sp,
modifier = Modifier
.testTag(ALL_CLASSROOMS_HEADER_TEST_TAG)
.padding(
start = dimensionResource(id = R.dimen.classrooms_text_margin_start),
top = dimensionResource(id = R.dimen.classrooms_text_margin_top),
end = dimensionResource(id = R.dimen.classrooms_text_margin_end),
),
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.oppia.android.app.classroom.classroomlist

import android.content.res.Configuration
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand All @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
Expand All @@ -24,60 +23,45 @@ import androidx.compose.ui.platform.LocalConfiguration
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.res.stringResource
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.home.classroomlist.ClassroomSummaryViewModel

/** Test tag for the header of the classroom section. */
const val CLASSROOM_HEADER_TEST_TAG = "TEST_TAG.classroom_header"

/** Test tag for the classroom list. */
const val CLASSROOM_LIST_TEST_TAG = "TEST_TAG.classroom_list"

/** Test tag for the classroom card icon. */
const val CLASSROOM_CARD_ICON_TEST_TAG = "TEST_TAG.classroom_card_icon"

/** Displays a list of classroom summaries with a header. */
@Composable
fun ClassroomList(
classroomSummaryList: List<ClassroomSummaryViewModel>,
selectedClassroomId: String
selectedClassroomId: String,
isSticky: Boolean,
) {
Column(
LazyRow(
modifier = Modifier
.testTag(CLASSROOM_LIST_TEST_TAG)
.background(
color = colorResource(id = R.color.component_color_shared_screen_primary_background_color)
)
.fillMaxWidth(),
contentPadding = PaddingValues(
start = dimensionResource(id = R.dimen.classrooms_text_margin_start),
top = dimensionResource(id = R.dimen.classrooms_text_margin_bottom),
end = dimensionResource(id = R.dimen.classrooms_text_margin_end),
),
) {
Text(
text = stringResource(id = R.string.classrooms_list_activity_section_header),
color = colorResource(id = R.color.component_color_shared_primary_text_color),
fontFamily = FontFamily.SansSerif,
fontWeight = FontWeight.Medium,
fontSize = dimensionResource(id = R.dimen.classrooms_list_header_text_size).value.sp,
modifier = Modifier
.testTag(CLASSROOM_HEADER_TEST_TAG)
.padding(
start = dimensionResource(id = R.dimen.classrooms_text_margin_start),
top = dimensionResource(id = R.dimen.classrooms_text_margin_top),
end = dimensionResource(id = R.dimen.classrooms_text_margin_end),
bottom = dimensionResource(id = R.dimen.classrooms_text_margin_bottom),
),
)
LazyRow(
modifier = Modifier.testTag(CLASSROOM_LIST_TEST_TAG),
contentPadding = PaddingValues(
start = dimensionResource(id = R.dimen.classrooms_text_margin_start),
end = dimensionResource(id = R.dimen.classrooms_text_margin_end),
),
) {
items(classroomSummaryList) {
ClassroomCard(classroomSummaryViewModel = it, selectedClassroomId)
}
items(classroomSummaryList) {
ClassroomCard(classroomSummaryViewModel = it, selectedClassroomId, isSticky)
}
}
}
Expand All @@ -86,37 +70,41 @@ fun ClassroomList(
@Composable
fun ClassroomCard(
classroomSummaryViewModel: ClassroomSummaryViewModel,
selectedClassroomId: String
selectedClassroomId: String,
isSticky: Boolean,
) {
val screenWidth = LocalConfiguration.current.screenWidthDp
val isPortrait = LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT
val isTablet = if (isPortrait) screenWidth > 600 else screenWidth > 840
val isCardSelected = classroomSummaryViewModel.classroomSummary.classroomId == selectedClassroomId
Card(
modifier = Modifier
.height(dimensionResource(id = R.dimen.classrooms_card_height))
.width(dimensionResource(id = R.dimen.classrooms_card_width))
.width(getClassroomCardWidth())
.padding(
start = dimensionResource(R.dimen.promoted_story_card_layout_margin_start),
end = dimensionResource(R.dimen.promoted_story_card_layout_margin_end),
start = dimensionResource(R.dimen.classrooms_card_margin_start),
end = dimensionResource(R.dimen.classrooms_card_margin_end),
)
.clickable {
classroomSummaryViewModel.handleClassroomClick()
},
backgroundColor = if (isCardSelected) {
colorResource(id = R.color.component_color_classroom_card_color)
colorResource(id = R.color.component_color_classroom_card_selected_color)
} else {
colorResource(id = R.color.component_color_shared_screen_primary_background_color)
colorResource(id = R.color.component_color_classroom_card_color)
},
border = BorderStroke(2.dp, color = colorResource(id = R.color.color_def_oppia_green)),
elevation = dimensionResource(id = R.dimen.classrooms_card_elevation),
) {
Column(
modifier = Modifier.padding(all = dimensionResource(id = R.dimen.classrooms_card_padding)),
modifier = Modifier.padding(
horizontal = dimensionResource(id = R.dimen.classrooms_card_padding_horizontal),
vertical = if (isSticky) {
dimensionResource(id = R.dimen.classrooms_card_collapsed_padding_vertical)
} else {
dimensionResource(id = R.dimen.classrooms_card_padding_vertical)
},
),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
if (isPortrait || isTablet) { // Hides the classroom icon for landscape phone layouts.
AnimatedVisibility(visible = !isSticky) {
Image(
painter = painterResource(
id = classroomSummaryViewModel
Expand All @@ -126,6 +114,7 @@ fun ClassroomCard(
),
contentDescription = classroomSummaryViewModel.title,
modifier = Modifier
.testTag("${CLASSROOM_CARD_ICON_TEST_TAG}_${classroomSummaryViewModel.title}")
.padding(bottom = dimensionResource(id = R.dimen.classrooms_card_icon_padding_bottom))
.size(size = dimensionResource(id = R.dimen.classrooms_card_icon_size)),
)
Expand All @@ -140,3 +129,17 @@ fun ClassroomCard(
}
}
}

@Composable
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
private fun getClassroomCardWidth(): Dp {
val configuration = LocalConfiguration.current
val screenWidth = configuration.screenWidthDp.dp
val horizontalPadding = dimensionResource(id = R.dimen.classrooms_text_margin_start)
val topicCardHorizontalMargin = 8.dp
val topicListSpanCount = integerResource(id = R.integer.home_span_count)

val totalTopicCardWidth = screenWidth -
(horizontalPadding.times(2) + (topicCardHorizontalMargin * (topicListSpanCount - 1) * 2))

return totalTopicCardWidth.div(topicListSpanCount)
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ fun PromotedStoryList(
) {
Text(
text = promotedStoryListViewModel.getHeader(),
color = colorResource(id = R.color.component_color_shared_primary_text_color),
color = colorResource(id = R.color.component_color_classroom_shared_header_text_color),
fontFamily = FontFamily.SansSerif,
fontWeight = FontWeight.Medium,
fontWeight = FontWeight.Normal,
fontSize = dimensionResource(id = R.dimen.promoted_story_list_header_text_size).value.sp,
modifier = Modifier
.weight(weight = 1f, fill = false),
Expand Down Expand Up @@ -127,7 +127,7 @@ fun PromotedStoryCard(
)
.clickable { promotedStoryViewModel.clickOnStoryTile() },
backgroundColor = colorResource(
id = R.color.component_color_shared_screen_primary_background_color
id = R.color.component_color_classroom_promoted_list_card_background_color
),
elevation = dimensionResource(id = R.dimen.promoted_story_card_elevation),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ fun AllTopicsHeaderText() {
modifier = Modifier
.testTag(ALL_TOPICS_HEADER_TEST_TAG)
.fillMaxWidth()
.background(colorResource(id = R.color.color_palette_classroom_topic_list_background_color))
.background(
colorResource(id = R.color.component_color_classroom_topic_list_background_color)
)
.padding(
start = dimensionResource(id = R.dimen.all_topics_text_margin_start),
top = dimensionResource(id = R.dimen.all_topics_text_margin_top),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.oppia.android.app.home.classroomlist

import androidx.lifecycle.ViewModel
import org.oppia.android.app.classroom.ClassroomListFragment
import org.oppia.android.app.home.HomeItemViewModel

/** [ViewModel] for displaying the classroom header in [ClassroomListFragment]. */
object AllClassroomsViewModel : HomeItemViewModel()
6 changes: 3 additions & 3 deletions app/src/main/res/drawable/ic_maths.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
android:pathData="M4,1.5L64,1.5A2.5,2.5 0,0 1,66.5 4L66.5,64A2.5,2.5 0,0 1,64 66.5L4,66.5A2.5,2.5 0,0 1,1.5 64L1.5,4A2.5,2.5 0,0 1,4 1.5z"
android:strokeWidth="3"
android:fillColor="#00000000"
android:strokeColor="#00645C"/>
android:strokeColor="@color/component_color_classroom_card_icon_stroke_color"/>
<path
android:pathData="M34,1.5V66.5"
android:strokeWidth="3"
android:fillColor="#00000000"
android:strokeColor="#00645C"/>
android:strokeColor="@color/component_color_classroom_card_icon_stroke_color"/>
<path
android:pathData="M66.5,34L1.5,34"
android:strokeWidth="3"
android:fillColor="#00000000"
android:strokeColor="#00645C"/>
android:strokeColor="@color/component_color_classroom_card_icon_stroke_color"/>
<path
android:pathData="M22.9502,13.0502L13.0507,22.9497"
android:strokeWidth="4"
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/res/values-land/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@
<dimen name="classrooms_text_margin_top">20dp</dimen>
<dimen name="classrooms_text_margin_end">72dp</dimen>
<dimen name="classrooms_text_margin_bottom">12dp</dimen>
<dimen name="classrooms_card_width">150dp</dimen>
<dimen name="classrooms_card_height">60dp</dimen>
<dimen name="classrooms_card_padding_vertical">36dp</dimen>
<dimen name="classrooms_card_icon_padding_bottom">28dp</dimen>
<dimen name="classrooms_card_icon_size">80dp</dimen>
<dimen name="classrooms_card_margin_start">8dp</dimen>
<dimen name="classrooms_card_margin_end">0dp</dimen>
</resources>
11 changes: 8 additions & 3 deletions app/src/main/res/values-night/color_palette.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<color name="color_palette_revision_card_toolbar_color">@color/color_def_forest_green</color>
<color name="color_palette_hints_and_solutions_fragment_toolbar_color">@color/color_def_oppia_dark_blue</color>
<color name="color_palette_menu_selected_text_color">@color/color_def_oppia_turquoise</color>
<color name="color_palette_developer_option_menu_selected_color">@color/color_def_persian_blue</color>
<color name="color_palette_developer_option_menu_selected_color">@color/color_def_persian_blue_1</color>
<color name="color_palette_underline_view_color">@color/color_def_bright_green</color>
<color name="color_palette_menu_text_color">@color/color_def_white</color>
<color name="color_palette_secondary_container_background_color">@color/color_def_oppia_metallic_blue</color>
Expand Down Expand Up @@ -242,7 +242,12 @@
<color name="color_palette_text_error_color">@color/color_def_oppia_reddish_brown</color>
<color name="color_palette_edittext_stroke_color">@color/color_def_accessible_light_grey_2</color>
<!-- CLASSROOM -->
<color name="color_palette_classroom_card_color">@color/color_def_greenish_black</color>
<color name="color_palette_classroom_shared_header_text_color">@color/color_def_white_1</color>
<color name="color_palette_classroom_card_color">@color/color_def_greenish_black_1</color>
<color name="color_palette_classroom_card_selected_color">@color/color_def_greenish_black_2</color>
<color name="color_palette_classroom_card_icon_stroke_color">@color/color_def_pale_green_1</color>
<color name="color_palette_classroom_shared_text_color">@color/color_def_white</color>
<color name="color_palette_classroom_topic_list_background_color">@color/color_def_greenish_black</color>
<color name="color_palette_classroom_topic_list_background_color">@color/color_def_greenish_black_3</color>
<color name="color_palette_classroom_promoted_list_classroom_label_color">@color/color_def_persian_blue_2</color>
<color name="color_palette_classroom_promoted_list_card_background_color">@color/color_def_greenish_black_2</color>
</resources>
Loading
Loading