1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-31 18:52:45 +01:00

Add option to change grade (background) color scheme (#259)

This commit is contained in:
Mikołaj Pich 2019-03-03 15:11:20 +01:00 committed by Rafał Borcz
parent 1b30b00bb8
commit cae4f140e6
17 changed files with 104 additions and 35 deletions

View File

@ -1,6 +1,8 @@
package io.github.wulkanowy.data.db package io.github.wulkanowy.data.db
import androidx.room.TypeConverter import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import org.threeten.bp.DateTimeUtils import org.threeten.bp.DateTimeUtils
import org.threeten.bp.Instant import org.threeten.bp.Instant
import org.threeten.bp.LocalDate import org.threeten.bp.LocalDate
@ -8,8 +10,6 @@ import org.threeten.bp.LocalDateTime
import org.threeten.bp.Month import org.threeten.bp.Month
import org.threeten.bp.ZoneOffset import org.threeten.bp.ZoneOffset
import java.util.Date import java.util.Date
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
class Converters { class Converters {

View File

@ -30,6 +30,10 @@ class PreferencesRepository @Inject constructor(
val gradeMinusModifier: Double val gradeMinusModifier: Double
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_modifier_minus), "0.0")?.toDouble() ?: 0.0 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 serviceEnablesKey: String = context.getString(R.string.pref_key_services_enable)
val isServiceEnabled: Boolean val isServiceEnabled: Boolean
get() = sharedPref.getBoolean(serviceEnablesKey, true) get() = sharedPref.getBoolean(serviceEnablesKey, true)

View File

@ -5,26 +5,30 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.View.GONE import android.view.View.GONE
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Grade import io.github.wulkanowy.data.db.entities.Grade
import io.github.wulkanowy.utils.colorStringId import io.github.wulkanowy.utils.colorStringId
import io.github.wulkanowy.utils.getBackgroundColor
import io.github.wulkanowy.utils.toFormattedString import io.github.wulkanowy.utils.toFormattedString
import io.github.wulkanowy.utils.valueBgColor
import kotlinx.android.synthetic.main.dialog_grade.* import kotlinx.android.synthetic.main.dialog_grade.*
class GradeDetailsDialog : DialogFragment() { class GradeDetailsDialog : DialogFragment() {
private lateinit var grade: Grade private lateinit var grade: Grade
private lateinit var colorScheme: String
companion object { companion object {
private const val ARGUMENT_KEY = "Item" 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 { 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) setStyle(STYLE_NO_TITLE, 0)
arguments?.run { arguments?.run {
grade = getSerializable(ARGUMENT_KEY) as Grade grade = getSerializable(ARGUMENT_KEY) as Grade
colorScheme = getString(COLOR_SCHEME_KEY) ?: "default"
} }
} }
@ -58,7 +63,7 @@ class GradeDetailsDialog : DialogFragment() {
gradeDialogValue.run { gradeDialogValue.run {
text = grade.entry text = grade.entry
setBackgroundResource(grade.valueBgColor) setBackgroundResource(grade.getBackgroundColor(colorScheme))
} }
gradeDialogTeacherValue.text = if (grade.teacher.isBlank()) { gradeDialogTeacherValue.text = if (grade.teacher.isBlank()) {

View File

@ -134,8 +134,8 @@ class GradeDetailsFragment : BaseSessionFragment(), GradeDetailsView, GradeView.
gradeDetailsSwipe.isRefreshing = show gradeDetailsSwipe.isRefreshing = show
} }
override fun showGradeDialog(grade: Grade) { override fun showGradeDialog(grade: Grade, colorScheme: String) {
(activity as? MainActivity)?.showDialogFragment(GradeDetailsDialog.newInstance(grade)) (activity as? MainActivity)?.showDialogFragment(GradeDetailsDialog.newInstance(grade, colorScheme))
} }
override fun onParentLoadData(semesterId: Int, forceRefresh: Boolean) { override fun onParentLoadData(semesterId: Int, forceRefresh: Boolean) {

View File

@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.view.View import android.view.View
import android.view.View.GONE import android.view.View.GONE
import android.view.View.VISIBLE import android.view.View.VISIBLE
import androidx.core.content.ContextCompat
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible

View File

@ -12,7 +12,7 @@ import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
import io.github.wulkanowy.utils.SchedulersProvider import io.github.wulkanowy.utils.SchedulersProvider
import io.github.wulkanowy.utils.calcAverage import io.github.wulkanowy.utils.calcAverage
import io.github.wulkanowy.utils.changeModifier import io.github.wulkanowy.utils.changeModifier
import io.github.wulkanowy.utils.valueBgColor import io.github.wulkanowy.utils.getBackgroundColor
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -42,7 +42,7 @@ class GradeDetailsPresenter @Inject constructor(
if (item is GradeDetailsItem) { if (item is GradeDetailsItem) {
Timber.i("Select grade item ${item.grade.id}") Timber.i("Select grade item ${item.grade.id}")
view?.apply { view?.apply {
showGradeDialog(item.grade) showGradeDialog(item.grade, preferencesRepository.gradeColorTheme)
if (!item.grade.isRead) { if (!item.grade.isRead) {
item.grade.isRead = true item.grade.isRead = true
updateItem(item) updateItem(item)
@ -151,7 +151,7 @@ class GradeDetailsPresenter @Inject constructor(
GradeDetailsItem( GradeDetailsItem(
grade = item, grade = item,
weightString = view?.weightString.orEmpty(), weightString = view?.weightString.orEmpty(),
valueBgColor = item.valueBgColor valueBgColor = item.getBackgroundColor(preferencesRepository.gradeColorTheme)
) )
} }
} }

View File

@ -28,7 +28,7 @@ interface GradeDetailsView : BaseSessionView {
fun collapseAllItems() fun collapseAllItems()
fun showGradeDialog(grade: Grade) fun showGradeDialog(grade: Grade, colorScheme: String)
fun showContent(show: Boolean) fun showContent(show: Boolean)

View File

@ -22,18 +22,36 @@ fun List<GradeSummary>.calcAverage(): Double {
}.average().let { if (it.isNaN()) 0.0 else it } }.average().let { if (it.isNaN()) 0.0 else it }
} }
inline val Grade.valueBgColor: Int fun Grade.getBackgroundColor(theme: String): Int {
get() { return when (theme) {
return when (value) { "grade_color" -> when (color) {
6 -> R.color.grade_six "000000" -> R.color.grade_black
5 -> R.color.grade_five "F04C4C" -> R.color.grade_red
4 -> R.color.grade_four "20A4F7" -> R.color.grade_blue
3 -> R.color.grade_three "6ECD07" -> R.color.grade_green
2 -> R.color.grade_two "B16CF1" -> R.color.grade_purple
1 -> R.color.grade_one 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 else -> R.color.grade_default
} }
} }
}
inline val Grade.colorStringId: Int inline val Grade.colorStringId: Int
get() { get() {

View File

@ -26,9 +26,9 @@
android:layout_gravity="end" android:layout_gravity="end"
android:background="@color/grade_default" android:background="@color/grade_default"
android:gravity="center" android:gravity="center"
android:text="@string/app_name"
android:textColor="@color/grade_text" android:textColor="@color/grade_text"
android:textSize="30sp" /> android:textSize="30sp"
tools:text="6" />
<TextView <TextView
android:id="@+id/gradeDialogSubject" android:id="@+id/gradeDialogSubject"

View File

@ -21,9 +21,9 @@
android:background="@color/grade_default" android:background="@color/grade_default"
android:gravity="center" android:gravity="center"
android:maxLength="5" android:maxLength="5"
android:text="@string/app_name"
android:textColor="@color/grade_text" android:textColor="@color/grade_text"
android:textSize="16sp" /> android:textSize="16sp"
tools:text="6" />
<TextView <TextView
android:id="@+id/gradeItemDescription" android:id="@+id/gradeItemDescription"

View File

@ -251,6 +251,7 @@
<string name="pref_view_grade_modifier_plus">Wartość plusa</string> <string name="pref_view_grade_modifier_plus">Wartość plusa</string>
<string name="pref_view_grade_modifier_minus">Wartość minusa</string> <string name="pref_view_grade_modifier_minus">Wartość minusa</string>
<string name="pref_view_expand_grade">Rozwiń oceny</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_header">Powiadomienia</string>
<string name="pref_notify_switch">Pokazuj powiadomienia</string> <string name="pref_notify_switch">Pokazuj powiadomienia</string>

View File

@ -9,16 +9,24 @@
<item>12 godzin</item> <item>12 godzin</item>
<item>24 godzin</item> <item>24 godzin</item>
</string-array> </string-array>
<string-array name="theme_entries"> <string-array name="theme_entries">
<item>Wyłączony</item> <item>Wyłączony</item>
<item>Włączony</item> <item>Włączony</item>
<item>Automatyczny</item> <item>Automatyczny</item>
<item>Używaj ustawień systemowych</item> <item>Używaj ustawień systemowych</item>
</string-array> </string-array>
<string-array name="grade_modifier_entries"> <string-array name="grade_modifier_entries">
<item>Domyślna</item> <item>Domyślna</item>
<item>0,25</item> <item>0,25</item>
<item>0,33</item> <item>0,33</item>
<item>0,5</item> <item>0,5</item>
</string-array> </string-array>
<string-array name="grade_color_scheme_entries">
<item>Dzienniczek+</item>
<item>Wulkanowy</item>
<item>Kolory ocen w dzienniku</item>
</string-array>
</resources> </resources>

View File

@ -5,16 +5,29 @@
<color name="colorPrimaryLight">#ff6659</color> <color name="colorPrimaryLight">#ff6659</color>
<color name="colorBackgroundBottomNav">#f0f0f0</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_default">#607d8b</color>
<color name="grade_text">#ffffff</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">#303030</color>
<color name="bottom_nav_background_inverse">#ffffff</color> <color name="bottom_nav_background_inverse">#ffffff</color>

View File

@ -5,6 +5,7 @@
<string name="pref_key_theme">theme</string> <string name="pref_key_theme">theme</string>
<string name="pref_key_grade_modifier_plus">grade_modifier_plus</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_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_expand_grade">expand_grade</string>
<string name="pref_key_services_enable">services_enable</string> <string name="pref_key_services_enable">services_enable</string>
<string name="pref_key_services_interval">services_interval</string> <string name="pref_key_services_interval">services_interval</string>

View File

@ -234,6 +234,7 @@
<string name="pref_view_grade_modifier_plus">Value of the plus</string> <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_grade_modifier_minus">Value of the minus</string>
<string name="pref_view_expand_grade">Expand grades</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_header">Notifications</string>
<string name="pref_notify_switch">Show notifications</string> <string name="pref_notify_switch">Show notifications</string>

View File

@ -57,4 +57,15 @@
<item>0.33</item> <item>0.33</item>
<item>0.5</item> <item>0.5</item>
</string-array> </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> </resources>

View File

@ -30,6 +30,14 @@
android:key="@string/pref_key_expand_grade" android:key="@string/pref_key_expand_grade"
android:title="@string/pref_view_expand_grade" android:title="@string/pref_view_expand_grade"
app:iconSpaceReserved="false" /> 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 <ListPreference
android:defaultValue="0.0" android:defaultValue="0.0"
android:entries="@array/grade_modifier_entries" android:entries="@array/grade_modifier_entries"