add: hiding grades, notes and attendance entries

This commit is contained in:
sadorowo 2024-03-21 23:21:06 +01:00
parent d17614fa64
commit 92bad9d112
25 changed files with 156 additions and 248 deletions

View File

@ -1,7 +1,7 @@
[*] [*]
charset=utf-8 charset=utf-8
end_of_line=lf end_of_line=lf
insert_final_newline=true insert_final_newline=Advanced
indent_style=space indent_style=space
indent_size=4 indent_size=4

View File

@ -3,6 +3,7 @@ package io.github.wulkanowy.data.db.dao
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Query import androidx.room.Query
import io.github.wulkanowy.data.db.entities.Attendance import io.github.wulkanowy.data.db.entities.Attendance
import io.github.wulkanowy.ui.modules.dashboard.DashboardItem
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import java.time.LocalDate import java.time.LocalDate
import javax.inject.Singleton import javax.inject.Singleton
@ -18,12 +19,4 @@ interface AttendanceDao : BaseDao<Attendance> {
start: LocalDate, start: LocalDate,
end: LocalDate end: LocalDate
): Flow<List<Attendance>> ): Flow<List<Attendance>>
@Query("SELECT * FROM Attendance WHERE diary_id = :diaryId AND student_id = :studentId AND date >= :start AND date <= :end AND (presence OR excused)")
fun loadAllCensored(
diaryId: Int,
studentId: Int,
start: LocalDate,
end: LocalDate
): Flow<List<Attendance>>
} }

View File

@ -11,7 +11,4 @@ import javax.inject.Singleton
interface NoteDao : BaseDao<Note> { interface NoteDao : BaseDao<Note> {
@Query("SELECT * FROM Notes WHERE student_id = :studentId") @Query("SELECT * FROM Notes WHERE student_id = :studentId")
fun loadAll(studentId: Int): Flow<List<Note>> fun loadAll(studentId: Int): Flow<List<Note>>
@Query("SELECT * FROM Notes WHERE student_id = :studentId AND 1 != 1")
fun pretendLoadingAll(studentId: Int): Flow<List<Note>>
} }

View File

