Skip to content

Commit

Permalink
fix oppia#5150, simplify the margins' calculation
Browse files Browse the repository at this point in the history
This is just a proposal, will brush it up if the proposal is approved
  • Loading branch information
nikitaevg committed Sep 22, 2023
1 parent 89e8032 commit 023d5b0
Showing 1 changed file with 2 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,72 +41,12 @@ class TopicSummaryViewModel(
topicSummaryClickListener.onTopicSummaryClicked(topicSummary)
}

/**
* Determines the start margin for an individual TopicSummary relative to the grid columns laid out on the
* HomeActivity. GridLayout columns are evenly spread out across the entire activity screen but the
* Topic Summaries are positioned towards the center, so start margins are calculated to stagger inside each
* fixed column but centered on the activity's layout, as shown below.
*
* | _____| _____ | _____ |_____ |
* | | | | | | | | | | |
* | | | | | | | | | | |
* | |_____| |_____| | |_____| |_____| |
* | | | | |
* | _____ _____ _____ _____ |
* | | | | | | | | | |
* | | | | | | | | | |
* | |_____| |_____| |_____| |_____| |
* | |
*/
fun computeStartMargin(): Int {
return when (spanCount) {
2 -> when (position % spanCount) {
0 -> outerMargin
else -> innerMargin
}
3 -> when (position % spanCount) {
0 -> outerMargin
1 -> innerMargin
2 -> 0
else -> 0
}
4 -> when (position % spanCount) {
0 -> outerMargin
1 -> innerMargin
2 -> innerMargin / 2
3 -> 0
else -> 0
}
else -> 0
}
return outerMargin
}

/**
* Determines the end margin for an individual TopicSummary relative to the grid columns laid out on the
* HomeActivity. The end margins are calculated to stagger inside each fixed column but centered on the
* activity's layout (see [computeStartMargin]).
*/
fun computeEndMargin(): Int {
return when (spanCount) {
2 -> when (position % spanCount) {
0 -> innerMargin
else -> outerMargin
}
3 -> when (position % spanCount) {
0 -> 0
1 -> innerMargin
2 -> outerMargin
else -> 0
}
4 -> when (position % spanCount) {
0 -> 0
1 -> innerMargin / 2
2 -> innerMargin
3 -> outerMargin
else -> 0
}
else -> 0
}
return innerMargin
}

fun computeLessonCountText(): String {
Expand Down

0 comments on commit 023d5b0

Please sign in to comment.