forked from github/wulkanowy-mirror
Convert from a stringly typed grade color to enum GradeColorTheme (#1672)
This commit is contained in:
parent
ab435a72ea
commit
d2aa940d46
@ -3,7 +3,7 @@ package io.github.wulkanowy.data.db.migrations
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import io.github.wulkanowy.data.db.SharedPrefProvider
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeExpandMode
|
||||
import io.github.wulkanowy.data.enums.GradeExpandMode
|
||||
|
||||
class Migration41(private val sharedPrefProvider: SharedPrefProvider) : Migration(40, 41) {
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package io.github.wulkanowy.data.enums
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
enum class GradeColorTheme(val value: String) : Serializable {
|
||||
VULCAN("vulcan"),
|
||||
MATERIAL("material"),
|
||||
GRADE_COLOR("grade_color");
|
||||
|
||||
companion object {
|
||||
fun getByValue(value: String) = values().find { it.value == value } ?: VULCAN
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package io.github.wulkanowy.data.enums
|
||||
|
||||
enum class GradeExpandMode(val value: String) {
|
||||
ONE("one"),
|
||||
UNLIMITED("any"),
|
||||
ALWAYS_EXPANDED("always");
|
||||
|
||||
companion object {
|
||||
fun getByValue(value: String) = values().find { it.value == value } ?: ONE
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package io.github.wulkanowy.data.enums
|
||||
|
||||
enum class GradeSortingMode(val value: String) {
|
||||
ALPHABETIC("alphabetic"),
|
||||
DATE("date");
|
||||
|
||||
companion object {
|
||||
fun getByValue(value: String) = values().find { it.value == value } ?: ALPHABETIC
|
||||
}
|
||||
}
|
@ -7,11 +7,12 @@ import com.fredporciuncula.flow.preferences.FlowSharedPreferences
|
||||
import com.fredporciuncula.flow.preferences.Preference
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.data.enums.GradeExpandMode
|
||||
import io.github.wulkanowy.data.enums.GradeSortingMode
|
||||
import io.github.wulkanowy.sdk.toLocalDate
|
||||
import io.github.wulkanowy.ui.modules.dashboard.DashboardItem
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeAverageMode
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeExpandMode
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeSortingMode
|
||||
import io.github.wulkanowy.utils.toLocalDateTime
|
||||
import io.github.wulkanowy.utils.toTimestamp
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
@ -75,10 +76,12 @@ class PreferencesRepository @Inject constructor(
|
||||
val appTheme: String
|
||||
get() = getString(appThemeKey, R.string.pref_default_app_theme)
|
||||
|
||||
val gradeColorTheme: String
|
||||
get() = getString(
|
||||
R.string.pref_key_grade_color_scheme,
|
||||
R.string.pref_default_grade_color_scheme
|
||||
val gradeColorTheme: GradeColorTheme
|
||||
get() = GradeColorTheme.getByValue(
|
||||
getString(
|
||||
R.string.pref_key_grade_color_scheme,
|
||||
R.string.pref_default_grade_color_scheme
|
||||
)
|
||||
)
|
||||
|
||||
val appLanguageKey = context.getString(R.string.pref_key_app_language)
|
||||
|
@ -20,6 +20,7 @@ import io.github.wulkanowy.data.db.entities.AdminMessage
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.db.entities.Timetable
|
||||
import io.github.wulkanowy.data.db.entities.TimetableHeader
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.databinding.ItemDashboardAccountBinding
|
||||
import io.github.wulkanowy.databinding.ItemDashboardAdminMessageBinding
|
||||
import io.github.wulkanowy.databinding.ItemDashboardAnnouncementsBinding
|
||||
@ -262,7 +263,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView
|
||||
val isLoading = item.isLoading
|
||||
val dashboardGradesAdapter = gradesViewHolder.adapter.apply {
|
||||
this.items = subjectWithGrades.toList()
|
||||
this.gradeTheme = gradeTheme.orEmpty()
|
||||
this.gradeColorTheme = gradeTheme ?: GradeColorTheme.VULCAN
|
||||
}
|
||||
|
||||
with(gradesViewHolder.binding) {
|
||||
|
@ -4,6 +4,7 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.databinding.SubitemDashboardGradesBinding
|
||||
import io.github.wulkanowy.databinding.SubitemDashboardSmallGradeBinding
|
||||
import io.github.wulkanowy.utils.getBackgroundColor
|
||||
@ -12,7 +13,7 @@ class DashboardGradesAdapter : RecyclerView.Adapter<DashboardGradesAdapter.ViewH
|
||||
|
||||
var items = listOf<Pair<String, List<Grade>>>()
|
||||
|
||||
var gradeTheme = ""
|
||||
lateinit var gradeColorTheme: GradeColorTheme
|
||||
|
||||
override fun getItemCount() = items.size
|
||||
|
||||
@ -36,7 +37,7 @@ class DashboardGradesAdapter : RecyclerView.Adapter<DashboardGradesAdapter.ViewH
|
||||
|
||||
with(subitemBinding.dashboardSmallGradeSubitemValue) {
|
||||
text = it.entry
|
||||
setBackgroundResource(it.getBackgroundColor(gradeTheme))
|
||||
setBackgroundResource(it.getBackgroundColor(gradeColorTheme))
|
||||
}
|
||||
|
||||
dashboardGradesSubitemGradeContainer.addView(subitemBinding.root)
|
||||
|
@ -6,6 +6,7 @@ import io.github.wulkanowy.data.db.entities.Exam
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.data.db.entities.SchoolAnnouncement
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.data.pojos.TimetableFull
|
||||
import io.github.wulkanowy.data.db.entities.Homework as EntitiesHomework
|
||||
|
||||
@ -52,7 +53,7 @@ sealed class DashboardItem(val type: Type) {
|
||||
|
||||
data class Grades(
|
||||
val subjectWithGrades: Map<String, List<Grade>>? = null,
|
||||
val gradeTheme: String? = null,
|
||||
val gradeTheme: GradeColorTheme? = null,
|
||||
override val error: Throwable? = null,
|
||||
override val isLoading: Boolean = false
|
||||
) : DashboardItem(Type.GRADES) {
|
||||
|
@ -1,9 +0,0 @@
|
||||
package io.github.wulkanowy.ui.modules.grade
|
||||
|
||||
enum class GradeExpandMode(val value: String) {
|
||||
ONE("one"), UNLIMITED("any"), ALWAYS_EXPANDED("always");
|
||||
|
||||
companion object {
|
||||
fun getByValue(value: String) = values().firstOrNull { it.value == value } ?: ONE
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package io.github.wulkanowy.ui.modules.grade
|
||||
|
||||
enum class GradeSortingMode(val value: String) {
|
||||
ALPHABETIC("alphabetic"),
|
||||
DATE("date");
|
||||
|
||||
companion object {
|
||||
fun getByValue(value: String) = values().firstOrNull { it.value == value } ?: ALPHABETIC
|
||||
}
|
||||
}
|
@ -11,10 +11,11 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.NO_POSITION
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.data.enums.GradeExpandMode
|
||||
import io.github.wulkanowy.databinding.HeaderGradeDetailsBinding
|
||||
import io.github.wulkanowy.databinding.ItemGradeDetailsBinding
|
||||
import io.github.wulkanowy.ui.base.BaseExpandableAdapter
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeExpandMode
|
||||
import io.github.wulkanowy.utils.getBackgroundColor
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import timber.log.Timber
|
||||
@ -33,7 +34,7 @@ class GradeDetailsAdapter @Inject constructor() : BaseExpandableAdapter<Recycler
|
||||
|
||||
var onClickListener: (Grade, position: Int) -> Unit = { _, _ -> }
|
||||
|
||||
var colorTheme = ""
|
||||
lateinit var gradeColorTheme: GradeColorTheme
|
||||
|
||||
fun setDataItems(data: List<GradeDetailsItem>, expandMode: GradeExpandMode = this.expandMode) {
|
||||
headers = data.filter { it.viewType == ViewType.HEADER }.toMutableList()
|
||||
@ -202,7 +203,7 @@ class GradeDetailsAdapter @Inject constructor() : BaseExpandableAdapter<Recycler
|
||||
with(holder.binding) {
|
||||
gradeItemValue.run {
|
||||
text = grade.entry
|
||||
setBackgroundResource(grade.getBackgroundColor(colorTheme))
|
||||
setBackgroundResource(grade.getBackgroundColor(gradeColorTheme))
|
||||
}
|
||||
gradeItemDescription.text = when {
|
||||
grade.description.isNotBlank() -> grade.description
|
||||
|
@ -8,6 +8,7 @@ import android.view.ViewGroup
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.databinding.DialogGradeBinding
|
||||
import io.github.wulkanowy.utils.colorStringId
|
||||
import io.github.wulkanowy.utils.getBackgroundColor
|
||||
@ -21,19 +22,19 @@ class GradeDetailsDialog : DialogFragment() {
|
||||
|
||||
private lateinit var grade: Grade
|
||||
|
||||
private lateinit var colorScheme: String
|
||||
private lateinit var gradeColorTheme: GradeColorTheme
|
||||
|
||||
companion object {
|
||||
|
||||
private const val ARGUMENT_KEY = "Item"
|
||||
|
||||
private const val COLOR_SCHEME_KEY = "Scheme"
|
||||
private const val COLOR_THEME_KEY = "Theme"
|
||||
|
||||
fun newInstance(grade: Grade, colorScheme: String) =
|
||||
fun newInstance(grade: Grade, colorTheme: GradeColorTheme) =
|
||||
GradeDetailsDialog().apply {
|
||||
arguments = Bundle().apply {
|
||||
putSerializable(ARGUMENT_KEY, grade)
|
||||
putString(COLOR_SCHEME_KEY, colorScheme)
|
||||
putSerializable(COLOR_THEME_KEY, colorTheme)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,7 +44,7 @@ class GradeDetailsDialog : DialogFragment() {
|
||||
setStyle(STYLE_NO_TITLE, 0)
|
||||
arguments?.run {
|
||||
grade = getSerializable(ARGUMENT_KEY) as Grade
|
||||
colorScheme = getString(COLOR_SCHEME_KEY) ?: "default"
|
||||
gradeColorTheme = getSerializable(COLOR_THEME_KEY) as GradeColorTheme
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +77,7 @@ class GradeDetailsDialog : DialogFragment() {
|
||||
|
||||
gradeDialogValue.run {
|
||||
text = grade.entry
|
||||
setBackgroundResource(grade.getBackgroundColor(colorScheme))
|
||||
setBackgroundResource(grade.getBackgroundColor(gradeColorTheme))
|
||||
}
|
||||
|
||||
gradeDialogTeacherValue.text = if (grade.teacher.isBlank()) {
|
||||
|
@ -12,7 +12,8 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeExpandMode
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.data.enums.GradeExpandMode
|
||||
import io.github.wulkanowy.databinding.FragmentGradeDetailsBinding
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeFragment
|
||||
@ -80,9 +81,9 @@ class GradeDetailsFragment :
|
||||
else false
|
||||
}
|
||||
|
||||
override fun updateData(data: List<GradeDetailsItem>, expandMode: GradeExpandMode, gradeColorTheme: String) {
|
||||
override fun updateData(data: List<GradeDetailsItem>, expandMode: GradeExpandMode, gradeColorTheme: GradeColorTheme) {
|
||||
with(gradeDetailsAdapter) {
|
||||
colorTheme = gradeColorTheme
|
||||
this.gradeColorTheme = gradeColorTheme
|
||||
setDataItems(data, expandMode)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
@ -143,8 +144,8 @@ class GradeDetailsFragment :
|
||||
binding.gradeDetailsSwipe.isRefreshing = show
|
||||
}
|
||||
|
||||
override fun showGradeDialog(grade: Grade, colorScheme: String) {
|
||||
(activity as? MainActivity)?.showDialogFragment(GradeDetailsDialog.newInstance(grade, colorScheme))
|
||||
override fun showGradeDialog(grade: Grade, colorTheme: GradeColorTheme) {
|
||||
(activity as? MainActivity)?.showDialogFragment(GradeDetailsDialog.newInstance(grade, colorTheme))
|
||||
}
|
||||
|
||||
override fun onParentLoadData(semesterId: Int, forceRefresh: Boolean) {
|
||||
|
@ -2,6 +2,9 @@ package io.github.wulkanowy.ui.modules.grade.details
|
||||
|
||||
import io.github.wulkanowy.data.Status
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.data.enums.GradeExpandMode
|
||||
import io.github.wulkanowy.data.enums.GradeSortingMode.ALPHABETIC
|
||||
import io.github.wulkanowy.data.enums.GradeSortingMode.DATE
|
||||
import io.github.wulkanowy.data.repositories.GradeRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.data.repositories.SemesterRepository
|
||||
@ -9,9 +12,6 @@ import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeAverageProvider
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeExpandMode
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeSortingMode.ALPHABETIC
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeSortingMode.DATE
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeSubject
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.github.wulkanowy.utils.afterLoading
|
||||
|
@ -1,7 +1,8 @@
|
||||
package io.github.wulkanowy.ui.modules.grade.details
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeExpandMode
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.data.enums.GradeExpandMode
|
||||
import io.github.wulkanowy.ui.base.BaseView
|
||||
|
||||
interface GradeDetailsView : BaseView {
|
||||
@ -10,7 +11,7 @@ interface GradeDetailsView : BaseView {
|
||||
|
||||
fun initView()
|
||||
|
||||
fun updateData(data: List<GradeDetailsItem>, expandMode: GradeExpandMode, gradeColorTheme: String)
|
||||
fun updateData(data: List<GradeDetailsItem>, expandMode: GradeExpandMode, gradeColorTheme: GradeColorTheme)
|
||||
|
||||
fun updateItem(item: Grade, position: Int)
|
||||
|
||||
@ -22,7 +23,7 @@ interface GradeDetailsView : BaseView {
|
||||
|
||||
fun collapseAllItems()
|
||||
|
||||
fun showGradeDialog(grade: Grade, colorScheme: String)
|
||||
fun showGradeDialog(grade: Grade, colorTheme: GradeColorTheme)
|
||||
|
||||
fun showContent(show: Boolean)
|
||||
|
||||
|
@ -20,6 +20,7 @@ import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.GradePartialStatistics
|
||||
import io.github.wulkanowy.data.db.entities.GradePointsStatistics
|
||||
import io.github.wulkanowy.data.db.entities.GradeSemesterStatistics
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.data.pojos.GradeStatisticsItem
|
||||
import io.github.wulkanowy.databinding.ItemGradeStatisticsBarBinding
|
||||
import io.github.wulkanowy.databinding.ItemGradeStatisticsHeaderBinding
|
||||
@ -34,7 +35,7 @@ class GradeStatisticsAdapter @Inject constructor() :
|
||||
|
||||
var items = emptyList<GradeStatisticsItem>()
|
||||
|
||||
var theme: String = "vulcan"
|
||||
lateinit var gradeColorTheme: GradeColorTheme
|
||||
|
||||
var showAllSubjectsOnList: Boolean = false
|
||||
|
||||
@ -156,8 +157,8 @@ class GradeStatisticsAdapter @Inject constructor() :
|
||||
visibility = if (items.size == 1 || !showAllSubjectsOnList) GONE else VISIBLE
|
||||
}
|
||||
|
||||
val gradeColors = when (theme) {
|
||||
"vulcan" -> vulcanGradeColors
|
||||
val gradeColors = when (gradeColorTheme) {
|
||||
GradeColorTheme.VULCAN -> vulcanGradeColors
|
||||
else -> materialGradeColors
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import android.widget.TextView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.data.pojos.GradeStatisticsItem
|
||||
import io.github.wulkanowy.databinding.FragmentGradeStatisticsBinding
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
@ -90,12 +91,12 @@ class GradeStatisticsFragment :
|
||||
|
||||
override fun updateData(
|
||||
newItems: List<GradeStatisticsItem>,
|
||||
newTheme: String,
|
||||
newTheme: GradeColorTheme,
|
||||
showAllSubjectsOnStatisticsList: Boolean
|
||||
) {
|
||||
with(statisticsAdapter) {
|
||||
showAllSubjectsOnList = showAllSubjectsOnStatisticsList
|
||||
theme = newTheme
|
||||
gradeColorTheme = newTheme
|
||||
items = newItems
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.wulkanowy.ui.modules.grade.statistics
|
||||
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.data.pojos.GradeStatisticsItem
|
||||
import io.github.wulkanowy.ui.base.BaseView
|
||||
|
||||
@ -15,7 +16,7 @@ interface GradeStatisticsView : BaseView {
|
||||
|
||||
fun updateData(
|
||||
newItems: List<GradeStatisticsItem>,
|
||||
newTheme: String,
|
||||
newTheme: GradeColorTheme,
|
||||
showAllSubjectsOnStatisticsList: Boolean
|
||||
)
|
||||
|
||||
|
@ -3,6 +3,7 @@ package io.github.wulkanowy.utils
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.data.db.entities.GradeSummary
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.sdk.scrapper.grades.isGradeValid
|
||||
|
||||
fun List<Grade>.calcAverage(isOptionalArithmeticAverage: Boolean): Double {
|
||||
@ -37,28 +38,6 @@ fun List<GradeSummary>.calcFinalAverage(plusModifier: Double, minusModifier: Dou
|
||||
.average()
|
||||
.let { if (it.isNaN()) 0.0 else it }
|
||||
|
||||
fun Grade.getBackgroundColor(theme: String) = when (theme) {
|
||||
"grade_color" -> getGradeColor()
|
||||
"material" -> when (value.toInt()) {
|
||||
6 -> R.color.grade_material_six
|
||||
5 -> R.color.grade_material_five
|
||||
4 -> R.color.grade_material_four
|
||||
3 -> R.color.grade_material_three
|
||||
2 -> R.color.grade_material_two
|
||||
1 -> R.color.grade_material_one
|
||||
else -> R.color.grade_material_default
|
||||
}
|
||||
else -> when (value.toInt()) {
|
||||
6 -> R.color.grade_vulcan_six
|
||||
5 -> R.color.grade_vulcan_five
|
||||
4 -> R.color.grade_vulcan_four
|
||||
3 -> R.color.grade_vulcan_three
|
||||
2 -> R.color.grade_vulcan_two
|
||||
1 -> R.color.grade_vulcan_one
|
||||
else -> R.color.grade_vulcan_default
|
||||
}
|
||||
}
|
||||
|
||||
fun Grade.getGradeColor() = when (color) {
|
||||
"000000" -> R.color.grade_black
|
||||
"F04C4C" -> R.color.grade_red
|
||||
@ -83,3 +62,25 @@ fun Grade.changeModifier(plusModifier: Double, minusModifier: Double) = when {
|
||||
modifier < 0 -> copy(modifier = -minusModifier)
|
||||
else -> this
|
||||
}
|
||||
|
||||
fun Grade.getBackgroundColor(theme: GradeColorTheme) = when (theme) {
|
||||
GradeColorTheme.GRADE_COLOR -> getGradeColor()
|
||||
GradeColorTheme.MATERIAL -> when (value.toInt()) {
|
||||
6 -> R.color.grade_material_six
|
||||
5 -> R.color.grade_material_five
|
||||
4 -> R.color.grade_material_four
|
||||
3 -> R.color.grade_material_three
|
||||
2 -> R.color.grade_material_two
|
||||
1 -> R.color.grade_material_one
|
||||
else -> R.color.grade_material_default
|
||||
}
|
||||
GradeColorTheme.VULCAN -> when (value.toInt()) {
|
||||
6 -> R.color.grade_vulcan_six
|
||||
5 -> R.color.grade_vulcan_five
|
||||
4 -> R.color.grade_vulcan_four
|
||||
3 -> R.color.grade_vulcan_three
|
||||
2 -> R.color.grade_vulcan_two
|
||||
1 -> R.color.grade_vulcan_one
|
||||
else -> R.color.grade_vulcan_default
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package io.github.wulkanowy.utils
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.data.db.entities.GradeSummary
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import org.junit.Assert.assertEquals
|
||||
@ -46,10 +47,25 @@ class GradeExtensionTest {
|
||||
|
||||
@Test
|
||||
fun getBackgroundColor() {
|
||||
assertEquals(R.color.grade_material_five, createGrade(5.0).getBackgroundColor("material"))
|
||||
assertEquals(R.color.grade_material_five, createGrade(5.5).getBackgroundColor("material"))
|
||||
assertEquals(R.color.grade_material_five, createGrade(5.9).getBackgroundColor("material"))
|
||||
assertEquals(R.color.grade_vulcan_five, createGrade(5.9).getBackgroundColor("whatever"))
|
||||
assertEquals(
|
||||
R.color.grade_material_five, createGrade(5.0).getBackgroundColor(
|
||||
GradeColorTheme.MATERIAL
|
||||
)
|
||||
)
|
||||
assertEquals(
|
||||
R.color.grade_material_five, createGrade(5.5).getBackgroundColor(
|
||||
GradeColorTheme.MATERIAL
|
||||
)
|
||||
)
|
||||
assertEquals(
|
||||
R.color.grade_material_five, createGrade(5.9).getBackgroundColor(
|
||||
GradeColorTheme.MATERIAL
|
||||
)
|
||||
)
|
||||
assertEquals(
|
||||
R.color.grade_vulcan_five,
|
||||
createGrade(5.9).getBackgroundColor(GradeColorTheme.VULCAN)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user