mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 13:28:21 +01:00
parent
533637d32a
commit
2f24b25399
@ -22,6 +22,9 @@ class PreferencesRepository @Inject constructor(
|
|||||||
val currentTheme: Int
|
val currentTheme: Int
|
||||||
get() = sharedPref.getString(currentThemeKey, "1")?.toInt() ?: 1
|
get() = sharedPref.getString(currentThemeKey, "1")?.toInt() ?: 1
|
||||||
|
|
||||||
|
val gradeModifier: Double
|
||||||
|
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_modifier), "0.0")?.toDouble() ?: 0.0
|
||||||
|
|
||||||
val serviceEnablesKey: String = context.getString(R.string.pref_key_services_enable)
|
val serviceEnablesKey: String = context.getString(R.string.pref_key_services_enable)
|
||||||
val serviceEnabled: Boolean
|
val serviceEnabled: Boolean
|
||||||
get() = sharedPref.getBoolean(serviceEnablesKey, true)
|
get() = sharedPref.getBoolean(serviceEnablesKey, true)
|
||||||
|
@ -4,10 +4,12 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
|||||||
import io.github.wulkanowy.data.ErrorHandler
|
import io.github.wulkanowy.data.ErrorHandler
|
||||||
import io.github.wulkanowy.data.db.entities.Grade
|
import io.github.wulkanowy.data.db.entities.Grade
|
||||||
import io.github.wulkanowy.data.repositories.GradeRepository
|
import io.github.wulkanowy.data.repositories.GradeRepository
|
||||||
|
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||||
import io.github.wulkanowy.data.repositories.SessionRepository
|
import io.github.wulkanowy.data.repositories.SessionRepository
|
||||||
import io.github.wulkanowy.ui.base.BasePresenter
|
import io.github.wulkanowy.ui.base.BasePresenter
|
||||||
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.logEvent
|
import io.github.wulkanowy.utils.logEvent
|
||||||
import io.github.wulkanowy.utils.valueColor
|
import io.github.wulkanowy.utils.valueColor
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -17,7 +19,8 @@ class GradeDetailsPresenter @Inject constructor(
|
|||||||
private val errorHandler: ErrorHandler,
|
private val errorHandler: ErrorHandler,
|
||||||
private val schedulers: SchedulersProvider,
|
private val schedulers: SchedulersProvider,
|
||||||
private val gradeRepository: GradeRepository,
|
private val gradeRepository: GradeRepository,
|
||||||
private val sessionRepository: SessionRepository
|
private val sessionRepository: SessionRepository,
|
||||||
|
private val preferencesRepository: PreferencesRepository
|
||||||
) : BasePresenter<GradeDetailsView>(errorHandler) {
|
) : BasePresenter<GradeDetailsView>(errorHandler) {
|
||||||
|
|
||||||
override fun onAttachView(view: GradeDetailsView) {
|
override fun onAttachView(view: GradeDetailsView) {
|
||||||
@ -28,6 +31,7 @@ class GradeDetailsPresenter @Inject constructor(
|
|||||||
fun onParentViewLoadData(semesterId: Int, forceRefresh: Boolean) {
|
fun onParentViewLoadData(semesterId: Int, forceRefresh: Boolean) {
|
||||||
disposable.add(sessionRepository.getSemesters()
|
disposable.add(sessionRepository.getSemesters()
|
||||||
.flatMap { gradeRepository.getGrades(it.first { item -> item.semesterId == semesterId }, forceRefresh) }
|
.flatMap { gradeRepository.getGrades(it.first { item -> item.semesterId == semesterId }, forceRefresh) }
|
||||||
|
.map { it.map { item -> item.changeModifier(preferencesRepository.gradeModifier) } }
|
||||||
.map { createGradeItems(it.groupBy { grade -> grade.subject }.toSortedMap()) }
|
.map { createGradeItems(it.groupBy { grade -> grade.subject }.toSortedMap()) }
|
||||||
.subscribeOn(schedulers.backgroundThread)
|
.subscribeOn(schedulers.backgroundThread)
|
||||||
.observeOn(schedulers.mainThread)
|
.observeOn(schedulers.mainThread)
|
||||||
|
@ -4,10 +4,12 @@ import io.github.wulkanowy.data.ErrorHandler
|
|||||||
import io.github.wulkanowy.data.db.entities.GradeSummary
|
import io.github.wulkanowy.data.db.entities.GradeSummary
|
||||||
import io.github.wulkanowy.data.repositories.GradeRepository
|
import io.github.wulkanowy.data.repositories.GradeRepository
|
||||||
import io.github.wulkanowy.data.repositories.GradeSummaryRepository
|
import io.github.wulkanowy.data.repositories.GradeSummaryRepository
|
||||||
|
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||||
import io.github.wulkanowy.data.repositories.SessionRepository
|
import io.github.wulkanowy.data.repositories.SessionRepository
|
||||||
import io.github.wulkanowy.ui.base.BasePresenter
|
import io.github.wulkanowy.ui.base.BasePresenter
|
||||||
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.logEvent
|
import io.github.wulkanowy.utils.logEvent
|
||||||
import java.lang.String.format
|
import java.lang.String.format
|
||||||
import java.util.Locale.FRANCE
|
import java.util.Locale.FRANCE
|
||||||
@ -18,6 +20,7 @@ class GradeSummaryPresenter @Inject constructor(
|
|||||||
private val gradeSummaryRepository: GradeSummaryRepository,
|
private val gradeSummaryRepository: GradeSummaryRepository,
|
||||||
private val gradeRepository: GradeRepository,
|
private val gradeRepository: GradeRepository,
|
||||||
private val sessionRepository: SessionRepository,
|
private val sessionRepository: SessionRepository,
|
||||||
|
private val preferencesRepository: PreferencesRepository,
|
||||||
private val schedulers: SchedulersProvider
|
private val schedulers: SchedulersProvider
|
||||||
) : BasePresenter<GradeSummaryView>(errorHandler) {
|
) : BasePresenter<GradeSummaryView>(errorHandler) {
|
||||||
|
|
||||||
@ -34,7 +37,8 @@ class GradeSummaryPresenter @Inject constructor(
|
|||||||
.flatMap { gradesSummary ->
|
.flatMap { gradesSummary ->
|
||||||
gradeRepository.getGrades(it, forceRefresh)
|
gradeRepository.getGrades(it, forceRefresh)
|
||||||
.map { grades ->
|
.map { grades ->
|
||||||
grades.groupBy { grade -> grade.subject }
|
grades.map { item -> item.changeModifier(preferencesRepository.gradeModifier) }
|
||||||
|
.groupBy { grade -> grade.subject }
|
||||||
.mapValues { entry -> entry.value.calcAverage() }
|
.mapValues { entry -> entry.value.calcAverage() }
|
||||||
.filterValues { value -> value != 0.0 }
|
.filterValues { value -> value != 0.0 }
|
||||||
.let { averages ->
|
.let { averages ->
|
||||||
|
@ -33,7 +33,6 @@ inline val Grade.valueColor: Int
|
|||||||
1 -> R.color.grade_one
|
1 -> R.color.grade_one
|
||||||
else -> R.color.grade_default
|
else -> R.color.grade_default
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline val Grade.colorStringId: Int
|
inline val Grade.colorStringId: Int
|
||||||
@ -46,4 +45,11 @@ inline val Grade.colorStringId: Int
|
|||||||
"B16CF1" -> R.string.all_purple
|
"B16CF1" -> R.string.all_purple
|
||||||
else -> R.string.all_empty_color
|
else -> R.string.all_empty_color
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Grade.changeModifier(newModifier: Double): Grade {
|
||||||
|
if (modifier != 0.0 && newModifier != 0.0) {
|
||||||
|
modifier = if (modifier > 0) newModifier else -newModifier
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
@ -134,6 +134,7 @@
|
|||||||
<string name="pref_view_summary">Pokazuj podsumowanie w ocenach</string>
|
<string name="pref_view_summary">Pokazuj podsumowanie w ocenach</string>
|
||||||
<string name="pref_view_present">Pokazuj obecność we frekwencji</string>
|
<string name="pref_view_present">Pokazuj obecność we frekwencji</string>
|
||||||
<string name="pref_view_theme_dark">Ciemny motyw (Beta)</string>
|
<string name="pref_view_theme_dark">Ciemny motyw (Beta)</string>
|
||||||
|
<string name="pref_view_grade_modifier">Wartość plusa i minusa</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>
|
||||||
|
@ -15,4 +15,10 @@
|
|||||||
<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">
|
||||||
|
<item>Domyślna</item>
|
||||||
|
<item>0,25</item>
|
||||||
|
<item>0,33</item>
|
||||||
|
<item>0,5</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -7,4 +7,5 @@
|
|||||||
<string name="pref_key_services_interval">services_interval</string>
|
<string name="pref_key_services_interval">services_interval</string>
|
||||||
<string name="pref_key_services_wifi_only">services_disable_wifi_only</string>
|
<string name="pref_key_services_wifi_only">services_disable_wifi_only</string>
|
||||||
<string name="pref_key_notifications_enable">notifications_enable</string>
|
<string name="pref_key_notifications_enable">notifications_enable</string>
|
||||||
|
<string name="pref_key_grade_modifier">grade_modifier</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -127,6 +127,7 @@
|
|||||||
<string name="pref_view_summary">Show the summary in the grades</string>
|
<string name="pref_view_summary">Show the summary in the grades</string>
|
||||||
<string name="pref_view_present">Show presence in attendance</string>
|
<string name="pref_view_present">Show presence in attendance</string>
|
||||||
<string name="pref_view_theme_dark">Dark theme (Beta)</string>
|
<string name="pref_view_theme_dark">Dark theme (Beta)</string>
|
||||||
|
<string name="pref_view_grade_modifier">Value of the plus and minus</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>
|
||||||
|
@ -44,4 +44,17 @@
|
|||||||
<item>720</item>
|
<item>720</item>
|
||||||
<item>1440</item>
|
<item>1440</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="grade_modifier_entries">
|
||||||
|
<item>Default</item>
|
||||||
|
<item>0,25</item>
|
||||||
|
<item>0,33</item>
|
||||||
|
<item>0,5</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="grade_modifier_value" translatable="false">
|
||||||
|
<item>0.0</item>
|
||||||
|
<item>0.25</item>
|
||||||
|
<item>0.33</item>
|
||||||
|
<item>0.5</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -25,6 +25,14 @@
|
|||||||
android:key="@string/pref_key_attendance_present"
|
android:key="@string/pref_key_attendance_present"
|
||||||
android:title="@string/pref_view_present"
|
android:title="@string/pref_view_present"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="0.0"
|
||||||
|
android:entries="@array/grade_modifier_entries"
|
||||||
|
android:entryValues="@array/grade_modifier_value"
|
||||||
|
android:key="@string/pref_key_grade_modifier"
|
||||||
|
android:summary="%s"
|
||||||
|
android:title="@string/pref_view_grade_modifier"
|
||||||
|
app:iconSpaceReserved="false" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/pref_services_header"
|
android:title="@string/pref_services_header"
|
||||||
|
@ -13,31 +13,45 @@ class GradeExtensionTest {
|
|||||||
fun calcWeightedAverage() {
|
fun calcWeightedAverage() {
|
||||||
val localDate = mock(LocalDate::class.java)
|
val localDate = mock(LocalDate::class.java)
|
||||||
assertEquals(3.47, listOf(
|
assertEquals(3.47, listOf(
|
||||||
Grade(1, 1, "", "", 5, 0.33
|
Grade(1, 1, "", "", 5, 0.33
|
||||||
, "", "", "", "", "",
|
, "", "", "", "", "",
|
||||||
6, localDate, ""),
|
6, localDate, ""),
|
||||||
Grade(1, 1, "", "", 5, -0.33
|
Grade(1, 1, "", "", 5, -0.33
|
||||||
, "", "", "", "", "",
|
, "", "", "", "", "",
|
||||||
5, localDate, ""),
|
5, localDate, ""),
|
||||||
Grade(1, 1, "", "", 4, 0.0
|
Grade(1, 1, "", "", 4, 0.0
|
||||||
, "", "", "", "", "",
|
, "", "", "", "", "",
|
||||||
1, localDate, ""),
|
1, localDate, ""),
|
||||||
Grade(1, 1, "", "", 1, 0.5
|
Grade(1, 1, "", "", 1, 0.5
|
||||||
, "", "", "", "", "",
|
, "", "", "", "", "",
|
||||||
9, localDate, ""),
|
9, localDate, ""),
|
||||||
Grade(1, 1, "", "", 0, 0.0
|
Grade(1, 1, "", "", 0, 0.0
|
||||||
, "", "", "", "", "",
|
, "", "", "", "", "",
|
||||||
0, localDate, "")
|
0, localDate, "")
|
||||||
).calcAverage(), 0.005)
|
).calcAverage(), 0.005)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun calcSummaryAverage() {
|
fun calcSummaryAverage() {
|
||||||
assertEquals(2.5, listOf(
|
assertEquals(2.5, listOf(
|
||||||
GradeSummary(1, 1, "", "", "5"),
|
GradeSummary(1, 1, "", "", "5"),
|
||||||
GradeSummary(1, 1, "", "", "-5"),
|
GradeSummary(1, 1, "", "", "-5"),
|
||||||
GradeSummary(1, 1, "", "", "test"),
|
GradeSummary(1, 1, "", "", "test"),
|
||||||
GradeSummary(1, 1, "", "", "0")
|
GradeSummary(1, 1, "", "", "0")
|
||||||
).calcAverage(), 0.005)
|
).calcAverage(), 0.005)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun changeModifierTest() {
|
||||||
|
val localDate = mock(LocalDate::class.java)
|
||||||
|
assertEquals(0.33, Grade(1, 1, "", "", 5, 0.25
|
||||||
|
, "", "", "", "", "",
|
||||||
|
6, localDate, "").changeModifier(0.33).modifier, 0.0)
|
||||||
|
assertEquals(-0.33, Grade(1, 1, "", "", 5, -0.25
|
||||||
|
, "", "", "", "", "",
|
||||||
|
6, localDate, "").changeModifier(0.33).modifier, 0.0)
|
||||||
|
assertEquals(0.25, Grade(1, 1, "", "", 5, 0.25
|
||||||
|
, "", "", "", "", "",
|
||||||
|
6, localDate, "").changeModifier(0.0).modifier, 0.0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user