forked from github/wulkanowy-mirror
Add option to change grade (background) color scheme (#259)
This commit is contained in:
parent
1b30b00bb8
commit
cae4f140e6
@ -1,6 +1,8 @@
|
||||
package io.github.wulkanowy.data.db
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import org.threeten.bp.DateTimeUtils
|
||||
import org.threeten.bp.Instant
|
||||
import org.threeten.bp.LocalDate
|
||||
@ -8,8 +10,6 @@ import org.threeten.bp.LocalDateTime
|
||||
import org.threeten.bp.Month
|
||||
import org.threeten.bp.ZoneOffset
|
||||
import java.util.Date
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
||||
class Converters {
|
||||
|
||||
|
@ -30,6 +30,10 @@ class PreferencesRepository @Inject constructor(
|
||||
val gradeMinusModifier: Double
|
||||
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_modifier_minus), "0.0")?.toDouble() ?: 0.0
|
||||
|
||||
val gradeColorTheme: String
|
||||
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_color_scheme), "vulcan") ?: "vulcan"
|
||||
|
||||
|
||||
val serviceEnablesKey: String = context.getString(R.string.pref_key_services_enable)
|
||||
val isServiceEnabled: Boolean
|
||||
get() = sharedPref.getBoolean(serviceEnablesKey, true)
|
||||
|
@ -5,26 +5,30 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.utils.colorStringId
|
||||
import io.github.wulkanowy.utils.getBackgroundColor
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import io.github.wulkanowy.utils.valueBgColor
|
||||
import kotlinx.android.synthetic.main.dialog_grade.*
|
||||
|
||||
|
||||
class GradeDetailsDialog : DialogFragment() {
|
||||
|
||||
private lateinit var grade: Grade
|
||||
|
||||
private lateinit var colorScheme: String
|
||||
|
||||
companion object {
|
||||
private const val ARGUMENT_KEY = "Item"
|
||||
private const val COLOR_SCHEME_KEY = "Scheme"
|
||||
|
||||
fun newInstance(grade: Grade): GradeDetailsDialog {
|
||||
fun newInstance(grade: Grade, colorScheme: String): GradeDetailsDialog {
|
||||
return GradeDetailsDialog().apply {
|
||||
arguments = Bundle().apply { putSerializable(ARGUMENT_KEY, grade) }
|
||||
arguments = Bundle().apply {
|
||||
putSerializable(ARGUMENT_KEY, grade)
|
||||
putString(COLOR_SCHEME_KEY, colorScheme)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -34,6 +38,7 @@ class GradeDetailsDialog : DialogFragment() {
|
||||
setStyle(STYLE_NO_TITLE, 0)
|
||||
arguments?.run {
|
||||
grade = getSerializable(ARGUMENT_KEY) as Grade
|
||||
colorScheme = getString(COLOR_SCHEME_KEY) ?: "default"
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +63,7 @@ class GradeDetailsDialog : DialogFragment() {
|
||||
|
||||
gradeDialogValue.run {
|
||||
text = grade.entry
|
||||
setBackgroundResource(grade.valueBgColor)
|
||||
setBackgroundResource(grade.getBackgroundColor(colorScheme))
|
||||
}
|
||||
|
||||
gradeDialogTeacherValue.text = if (grade.teacher.isBlank()) {
|
||||
|
@ -134,8 +134,8 @@ class GradeDetailsFragment : BaseSessionFragment(), GradeDetailsView, GradeView.
|
||||
gradeDetailsSwipe.isRefreshing = show
|
||||
}
|
||||
|
||||
override fun showGradeDialog(grade: Grade) {
|
||||
(activity as? MainActivity)?.showDialogFragment(GradeDetailsDialog.newInstance(grade))
|
||||
override fun showGradeDialog(grade: Grade, colorScheme: String) {
|
||||
(activity as? MainActivity)?.showDialogFragment(GradeDetailsDialog.newInstance(grade, colorScheme))
|
||||
}
|
||||
|
||||
override fun onParentLoadData(semesterId: Int, forceRefresh: Boolean) {
|
||||
|
@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
||||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import androidx.core.content.ContextCompat
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
|
@ -12,7 +12,7 @@ import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.github.wulkanowy.utils.calcAverage
|
||||
import io.github.wulkanowy.utils.changeModifier
|
||||
import io.github.wulkanowy.utils.valueBgColor
|
||||
import io.github.wulkanowy.utils.getBackgroundColor
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -42,7 +42,7 @@ class GradeDetailsPresenter @Inject constructor(
|
||||
if (item is GradeDetailsItem) {
|
||||
Timber.i("Select grade item ${item.grade.id}")
|
||||
view?.apply {
|
||||
showGradeDialog(item.grade)
|
||||
showGradeDialog(item.grade, preferencesRepository.gradeColorTheme)
|
||||
if (!item.grade.isRead) {
|
||||
item.grade.isRead = true
|
||||
updateItem(item)
|
||||
@ -151,7 +151,7 @@ class GradeDetailsPresenter @Inject constructor(
|
||||
GradeDetailsItem(
|
||||
grade = item,
|
||||
weightString = view?.weightString.orEmpty(),
|
||||
valueBgColor = item.valueBgColor
|
||||
valueBgColor = item.getBackgroundColor(preferencesRepository.gradeColorTheme)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ interface GradeDetailsView : BaseSessionView {
|
||||
|
||||
fun collapseAllItems()
|
||||
|
||||
fun showGradeDialog(grade: Grade)
|
||||
fun showGradeDialog(grade: Grade, colorScheme: String)
|
||||
|
||||
fun showContent(show: Boolean)
|
||||
|
||||
|
@ -22,18 +22,36 @@ fun List<GradeSummary>.calcAverage(): Double {
|
||||
}.average().let { if (it.isNaN()) 0.0 else it }
|
||||
}
|
||||
|
||||
inline val Grade.valueBgColor: Int
|
||||
get() {
|
||||
return when (value) {
|
||||
6 -> R.color.grade_six
|
||||
5 -> R.color.grade_five
|
||||
4 -> R.color.grade_four
|
||||
3 -> R.color.grade_three
|
||||
2 -> R.color.grade_two
|
||||
1 -> R.color.grade_one
|
||||
fun Grade.getBackgroundColor(theme: String): Int {
|
||||
return when (theme) {
|
||||
"grade_color" -> when (color) {
|
||||
"000000" -> R.color.grade_black
|
||||
"F04C4C" -> R.color.grade_red
|
||||
"20A4F7" -> R.color.grade_blue
|
||||
"6ECD07" -> R.color.grade_green
|
||||
"B16CF1" -> R.color.grade_purple
|
||||
else -> R.color.grade_default
|
||||
}
|
||||
"material" -> when (value) {
|
||||
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_default
|
||||
}
|
||||
else -> when (value) {
|
||||
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_default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline val Grade.colorStringId: Int
|
||||
get() {
|
||||
|
@ -26,9 +26,9 @@
|
||||
android:layout_gravity="end"
|
||||
android:background="@color/grade_default"
|
||||
android:gravity="center"
|
||||
android:text="@string/app_name"
|
||||
android:textColor="@color/grade_text"
|
||||
android:textSize="30sp" />
|
||||
android:textSize="30sp"
|
||||
tools:text="6" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gradeDialogSubject"
|
||||
|
@ -21,9 +21,9 @@
|
||||
android:background="@color/grade_default"
|
||||
android:gravity="center"
|
||||
android:maxLength="5"
|
||||
android:text="@string/app_name"
|
||||
android:textColor="@color/grade_text"
|
||||
android:textSize="16sp" />
|
||||
android:textSize="16sp"
|
||||
tools:text="6" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gradeItemDescription"
|
||||
|
@ -251,6 +251,7 @@
|
||||
<string name="pref_view_grade_modifier_plus">Wartość plusa</string>
|
||||
<string name="pref_view_grade_modifier_minus">Wartość minusa</string>
|
||||
<string name="pref_view_expand_grade">Rozwiń oceny</string>
|
||||
<string name="pref_grade_color_scheme">Schemat kolorów ocen</string>
|
||||
|
||||
<string name="pref_notify_header">Powiadomienia</string>
|
||||
<string name="pref_notify_switch">Pokazuj powiadomienia</string>
|
||||
|
@ -9,16 +9,24 @@
|
||||
<item>12 godzin</item>
|
||||
<item>24 godzin</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="theme_entries">
|
||||
<item>Wyłączony</item>
|
||||
<item>Włączony</item>
|
||||
<item>Automatyczny</item>
|
||||
<item>Używaj ustawień systemowych</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="grade_modifier_entries">
|
||||
<item>Domyślna</item>
|
||||
<item>0,25</item>
|
||||
<item>0,33</item>
|
||||
<item>0,5</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="grade_color_scheme_entries">
|
||||
<item>Dzienniczek+</item>
|
||||
<item>Wulkanowy</item>
|
||||
<item>Kolory ocen w dzienniku</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -5,16 +5,29 @@
|
||||
<color name="colorPrimaryLight">#ff6659</color>
|
||||
<color name="colorBackgroundBottomNav">#f0f0f0</color>
|
||||
|
||||
<color name="grade_six">#03a9f4</color>
|
||||
<color name="grade_five">#4caf50</color>
|
||||
<color name="grade_four">#92c400</color>
|
||||
<color name="grade_three">#ffa000</color>
|
||||
<color name="grade_two">#ff5722</color>
|
||||
<color name="grade_one">#d32f2f</color>
|
||||
<color name="grade_default">#607d8b</color>
|
||||
|
||||
<color name="grade_text">#ffffff</color>
|
||||
|
||||
<color name="grade_black">#424242</color>
|
||||
<color name="grade_red">#F44336</color>
|
||||
<color name="grade_blue">#2196F3</color>
|
||||
<color name="grade_green">#8BC34A</color>
|
||||
<color name="grade_purple">#7E57C2</color>
|
||||
|
||||
<color name="grade_material_six">#03a9f4</color>
|
||||
<color name="grade_material_five">#4caf50</color>
|
||||
<color name="grade_material_four">#92c400</color>
|
||||
<color name="grade_material_three">#ffa000</color>
|
||||
<color name="grade_material_two">#ff5722</color>
|
||||
<color name="grade_material_one">#d32f2f</color>
|
||||
|
||||
<color name="grade_vulcan_six">#91b43c</color>
|
||||
<color name="grade_vulcan_five">#2cbd92</color>
|
||||
<color name="grade_vulcan_four">#50b6d6</color>
|
||||
<color name="grade_vulcan_three">#d2ab24</color>
|
||||
<color name="grade_vulcan_two">#9071b3</color>
|
||||
<color name="grade_vulcan_one">#d65757</color>
|
||||
|
||||
<color name="bottom_nav_background">#303030</color>
|
||||
<color name="bottom_nav_background_inverse">#ffffff</color>
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
<string name="pref_key_theme">theme</string>
|
||||
<string name="pref_key_grade_modifier_plus">grade_modifier_plus</string>
|
||||
<string name="pref_key_grade_modifier_minus">grade_modifier_minus</string>
|
||||
<string name="pref_key_grade_color_scheme">grade_color_scheme</string>
|
||||
<string name="pref_key_expand_grade">expand_grade</string>
|
||||
<string name="pref_key_services_enable">services_enable</string>
|
||||
<string name="pref_key_services_interval">services_interval</string>
|
||||
|
@ -234,6 +234,7 @@
|
||||
<string name="pref_view_grade_modifier_plus">Value of the plus</string>
|
||||
<string name="pref_view_grade_modifier_minus">Value of the minus</string>
|
||||
<string name="pref_view_expand_grade">Expand grades</string>
|
||||
<string name="pref_grade_color_scheme">Grades color scheme</string>
|
||||
|
||||
<string name="pref_notify_header">Notifications</string>
|
||||
<string name="pref_notify_switch">Show notifications</string>
|
||||
|
@ -57,4 +57,15 @@
|
||||
<item>0.33</item>
|
||||
<item>0.5</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="grade_color_scheme_entries">
|
||||
<item>Dzienniczek+</item>
|
||||
<item>Wulkanowy</item>
|
||||
<item>Grade colors in register</item>
|
||||
</string-array>
|
||||
<string-array name="grade_color_scheme_values" translatable="false">
|
||||
<item>vulcan</item>
|
||||
<item>material</item>
|
||||
<item>grade_color</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -30,6 +30,14 @@
|
||||
android:key="@string/pref_key_expand_grade"
|
||||
android:title="@string/pref_view_expand_grade"
|
||||
app:iconSpaceReserved="false" />
|
||||
<ListPreference
|
||||
android:defaultValue="vulcan"
|
||||
android:entries="@array/grade_color_scheme_entries"
|
||||
android:entryValues="@array/grade_color_scheme_values"
|
||||
android:key="@string/pref_key_grade_color_scheme"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_grade_color_scheme"
|
||||
app:iconSpaceReserved="false" />
|
||||
<ListPreference
|
||||
android:defaultValue="0.0"
|
||||
android:entries="@array/grade_modifier_entries"
|
||||
|
Loading…
x
Reference in New Issue
Block a user