@ -9,6 +9,7 @@ import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.mappers.mapToEntities import io.github.wulkanowy.data.mappers.mapToEntities
import io.github.wulkanowy.data.networkBoundResource import io.github.wulkanowy.data.networkBoundResource
import io.github.wulkanowy.sdk.pojo.Absent import io.github.wulkanowy.sdk.pojo.Absent
import io.github.wulkanowy.sdk.pojo.Attendance as SdkAttendance
import io.github.wulkanowy.ui.modules.dashboard.DashboardItem import io.github.wulkanowy.ui.modules.dashboard.DashboardItem
import io.github.wulkanowy.utils.AutoRefreshHelper import io.github.wulkanowy.utils.AutoRefreshHelper
import io.github.wulkanowy.utils.getRefreshKey import io.github.wulkanowy.utils.getRefreshKey
@ -16,6 +17,7 @@ import io.github.wulkanowy.utils.monday
import io.github.wulkanowy.utils.sunday import io.github.wulkanowy.utils.sunday
import io.github.wulkanowy.utils.uniqueSubtract import io.github.wulkanowy.utils.uniqueSubtract
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import java.time.LocalDate import java.time.LocalDate
import java.time.LocalDateTime import java.time.LocalDateTime
@ -36,6 +38,64 @@ class AttendanceRepository @Inject constructor(
private val cacheKey = "attendance" private val cacheKey = "attendance"
private fun filterAttendance(
hiddenAttendanceTiles: List<DashboardItem.HiddenAttendanceTile>,
attendanceItem: Attendance
): Boolean {
return when {
attendanceItem.absence && attendanceItem.excused && hiddenAttendanceTiles.contains(
DashboardItem.HiddenAttendanceTile.EXCUSED_ABSENCE
) -> false
attendanceItem.absence && !attendanceItem.excused && hiddenAttendanceTiles.contains(
DashboardItem.HiddenAttendanceTile.UNEXCUSED_ABSENCE
) -> false
attendanceItem.lateness && attendanceItem.excused && hiddenAttendanceTiles.contains(
DashboardItem.HiddenAttendanceTile.EXCUSED_LATENESS
) -> false
attendanceItem.lateness && !attendanceItem.excused && hiddenAttendanceTiles.contains(
DashboardItem.HiddenAttendanceTile.UNEXCUSED_LATENESS
) -> false
attendanceItem.exemption && hiddenAttendanceTiles.contains(DashboardItem.HiddenAttendanceTile.EXEMPTION) -> false
attendanceItem.deleted && hiddenAttendanceTiles.contains(DashboardItem.HiddenAttendanceTile.DELETED) -> false
attendanceItem.presence && hiddenAttendanceTiles.contains(DashboardItem.HiddenAttendanceTile.PRESENT) -> false
else -> !hiddenAttendanceTiles.contains(DashboardItem.HiddenAttendanceTile.UNKNOWN)
}
}
private fun filterAttendance(
hiddenAttendanceTiles: List<DashboardItem.HiddenAttendanceTile>,
attendanceItem: SdkAttendance
): Boolean {
return when {
attendanceItem.absence && attendanceItem.excused && hiddenAttendanceTiles.contains(
DashboardItem.HiddenAttendanceTile.EXCUSED_ABSENCE
) -> false
attendanceItem.absence && !attendanceItem.excused && hiddenAttendanceTiles.contains(
DashboardItem.HiddenAttendanceTile.UNEXCUSED_ABSENCE
) -> false
attendanceItem.lateness && attendanceItem.excused && hiddenAttendanceTiles.contains(
DashboardItem.HiddenAttendanceTile.EXCUSED_LATENESS
) -> false
attendanceItem.lateness && !attendanceItem.excused && hiddenAttendanceTiles.contains(
DashboardItem.HiddenAttendanceTile.UNEXCUSED_LATENESS
) -> false
attendanceItem.exemption && hiddenAttendanceTiles.contains(DashboardItem.HiddenAttendanceTile.EXEMPTION) -> false
attendanceItem.deleted && hiddenAttendanceTiles.contains(DashboardItem.HiddenAttendanceTile.DELETED) -> false
attendanceItem.presence && hiddenAttendanceTiles.contains(DashboardItem.HiddenAttendanceTile.PRESENT) -> false
else -> !hiddenAttendanceTiles.contains(DashboardItem.HiddenAttendanceTile.UNKNOWN)
}
}
fun getAttendance( fun getAttendance(
student: Student, student: Student,
semester: Semester, semester: Semester,
@ -53,30 +113,16 @@ class AttendanceRepository @Inject constructor(
it.isEmpty() || forceRefresh || isExpired it.isEmpty() || forceRefresh || isExpired
}, },
query = { query = {
val badAttendanceHidden = preferencesRepository val hiddenAttendanceItems = preferencesRepository.hiddenAttendanceItems
.selectedHiddenSettingTiles
.contains(DashboardItem.HiddenSettingTile.NOTES)
if (badAttendanceHidden) { attendanceDb
attendanceDb.loadAllCensored( .loadAll(semester.diaryId, semester.studentId, start.monday, end.sunday)
semester.diaryId, .map {
semester.studentId, it.filter { item -> filterAttendance(hiddenAttendanceItems, item) }
start.monday, }
end.sunday
)
} else {
attendanceDb.loadAll(
semester.diaryId,
semester.studentId,
start.monday,
end.sunday
)
}
}, },
fetch = { fetch = {
val badAttendanceHidden = preferencesRepository val hiddenAttendanceItems = preferencesRepository.hiddenAttendanceItems
.selectedHiddenSettingTiles
.contains(DashboardItem.HiddenSettingTile.NOTES)
val lessons = timetableDb.load( val lessons = timetableDb.load(
semester.diaryId, semester.studentId, start.monday, end.sunday semester.diaryId, semester.studentId, start.monday, end.sunday
@ -84,7 +130,7 @@ class AttendanceRepository @Inject constructor(
wulkanowySdkFactory.create(student, semester) wulkanowySdkFactory.create(student, semester)
.getAttendance(start.monday, end.sunday) .getAttendance(start.monday, end.sunday)
.filter { !badAttendanceHidden || (it.presence || it.excused) } .filter { item -> filterAttendance(hiddenAttendanceItems, item) }
.mapToEntities(semester, lessons) .mapToEntities(semester, lessons)
}, },
saveFetchResult = { old, new -> saveFetchResult = { old, new ->
@ -105,15 +151,13 @@ class AttendanceRepository @Inject constructor(
start: LocalDate, start: LocalDate,
end: LocalDate end: LocalDate
): Flow<List<Attendance>> { ): Flow<List<Attendance>> {
val badAttendanceHidden = preferencesRepository val hiddenAttendanceItems = preferencesRepository.hiddenAttendanceItems
.selectedHiddenSettingTiles
.contains(DashboardItem.HiddenSettingTile.BAD_ATTENDANCE)
return if (badAttendanceHidden) { return attendanceDb
attendanceDb.loadAllCensored(semester.diaryId, semester.studentId, start, end) .loadAll(semester.diaryId, semester.studentId, start.monday, end.sunday)
} else { .map {
attendanceDb.loadAll(semester.diaryId, semester.studentId, start, end) it.filter { item -> filterAttendance(hiddenAttendanceItems, item) }
} }
} }
suspend fun updateTimetable(timetable: List<Attendance>) { suspend fun updateTimetable(timetable: List<Attendance>) {

View File

@ -7,7 +7,6 @@ import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.mappers.mapToEntities import io.github.wulkanowy.data.mappers.mapToEntities
import io.github.wulkanowy.data.networkBoundResource import io.github.wulkanowy.data.networkBoundResource
import io.github.wulkanowy.ui.modules.dashboard.DashboardItem
import io.github.wulkanowy.utils.AutoRefreshHelper import io.github.wulkanowy.utils.AutoRefreshHelper
import io.github.wulkanowy.utils.getRefreshKey import io.github.wulkanowy.utils.getRefreshKey
import io.github.wulkanowy.utils.toLocalDate import io.github.wulkanowy.utils.toLocalDate
@ -41,27 +40,16 @@ class NoteRepository @Inject constructor(
val isExpired = refreshHelper.shouldBeRefreshed( val isExpired = refreshHelper.shouldBeRefreshed(
getRefreshKey(cacheKey, semester) getRefreshKey(cacheKey, semester)
) )
it.isEmpty() || forceRefresh || isExpired it.isEmpty() || forceRefresh || isExpired
}, },
query = { query = { noteDb.loadAll(student.studentId) },
val notesHidden = preferencesRepository
.selectedHiddenSettingTiles
.contains(DashboardItem.HiddenSettingTile.NOTES)
if (notesHidden) {
noteDb.pretendLoadingAll(student.studentId)
} else {
noteDb.loadAll(student.studentId)
}
},
fetch = { fetch = {
val notesHidden = preferencesRepository val showNotes = preferencesRepository.showNotes
.selectedHiddenSettingTiles
.contains(DashboardItem.HiddenSettingTile.NOTES)
wulkanowySdkFactory.create(student, semester) wulkanowySdkFactory.create(student, semester)
.getNotes() .getNotes()
.filter { !notesHidden } .filter { showNotes }
.mapToEntities(semester) .mapToEntities(semester)
}, },
saveFetchResult = { old, new -> saveFetchResult = { old, new ->
@ -80,15 +68,7 @@ class NoteRepository @Inject constructor(
) )
fun getNotesFromDatabase(student: Student): Flow<List<Note>> { fun getNotesFromDatabase(student: Student): Flow<List<Note>> {
val notesHidden = preferencesRepository return noteDb.loadAll(student.studentId)
.selectedHiddenSettingTiles
.contains(DashboardItem.HiddenSettingTile.NOTES)
return if (notesHidden) {
noteDb.pretendLoadingAll(student.studentId)
} else {
noteDb.loadAll(student.studentId)
}
} }
suspend fun updateNote(note: Note) { suspend fun updateNote(note: Note) {

View File

@ -2,8 +2,6 @@ package io.github.wulkanowy.data.repositories
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.core.content.edit import androidx.core.content.edit
import com.fredporciuncula.flow.preferences.FlowSharedPreferences import com.fredporciuncula.flow.preferences.FlowSharedPreferences
@ -26,7 +24,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import okhttp3.internal.notifyAll import timber.log.Timber
import java.time.Instant import java.time.Instant
import java.util.UUID import java.util.UUID
import javax.inject.Inject import javax.inject.Inject
@ -39,6 +37,8 @@ class PreferencesRepository @Inject constructor(
private val flowSharedPref: FlowSharedPreferences, private val flowSharedPref: FlowSharedPreferences,
private val json: Json, private val json: Json,
) { ) {
private val NO_ATTENDANCE_VALUE = -1.0
val isShowPresent: Boolean val isShowPresent: Boolean
get() = getBoolean( get() = getBoolean(
R.string.pref_key_attendance_present, R.string.pref_key_attendance_present,
@ -297,28 +297,9 @@ class PreferencesRepository @Inject constructor(
selectedDashboardTilesPreference.set(filteredValue) selectedDashboardTilesPreference.set(filteredValue)
} }
var selectedHiddenSettingTiles: List<DashboardItem.HiddenSettingTile> var attendancePercentage: Double?
get() = selectedHiddenSettingTilesPreference.get() get() = attendancePercentagePreference.get().takeIf { it != NO_ATTENDANCE_VALUE }
.map { DashboardItem.HiddenSettingTile.valueOf(it) } set(value) = attendancePercentagePreference.set(value ?: NO_ATTENDANCE_VALUE)
set(value) {
val filteredValue = value
.map { it.name }
.toSet()
selectedHiddenSettingTilesPreference.set(filteredValue)
}
var attendancePercentage: Float?
get() = getString(
R.string.pref_key_attendance_percentage,
R.string.pref_default_attendance_percentage
).let { if (it.isNullOrEmpty()) null else it.toFloat() }
set(value) = sharedPref.edit {
putString(
context.getString(R.string.pref_key_attendance_percentage),
value?.toString() ?: "-1"
)
}
var hiddenAttendanceItems: List<DashboardItem.HiddenAttendanceTile> var hiddenAttendanceItems: List<DashboardItem.HiddenAttendanceTile>
get() = hiddenAttendanceItemsPreference.get().toList() get() = hiddenAttendanceItemsPreference.get().toList()
@ -328,6 +309,10 @@ class PreferencesRepository @Inject constructor(
get() = hiddenGradesPreference.get().toList() get() = hiddenGradesPreference.get().toList()
set(value) = hiddenGradesPreference.set(value.toSet()) set(value) = hiddenGradesPreference.set(value.toSet())
var showNotes: Boolean
get() = showNotesPreference.get()
set(value) = showNotesPreference.set(value)
private val hiddenGradesPreference: Preference<Set<String>> private val hiddenGradesPreference: Preference<Set<String>>
get() { get() {
val defaultSet = context.resources.getStringArray(R.array.pref_default_hidden_grades).toSet() val defaultSet = context.resources.getStringArray(R.array.pref_default_hidden_grades).toSet()
@ -336,11 +321,17 @@ class PreferencesRepository @Inject constructor(
return flowSharedPref.getStringSet(prefKey, defaultSet) return flowSharedPref.getStringSet(prefKey, defaultSet)
} }
private val showNotesPreference: Preference<Boolean>
get() = flowSharedPref.getBoolean(
context.getString(R.string.pref_key_show_notes),
context.resources.getBoolean(R.bool.pref_default_show_notes)
)
private val hiddenAttendanceItemsPreference: Preference<Set<DashboardItem.HiddenAttendanceTile>> private val hiddenAttendanceItemsPreference: Preference<Set<DashboardItem.HiddenAttendanceTile>>
get() { get() {
val defaultSet = val defaultSet =
context.resources.getStringArray(R.array.pref_default_hidden_attendance_items).toSet() context.resources.getStringArray(R.array.pref_default_hidden_attendance_items).toSet()
val prefKey = "hidden_attendance_items" val prefKey = "attendance_items"
return flowSharedPref return flowSharedPref
.getStringSet(prefKey, defaultSet) .getStringSet(prefKey, defaultSet)
@ -359,21 +350,19 @@ class PreferencesRepository @Inject constructor(
return flowSharedPref.getStringSet(prefKey, defaultSet) return flowSharedPref.getStringSet(prefKey, defaultSet)
} }
private val selectedHiddenSettingTilesPreference: Preference<Set<String>> private val attendancePercentagePreference: Preference<Double>
get() { get() {
val defaultSet = val prefKey = context.getString(R.string.pref_key_attendance_percentage)
context.resources.getStringArray(R.array.pref_default_hidden_settings_tiles).toSet() val defaultValue = context.resources.getString(R.string.pref_default_attendance_percentage)
val prefKey = "hidden_settings_tiles"
return flowSharedPref.getStringSet(prefKey, defaultSet) return flowSharedPref
.getString(prefKey, defaultValue)
.map(
mapper = { it.toDoubleOrNull() ?: NO_ATTENDANCE_VALUE },
reverse = { it.toString() }
)
} }
private val attendancePercentagePreference: Preference<Float>
get() = flowSharedPref.getFloat(
context.getString(R.string.pref_key_attendance_percentage),
context.resources.getInteger(R.integer.pref_default_attendance_percentage).toFloat()
)
var dismissedAdminMessageIds: List<Int> var dismissedAdminMessageIds: List<Int>
get() = sharedPref.getStringSet(PREF_KEY_ADMIN_DISMISSED_MESSAGE_IDS, emptySet()) get() = sharedPref.getStringSet(PREF_KEY_ADMIN_DISMISSED_MESSAGE_IDS, emptySet())
.orEmpty() .orEmpty()

View File

@ -54,7 +54,7 @@ class AttendanceSummaryAdapter @Inject constructor(
private fun bindHeaderViewHolder(binding: ScrollableHeaderAttendanceSummaryBinding) { private fun bindHeaderViewHolder(binding: ScrollableHeaderAttendanceSummaryBinding) {
binding.attendanceSummaryScrollableHeaderPercentage.text = formatPercentage( binding.attendanceSummaryScrollableHeaderPercentage.text = formatPercentage(
attendancePercentage?.toDouble() ?: attendancePercentage ?:
items.calculatePercentage() items.calculatePercentage()
) )
} }
@ -68,8 +68,8 @@ class AttendanceSummaryAdapter @Inject constructor(
else -> item.month.getFormattedName() else -> item.month.getFormattedName()
} }
attendanceSummaryPercentage.text = when (position) { attendanceSummaryPercentage.text = when (position) {
-1 -> formatPercentage(attendancePercentage?.toDouble() ?: item.calculatePercentage()) -1 -> formatPercentage(attendancePercentage ?: item.calculatePercentage())
else -> formatPercentage(attendancePercentage?.toDouble() ?: item.calculatePercentage()) else -> formatPercentage(attendancePercentage ?: item.calculatePercentage())
} }
attendanceSummaryPresent.text = item.presence.toString() attendanceSummaryPresent.text = item.presence.toString()

View File

@ -148,12 +148,6 @@ sealed class DashboardItem(val type: Type) {
CONFERENCES, CONFERENCES,
} }
enum class HiddenSettingTile {
BAD_ATTENDANCE,
NOTES,
ATTENDANCE,
}
enum class HiddenAttendanceTile { enum class HiddenAttendanceTile {
UNEXCUSED_ABSENCE, UNEXCUSED_ABSENCE,
EXEMPTION, EXEMPTION,

View File

@ -338,7 +338,7 @@ class DashboardPresenter @Inject constructor(
} else null } else null
}, },
attendancePercentage = DashboardItem.HorizontalGroup.Cell( attendancePercentage = DashboardItem.HorizontalGroup.Cell(
data = attendancePercentage?.toDouble() ?: attendanceResource.dataOrNull?.calculatePercentage(), data = attendancePercentage ?: attendanceResource.dataOrNull?.calculatePercentage(),
error = attendanceResource.errorOrNull != null, error = attendanceResource.errorOrNull != null,
isLoading = attendanceResource is Resource.Loading, isLoading = attendanceResource is Resource.Loading,
), ),

View File

@ -3,6 +3,7 @@ package io.github.wulkanowy.ui.modules.note
import io.github.wulkanowy.data.* import io.github.wulkanowy.data.*
import io.github.wulkanowy.data.db.entities.Note import io.github.wulkanowy.data.db.entities.Note
import io.github.wulkanowy.data.repositories.NoteRepository import io.github.wulkanowy.data.repositories.NoteRepository
import io.github.wulkanowy.data.repositories.PreferencesRepository
import io.github.wulkanowy.data.repositories.SemesterRepository import io.github.wulkanowy.data.repositories.SemesterRepository
import io.github.wulkanowy.data.repositories.StudentRepository import io.github.wulkanowy.data.repositories.StudentRepository
import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.BasePresenter
@ -17,6 +18,7 @@ class NotePresenter @Inject constructor(
studentRepository: StudentRepository, studentRepository: StudentRepository,
private val noteRepository: NoteRepository, private val noteRepository: NoteRepository,
private val semesterRepository: SemesterRepository, private val semesterRepository: SemesterRepository,
private val preferencesRepository: PreferencesRepository,
private val analytics: AnalyticsHelper private val analytics: AnalyticsHelper
) : BasePresenter<NoteView>(errorHandler, studentRepository) { ) : BasePresenter<NoteView>(errorHandler, studentRepository) {
@ -48,6 +50,19 @@ class NotePresenter @Inject constructor(
} }
private fun loadData(forceRefresh: Boolean = false) { private fun loadData(forceRefresh: Boolean = false) {
if (!preferencesRepository.showNotes) {
view?.run {
enableSwipe(false)
showEmpty(false)
showContent(false)
showErrorView(false)
showProgress(false)
showEmpty(true)
}
return
}
flatResourceFlow { flatResourceFlow {
val student = studentRepository.getCurrentStudent() val student = studentRepository.getCurrentStudent()
val semester = semesterRepository.getCurrentSemester(student) val semester = semesterRepository.getCurrentSemester(student)

View File

@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.View import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
import androidx.preference.MultiSelectListPreference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@ -43,8 +44,8 @@ class ModSettingsFragment : PreferenceFragmentCompat(),
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.scheme_preferences_mod_settings, rootKey) setPreferencesFromResource(R.xml.scheme_preferences_mod_settings, rootKey)
val etp: EditTextPreference? = findPreference("attendance_percentage") val attendancePercentagePreference: EditTextPreference? = findPreference("attendance_percentage")
etp?.setOnBindEditTextListener { editText -> attendancePercentagePreference?.setOnBindEditTextListener { editText ->
editText.inputType = android.text.InputType.TYPE_CLASS_NUMBER or android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL editText.inputType = android.text.InputType.TYPE_CLASS_NUMBER or android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL
editText.filters = arrayOf( editText.filters = arrayOf(
android.text.InputFilter { source, _, _, dest, _, _ -> android.text.InputFilter { source, _, _, dest, _, _ ->
@ -118,25 +119,6 @@ class ModSettingsFragment : PreferenceFragmentCompat(),
preferenceScreen.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) preferenceScreen.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this)
} }
override fun showGradeDialogSettings() {
val hiddenGrades = preferencesRepository.hiddenGrades
val grades = requireContext().resources.getStringArray(R.array.hidden_settings_bad_grades)
val selectedItemsState = grades.map { grade -> hiddenGrades.any { it == grade } }
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.pref_hidden_settings_hidden_grades)
.setMultiChoiceItems(grades, selectedItemsState.toBooleanArray()) { _, _, _ -> }
.setPositiveButton(android.R.string.ok) { dialog, _ ->
val selectedState = (dialog as AlertDialog).listView.checkedItemPositions
val selectedValues = grades.filterIndexed { index, _ -> selectedState[index] }
Timber.i("Selected hidden grades: $selectedValues")
presenter.onHiddenGradesSelected(selectedValues)
}
.show()
}
override fun showAttendanceSettings(items: List<DashboardItem.HiddenAttendanceTile>) { override fun showAttendanceSettings(items: List<DashboardItem.HiddenAttendanceTile>) {
val entries = requireContext().resources.getStringArray(R.array.mod_settings_attendance_entries) val entries = requireContext().resources.getStringArray(R.array.mod_settings_attendance_entries)
val values = requireContext().resources.getStringArray(R.array.mod_settings_attendance_values) val values = requireContext().resources.getStringArray(R.array.mod_settings_attendance_values)

View File

@ -18,6 +18,7 @@ class ModSettingsPresenter @Inject constructor(
override fun onAttachView(view: ModSettingsView) { override fun onAttachView(view: ModSettingsView) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Mod settings view was initialized") Timber.i("Mod settings view was initialized")
} }

View File

@ -5,6 +5,5 @@ import io.github.wulkanowy.ui.modules.dashboard.DashboardItem
interface ModSettingsView : BaseView { interface ModSettingsView : BaseView {
fun restartApp() fun restartApp()
fun showGradeDialogSettings()
fun showAttendanceSettings(items: List<DashboardItem.HiddenAttendanceTile>) fun showAttendanceSettings(items: List<DashboardItem.HiddenAttendanceTile>)
} }

View File

@ -3,10 +3,4 @@
<string name="pref_mod_settings_title">Skrytá nastavení</string> <string name="pref_mod_settings_title">Skrytá nastavení</string>
<string name="pref_hidden_settings_attendance_percentage">Procento docházky</string> <string name="pref_hidden_settings_attendance_percentage">Procento docházky</string>
<string name="pref_hidden_settings_hidden_grades">Skrýt známky</string> <string name="pref_hidden_settings_hidden_grades">Skrýt známky</string>
<string-array name="hidden_settings_entries">
<item>Špatná účast</item>
<item>Poznámky</item>
<item>Falešná účast</item>
</string-array>
</resources> </resources>

View File

@ -3,10 +3,4 @@
<string name="pref_mod_settings_title">Hidden settings</string> <string name="pref_mod_settings_title">Hidden settings</string>
<string name="pref_hidden_settings_attendance_percentage">Attendance percentage</string> <string name="pref_hidden_settings_attendance_percentage">Attendance percentage</string>
<string name="pref_hidden_settings_hidden_grades">Hide grades</string> <string name="pref_hidden_settings_hidden_grades">Hide grades</string>
<string-array name="hidden_settings_entries">
<item>Bad attendance</item>
<item>Notes</item>
<item>Fake attendance</item>
</string-array>
</resources> </resources>

View File

@ -3,10 +3,4 @@
<string name="pref_mod_settings_title">Geheime Einstellungen</string> <string name="pref_mod_settings_title">Geheime Einstellungen</string>
<string name="pref_hidden_settings_attendance_percentage">Prozentuale Erwartung</string> <string name="pref_hidden_settings_attendance_percentage">Prozentuale Erwartung</string>
<string name="pref_hidden_settings_hidden_grades">Hide Grades</string> <string name="pref_hidden_settings_hidden_grades">Hide Grades</string>
<string-array name="hidden_settings_entries">
<item>Schlechte Anwesenheit</item>
<item>Notizen</item>
<item>Vorgetäuschte 100-prozentige Anwesenheit</item>
</string-array>
</resources> </resources>

View File

@ -3,10 +3,4 @@
<string name="pref_mod_settings_title">Hidden settings</string> <string name="pref_mod_settings_title">Hidden settings</string>
<string name="pref_hidden_settings_attendance_percentage">Attendance percentage</string> <string name="pref_hidden_settings_attendance_percentage">Attendance percentage</string>
<string name="pref_hidden_settings_hidden_grades">Hide grades</string> <string name="pref_hidden_settings_hidden_grades">Hide grades</string>
<string-array name="hidden_settings_entries">
<item>Bad attendance</item>
<item>Notes</item>
<item>Fake attendance</item>
</string-array>
</resources> </resources>

View File

@ -3,10 +3,4 @@
<string name="pref_mod_settings_title">Hidden settings</string> <string name="pref_mod_settings_title">Hidden settings</string>
<string name="pref_hidden_settings_attendance_percentage">Attendance percentage</string> <string name="pref_hidden_settings_attendance_percentage">Attendance percentage</string>
<string name="pref_hidden_settings_hidden_grades">Hide grades</string> <string name="pref_hidden_settings_hidden_grades">Hide grades</string>
<string-array name="hidden_settings_entries">
<item>Bad attendance</item>
<item>Notes</item>
<item>Fake attendance</item>
</string-array>
</resources> </resources>

View File

@ -3,10 +3,4 @@
<string name="pref_mod_settings_title">Sekretne ustawienia</string> <string name="pref_mod_settings_title">Sekretne ustawienia</string>
<string name="pref_hidden_settings_attendance_percentage">Procent frekwencji</string> <string name="pref_hidden_settings_attendance_percentage">Procent frekwencji</string>
<string name="pref_hidden_settings_hidden_grades">Ukryj oceny</string> <string name="pref_hidden_settings_hidden_grades">Ukryj oceny</string>
<string-array name="hidden_settings_entries">
<item>Słaba frekwencja</item>
<item>Uwagi</item>
<item>Fałszywa frekwencja</item>
</string-array>
</resources> </resources>

View File

@ -3,10 +3,4 @@
<string name="pref_mod_settings_title">Секретные настройки</string> <string name="pref_mod_settings_title">Секретные настройки</string>
<string name="pref_hidden_settings_attendance_percentage">Процент посещаемости</string> <string name="pref_hidden_settings_attendance_percentage">Процент посещаемости</string>
<string name="pref_hidden_settings_hidden_grades">Скрыть оценки</string> <string name="pref_hidden_settings_hidden_grades">Скрыть оценки</string>
<string-array name="hidden_settings_entries">
<item>Плохая посещаемость</item>
<item>Примечания</item>
<item>Фейковая посещаемость</item>
</string-array>
</resources> </resources>

View File

@ -3,10 +3,4 @@
<string name="pref_mod_settings_title">Skryté nastavenia</string> <string name="pref_mod_settings_title">Skryté nastavenia</string>
<string name="pref_hidden_settings_attendance_percentage">Percento dochádzky</string> <string name="pref_hidden_settings_attendance_percentage">Percento dochádzky</string>
<string name="pref_hidden_settings_hidden_grades">Skryť známky</string> <string name="pref_hidden_settings_hidden_grades">Skryť známky</string>
<string-array name="hidden_settings_entries">
<item>Zlá účasť</item>
<item>Poznámky</item>
<item>Falošná účasť</item>
</string-array>
</resources> </resources>

View File

@ -3,10 +3,4 @@
<string name="pref_mod_settings_title">Секретні налаштування</string> <string name="pref_mod_settings_title">Секретні налаштування</string>
<string name="pref_hidden_settings_attendance_percentage">Відсоток відвідуваності</string> <string name="pref_hidden_settings_attendance_percentage">Відсоток відвідуваності</string>
<string name="pref_hidden_settings_hidden_grades">Приховати оцінки</string> <string name="pref_hidden_settings_hidden_grades">Приховати оцінки</string>
<string-array name="hidden_settings_entries">
<item>Погана відвідуваність</item>
<item>Примітки</item>
<item>Фальшива явка</item>
</string-array>
</resources> </resources>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="pref_default_attendance_percentage">-1</integer>
</resources>

View File

@ -5,11 +5,14 @@
<string name="pref_hidden_settings_attendance_percentage">Attendance percentage</string> <string name="pref_hidden_settings_attendance_percentage">Attendance percentage</string>
<string name="pref_hidden_settings_hidden_grades">Hidden grades</string> <string name="pref_hidden_settings_hidden_grades">Hidden grades</string>
<string name="pref_key_hidden_grades" translatable="false">hidden_grades</string>
<string name="pref_key_attendance_items" translatable="false">attendance_items</string> <string name="pref_key_attendance_items" translatable="false">attendance_items</string>
<string name="pref_key_attendance_percentage" translatable="false">attendance_percentage</string> <string name="pref_key_attendance_percentage" translatable="false">attendance_percentage</string>
<string name="pref_default_attendance_percentage" translatable="false"> <string name="pref_default_attendance_percentage">-1</string>
</string> <string name="pref_mod_settings_show_notes">Show notes</string>
<string name="pref_key_show_notes" translatable="false">show_notes</string>
<bool name="pref_default_show_notes">true</bool>
<string-array name="mod_settings_attendance_entries"> <string-array name="mod_settings_attendance_entries">
<item>Unexcused absence</item> <item>Unexcused absence</item>
@ -37,17 +40,6 @@
</string-array> </string-array>
<string-array name="hidden_settings_entries">
<item>Bad attendance</item>
<item>Notes</item>
<item>Fake attendance</item>
</string-array>
<string-array name="hidden_settings_values" translatable="false">
<item>BAD_ATTENDANCE</item>
<item>NOTES</item>
<item>ATTENDANCE</item>
</string-array>
<string-array name="hidden_settings_bad_grades" translatable="false"> <string-array name="hidden_settings_bad_grades" translatable="false">
<item>1</item> <item>1</item>
<item>1+</item> <item>1+</item>

View File

@ -21,45 +21,25 @@
app:title="@string/pref_mod_settings_hidden_attendance_items" app:title="@string/pref_mod_settings_hidden_attendance_items"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
</PreferenceCategory> </PreferenceCategory>
<!-- <PreferenceCategory--> <PreferenceCategory
<!-- app:iconSpaceReserved="false"--> app:iconSpaceReserved="false"
<!-- app:title="@string/pref_counted_average_advanced_header">--> app:title="@string/grade_title">
<!-- <SwitchPreferenceCompat--> <MultiSelectListPreference
<!-- app:defaultValue="@bool/pref_default_grade_average_force_calc"--> app:entries="@array/hidden_settings_bad_grades"
<!-- app:iconSpaceReserved="false"--> app:entryValues="@array/hidden_settings_bad_grades"
<!-- app:key="@string/pref_key_grade_average_force_calc"--> app:iconSpaceReserved="false"
<!-- app:singleLineTitle="false"--> app:key="@string/pref_key_hidden_grades"
<!-- app:title="@string/pref_view_grade_average_force_calc" />--> app:title="@string/pref_hidden_settings_hidden_grades"
<!-- <ListPreference--> app:useSimpleSummaryProvider="true" />
<!-- app:defaultValue="@string/pref_default_grade_average_mode"--> </PreferenceCategory>
<!-- app:entries="@array/grade_average_mode_entries"--> <PreferenceCategory
<!-- app:entryValues="@array/grade_average_mode_values"--> app:iconSpaceReserved="false"
<!-- app:iconSpaceReserved="false"--> app:title="@string/note_title">
<!-- app:key="@string/pref_key_grade_average_mode"--> <SwitchPreferenceCompat
<!-- app:title="@string/pref_view_grade_average_mode"--> app:defaultValue="@bool/pref_default_show_notes"
<!-- app:useSimpleSummaryProvider="true" />--> app:iconSpaceReserved="false"
<!-- <SwitchPreferenceCompat--> app:key="@string/pref_key_show_notes"
<!-- app:defaultValue="@bool/pref_default_optional_arithmetic_average"--> app:singleLineTitle="false"
<!-- app:iconSpaceReserved="false"--> app:title="@string/pref_mod_settings_show_notes" />
<!-- app:key="@string/pref_key_optional_arithmetic_average"--> </PreferenceCategory>
<!-- app:singleLineTitle="false"-->
<!-- app:title="@string/pref_other_optional_arithmetic_average" />-->
<!-- </PreferenceCategory>-->
<!-- <PreferenceCategory-->
<!-- app:iconSpaceReserved="false"-->
<!-- app:title="@string/pref_messages_advanced_header">-->
<!-- <SwitchPreferenceCompat-->
<!-- app:defaultValue="@bool/pref_default_fill_message_content"-->
<!-- app:iconSpaceReserved="false"-->
<!-- app:key="@string/pref_key_fill_message_content"-->
<!-- app:singleLineTitle="false"-->
<!-- app:title="@string/pref_other_fill_message_content" />-->
<!-- <SwitchPreferenceCompat-->
<!-- app:defaultValue="@bool/pref_default_incognito_mode"-->
<!-- app:iconSpaceReserved="false"-->
<!-- app:key="@string/pref_key_incognito_moge"-->
<!-- app:singleLineTitle="false"-->
<!-- app:title="@string/pref_other_incognito_mode"-->
<!-- app:summary="@string/pref_other_incognito_mode_summary" />-->
<!-- </PreferenceCategory>-->
</PreferenceScreen> </PreferenceScreen>