Skip to content

Commit

Permalink
Fix oppia#206: Remove color-darkening computation. (oppia#3100)
Browse files Browse the repository at this point in the history
* Remove the color darkening computation.

* Remove backgroundColor from TopicSummaryViewModel.

* Add more properties to the walkthrough_lesson_count_text_view.
  • Loading branch information
viktoriias committed Apr 21, 2021
1 parent 0027ded commit adae599
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
package org.oppia.android.app.home.topiclist

import android.graphics.Color
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity
import org.oppia.android.R
import org.oppia.android.app.home.HomeItemViewModel
import org.oppia.android.app.model.TopicSummary
import java.util.Objects

// TODO(#206): Remove the color darkening computation and properly set up the topic thumbnails.
// These values were roughly computed based on the mocks. They won't produce the same colors since darker colors in the
// mocks were not consistently darker. An alternative would be to specify both background colors together to ensure
// proper contrast with readable elements.
const val DARKEN_VALUE_MULTIPLIER: Float = 0.9f
const val DARKEN_SATURATION_MULTIPLIER: Float = 1.2f

/** The view model corresponding to individual topic summaries in the topic summary RecyclerView. */
class TopicSummaryViewModel(
private val activity: AppCompatActivity,
Expand All @@ -26,11 +17,6 @@ class TopicSummaryViewModel(
val name: String = topicSummary.name
val totalChapterCount: Int = topicSummary.totalChapterCount

@ColorInt
val backgroundColor: Int = retrieveBackgroundColor()

@ColorInt
val darkerBackgroundOverlayColor: Int = computeDarkerBackgroundColor()
private val outerMargin by lazy {
activity.resources.getDimensionPixelSize(R.dimen.home_outer_margin)
}
Expand Down Expand Up @@ -114,20 +100,6 @@ class TopicSummaryViewModel(
}
}

@ColorInt
private fun retrieveBackgroundColor(): Int {
return topicSummary.topicThumbnail.backgroundColorRgb
}

/** Returns a version of [backgroundColor] that is slightly darker. */
private fun computeDarkerBackgroundColor(): Int {
val hsv = floatArrayOf(0f, 0f, 0f)
Color.colorToHSV(backgroundColor, hsv)
hsv[1] = (hsv[1] * DARKEN_SATURATION_MULTIPLIER).coerceIn(0f, 1f)
hsv[2] = (hsv[2] * DARKEN_VALUE_MULTIPLIER).coerceIn(0f, 1f)
return Color.HSVToColor(hsv)
}

// Overriding equals is needed so that DataProvider combine functions used in the HomeViewModel
// will only rebind when the actual data in the data list changes, rather than when the ViewModel
// object changes.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package org.oppia.android.app.walkthrough.topiclist.topiclistviewmodel

import android.graphics.Color
import androidx.annotation.ColorInt
import androidx.lifecycle.ViewModel
import org.oppia.android.app.home.topiclist.TopicSummaryClickListener
import org.oppia.android.app.model.TopicSummary
import org.oppia.android.app.walkthrough.topiclist.WalkthroughTopicItemViewModel

// TODO(#206): Remove the color darkening computation and properly set up the topic thumbnails.
// These values were roughly computed based on the mocks. They won't produce the same colors since darker colors in the
// mocks were not consistently darker. An alternative would be to specify both background colors together to ensure
// proper contrast with readable elements.
private const val DARKEN_VALUE_MULTIPLIER: Float = 0.9f
private const val DARKEN_SATURATION_MULTIPLIER: Float = 1.2f

/** The view model corresponding to topic summaries in the topic summary RecyclerView. */

/** [ViewModel] corresponding to topic summaries in [WalkthroughTopicListFragment] RecyclerView.. */
Expand All @@ -28,9 +20,6 @@ class WalkthroughTopicSummaryViewModel(
@ColorInt
val backgroundColor: Int = retrieveBackgroundColor()

@ColorInt
val darkerBackgroundOverlayColor: Int = computeDarkerBackgroundColor()

/** Callback from data-binding for when the summary tile is clicked. */
fun clickOnSummaryTile() {
topicSummaryClickListener.onTopicSummaryClicked(topicSummary)
Expand All @@ -40,13 +29,4 @@ class WalkthroughTopicSummaryViewModel(
private fun retrieveBackgroundColor(): Int {
return topicSummary.topicThumbnail.backgroundColorRgb
}

/** Returns a version of [backgroundColor] that is slightly darker. */
private fun computeDarkerBackgroundColor(): Int {
val hsv = floatArrayOf(0f, 0f, 0f)
Color.colorToHSV(backgroundColor, hsv)
hsv[1] = (hsv[1] * DARKEN_SATURATION_MULTIPLIER).coerceIn(0f, 1f)
hsv[2] = (hsv[2] * DARKEN_VALUE_MULTIPLIER).coerceIn(0f, 1f)
return Color.HSVToColor(hsv)
}
}
8 changes: 5 additions & 3 deletions app/src/main/res/layout/walkthrough_topic_summary_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

<org.oppia.android.app.customview.LessonThumbnailImageView
android:id="@+id/walkthrough_topic_thumbnail_image_view"
android:layout_width="match_parent"
android:layout_height="92dp"
android:layout_width="0dp"
android:layout_height="0dp"
android:importantForAccessibility="no"
android:scaleType="centerInside"
app:entityId="@{viewModel.topicSummary.topicId}"
Expand All @@ -46,7 +46,7 @@
android:id="@+id/bottom_topic_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:bottomRoundedRectDrawableWithColor="@{viewModel.darkerBackgroundOverlayColor}"
android:background="@color/topicTitleBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

Expand Down Expand Up @@ -76,7 +76,9 @@
android:id="@+id/walkthrough_lesson_count_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="sans-serif-light"
android:lines="1"
android:text="@{@plurals/lesson_count(viewModel.totalChapterCount, viewModel.totalChapterCount)}"
android:textColor="@color/white_80"
android:textSize="14sp"
Expand Down

0 comments on commit adae599

Please sign in to comment.