1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-20 04:39:09 -05:00

Add option to hide/show chart list in grade class stats (#807)

This commit is contained in:
Mikołaj Pich 2020-05-16 22:21:14 +02:00 committed by GitHub
parent f7b5b9c413
commit 0b75635ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 39 additions and 30 deletions

View File

@ -26,6 +26,9 @@ class PreferencesRepository @Inject constructor(
val isGradeExpandable: Boolean
get() = !getBoolean(R.string.pref_key_expand_grade, R.bool.pref_default_expand_grade)
val showAllSubjectsOnStatisticsList: Boolean
get() = getBoolean(R.string.pref_key_grade_statistics_list, R.bool.pref_default_grade_statistics_list)
val appThemeKey = context.getString(R.string.pref_key_app_theme)
val appTheme: String
get() = getString(appThemeKey, R.string.pref_default_app_theme)

View File

@ -32,6 +32,8 @@ class GradeStatisticsAdapter @Inject constructor() :
var theme: String = "vulcan"
var showAllSubjectsOnList: Boolean = false
private val vulcanGradeColors = listOf(
6 to R.color.grade_vulcan_six,
5 to R.color.grade_vulcan_five,
@ -59,7 +61,7 @@ class GradeStatisticsAdapter @Inject constructor() :
"6, 6-", "5, 5-, 5+", "4, 4-, 4+", "3, 3-, 3+", "2, 2-, 2+", "1, 1+"
)
override fun getItemCount() = items.size
override fun getItemCount() = if (showAllSubjectsOnList) items.size else (if (items.isEmpty()) 0 else 1)
override fun getItemViewType(position: Int) = items[position].type.id
@ -82,7 +84,7 @@ class GradeStatisticsAdapter @Inject constructor() :
private fun bindPieChart(holder: PieViewHolder, partials: List<GradeStatistics>) {
with(holder.binding.gradeStatisticsPieTitle) {
text = partials.firstOrNull()?.subject
visibility = if (items.size == 1) GONE else VISIBLE
visibility = if (items.size == 1 || !showAllSubjectsOnList) GONE else VISIBLE
}
val gradeColors = when (theme) {

View File

@ -80,17 +80,17 @@ class GradeStatisticsFragment :
}
}
override fun updateData(items: List<GradeStatisticsItem>, theme: String) {
statisticsAdapter.theme = theme
statisticsAdapter.items = items
statisticsAdapter.notifyDataSetChanged()
override fun updateData(items: List<GradeStatisticsItem>, theme: String, showAllSubjectsOnStatisticsList: Boolean) {
with(statisticsAdapter) {
this.showAllSubjectsOnList = showAllSubjectsOnStatisticsList
this.theme = theme
this.items = items
notifyDataSetChanged()
}
}
override fun showSubjects(show: Boolean) {
with(binding) {
gradeStatisticsSubjectsContainer.visibility = if (show) View.VISIBLE else View.INVISIBLE
gradeStatisticsTypeSwitch.visibility = if (show) View.VISIBLE else View.INVISIBLE
}
binding.gradeStatisticsSubjectsContainer.visibility = if (show) View.VISIBLE else View.GONE
}
override fun clearView() {

View File

@ -128,10 +128,7 @@ class GradeStatisticsPresenter @Inject constructor(
.observeOn(schedulers.mainThread)
.subscribe({
Timber.i("Loading grade stats subjects result: Success")
view?.run {
updateSubjects(it)
showSubjects(true)
}
view?.updateSubjects(it)
}, {
Timber.i("Loading grade stats subjects result: An exception occurred")
errorHandler.dispatch(it)
@ -140,22 +137,21 @@ class GradeStatisticsPresenter @Inject constructor(
}
private fun loadDataByType(semesterId: Int, subjectName: String, type: ViewType, forceRefresh: Boolean = false) {
currentSubjectName = subjectName
currentSubjectName = if (preferencesRepository.showAllSubjectsOnStatisticsList) "Wszystkie" else subjectName
currentType = type
loadData(semesterId, subjectName, type, forceRefresh)
}
private fun loadData(semesterId: Int, subjectName: String, type: ViewType, forceRefresh: Boolean) {
Timber.i("Loading grade stats data started")
disposable.add(studentRepository.getCurrentStudent()
.flatMap { student ->
semesterRepository.getSemesters(student).flatMap { semesters ->
val semester = semesters.first { item -> item.semesterId == semesterId }
when (type) {
ViewType.SEMESTER -> gradeStatisticsRepository.getGradesStatistics(student, semester, subjectName, true, forceRefresh)
ViewType.PARTIAL -> gradeStatisticsRepository.getGradesStatistics(student, semester, subjectName, false, forceRefresh)
ViewType.POINTS -> gradeStatisticsRepository.getGradesPointsStatistics(student, semester, subjectName, forceRefresh)
with(gradeStatisticsRepository) {
when (type) {
ViewType.SEMESTER -> getGradesStatistics(student, semester, currentSubjectName, true, forceRefresh)
ViewType.PARTIAL -> getGradesStatistics(student, semester, currentSubjectName, false, forceRefresh)
ViewType.POINTS -> getGradesPointsStatistics(student, semester, currentSubjectName, forceRefresh)
}
}
}
}
@ -175,7 +171,8 @@ class GradeStatisticsPresenter @Inject constructor(
showEmpty(it.isEmpty())
showContent(it.isNotEmpty())
showErrorView(false)
updateData(it, preferencesRepository.gradeColorTheme)
updateData(it, preferencesRepository.gradeColorTheme, preferencesRepository.showAllSubjectsOnStatisticsList)
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
}
analytics.logEvent("load_grade_statistics", "items" to it.size, "force_refresh" to forceRefresh)
}) {

View File

@ -13,7 +13,7 @@ interface GradeStatisticsView : BaseView {
fun updateSubjects(data: ArrayList<String>)
fun updateData(items: List<GradeStatisticsItem>, theme: String)
fun updateData(items: List<GradeStatisticsItem>, theme: String, showAllSubjectsOnStatisticsList: Boolean)
fun showSubjects(show: Boolean)

View File

@ -12,7 +12,7 @@
android:layout_height="wrap_content"
android:background="?android:windowBackground"
android:padding="5dp"
android:visibility="invisible"
android:visibility="gone"
tools:ignore="UnusedAttribute"
tools:listitem="@layout/item_attendance_summary"
tools:visibility="visible">
@ -59,9 +59,7 @@
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingTop="5dp"
android:paddingEnd="16dp"
android:visibility="invisible"
tools:visibility="visible">
android:paddingEnd="16dp">
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/gradeStatisticsTypePartial"

View File

@ -312,6 +312,7 @@
<string name="pref_view_present">Pokazuj obecność we frekwencji</string>
<string name="pref_view_app_theme">Motyw aplikacji</string>
<string name="pref_view_expand_grade">Rozwiń oceny</string>
<string name="pref_view_grade_statistics_list">Pokazuj listę wykresów w ocenach klasy</string>
<string name="pref_view_timetable_show_whole_class">Pokazuj lekcje całej klasy</string>
<string name="pref_view_grade_color_scheme">Schemat kolorów ocen</string>
<string name="pref_view_app_language">Język aplikacji</string>

View File

@ -5,6 +5,7 @@
<string name="pref_default_grade_average_mode">only_one_semester</string>
<bool name="pref_default_grade_average_force_calc">false</bool>
<bool name="pref_default_expand_grade">false</bool>
<bool name="pref_default_grade_statistics_list">false</bool>
<string name="pref_default_app_theme">light</string>
<string name="pref_default_grade_color_scheme">vulcan</string>
<string name="pref_default_app_language">system</string>

View File

@ -7,6 +7,7 @@
<string name="pref_key_expand_grade">expand_grade</string>
<string name="pref_key_grade_average_mode">grade_average_mode</string>
<string name="pref_key_grade_average_force_calc">grade_average_always_calc</string>
<string name="pref_key_grade_statistics_list">grade_statistics_list</string>
<string name="pref_key_app_language">app_language</string>
<string name="pref_key_services_enable">services_enable</string>
<string name="pref_key_services_interval">services_interval</string>

View File

@ -347,6 +347,7 @@
<string name="pref_view_present">Show presence in attendance</string>
<string name="pref_view_app_theme">Application theme</string>
<string name="pref_view_expand_grade">Expand grades</string>
<string name="pref_view_grade_statistics_list">Show chart list in class grades</string>
<string name="pref_view_timetable_show_whole_class">Show whole class lessons</string>
<string name="pref_view_grade_color_scheme">Grades color scheme</string>
<string name="pref_view_app_language">App language</string>

View File

@ -29,6 +29,11 @@
app:iconSpaceReserved="false"
app:key="@string/pref_key_expand_grade"
app:title="@string/pref_view_expand_grade" />
<SwitchPreferenceCompat
app:defaultValue="@bool/pref_default_grade_statistics_list"
app:iconSpaceReserved="false"
app:key="@string/pref_key_grade_statistics_list"
app:title="@string/pref_view_grade_statistics_list"/>
<ListPreference
app:defaultValue="@string/pref_default_timetable_show_whole_class"
app:entries="@array/timetable_show_whole_class_entries"
@ -79,8 +84,8 @@
app:title="@string/pref_services_wifi" />
<Preference
app:iconSpaceReserved="false"
app:title="@string/pref_services_force_sync"
app:key="@string/pref_key_services_force_sync" />
app:key="@string/pref_key_services_force_sync"
app:title="@string/pref_services_force_sync" />
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"