mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 10:54:36 -06:00
[UI] Update event types for university school.
This commit is contained in:
parent
48c9e2dfe3
commit
aaa3b8626e
@ -62,7 +62,7 @@ data class AppData(
|
||||
)
|
||||
|
||||
data class EventType(
|
||||
val id: Int,
|
||||
val id: Long,
|
||||
val color: String,
|
||||
val name: String,
|
||||
)
|
||||
|
@ -15,7 +15,7 @@ class ProfileConfig(
|
||||
entries: List<ConfigEntry>?,
|
||||
) : BaseConfig(db, profileId, entries) {
|
||||
companion object {
|
||||
const val DATA_VERSION = 4
|
||||
const val DATA_VERSION = 5
|
||||
}
|
||||
|
||||
val grades by lazy { ProfileConfigGrades(this) }
|
||||
|
@ -16,6 +16,8 @@ import pl.szczodrzynski.edziennik.utils.managers.GradesManager.Companion.YEAR_AL
|
||||
class ProfileConfigMigration(config: ProfileConfig) {
|
||||
init { config.apply {
|
||||
|
||||
val profile = db.profileDao().getByIdNow(profileId ?: -1)
|
||||
|
||||
if (dataVersion < 2) {
|
||||
sync.notificationFilter = sync.notificationFilter + NotificationType.TEACHER_ABSENCE
|
||||
|
||||
@ -37,11 +39,23 @@ class ProfileConfigMigration(config: ProfileConfig) {
|
||||
// switch to new event types (USOS)
|
||||
dataVersion = 4
|
||||
|
||||
val profile = db.profileDao().getByIdNow(profileId ?: -1)
|
||||
if (profile?.loginStoreType?.schoolType == SchoolType.UNIVERSITY) {
|
||||
db.eventTypeDao().clear(profileId ?: -1)
|
||||
db.eventTypeDao().addDefaultTypes(profile)
|
||||
}
|
||||
}
|
||||
|
||||
if (dataVersion < 5) {
|
||||
// update USOS event types and the appropriate events (2022-12-25)
|
||||
dataVersion = 5
|
||||
|
||||
if (profile?.loginStoreType?.schoolType == SchoolType.UNIVERSITY) {
|
||||
db.eventTypeDao().getAllWithDefaults(profile)
|
||||
// wejściówka (4) -> kartkówka (3)
|
||||
db.eventDao().getRawNow("UPDATE events SET eventType = 3 WHERE profileId = $profileId AND eventType = 4;")
|
||||
// zadanie (6) -> zadanie domowe (-1)
|
||||
db.eventDao().getRawNow("UPDATE events SET eventType = -1 WHERE profileId = $profileId AND eventType = 6;")
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
@ -25,6 +25,9 @@ abstract class EventTypeDao {
|
||||
@Query("DELETE FROM eventTypes WHERE profileId = :profileId")
|
||||
abstract fun clear(profileId: Int)
|
||||
|
||||
@Query("DELETE FROM eventTypes WHERE profileId = :profileId AND eventTypeSource = :source")
|
||||
abstract fun clearBySource(profileId: Int, source: Int)
|
||||
|
||||
@Query("SELECT * FROM eventTypes WHERE profileId = :profileId AND eventType = :typeId")
|
||||
abstract fun getByIdNow(profileId: Int, typeId: Long): EventType?
|
||||
|
||||
@ -43,7 +46,7 @@ abstract class EventTypeDao {
|
||||
val typeList = data.eventTypes.map {
|
||||
EventType(
|
||||
profileId = profile.id,
|
||||
id = it.id.toLong(),
|
||||
id = it.id,
|
||||
name = it.name,
|
||||
color = Color.parseColor(it.color),
|
||||
order = order++,
|
||||
@ -53,4 +56,21 @@ abstract class EventTypeDao {
|
||||
addAll(typeList)
|
||||
return typeList
|
||||
}
|
||||
|
||||
fun getAllWithDefaults(profile: Profile): List<EventType> {
|
||||
val eventTypes = getAllNow(profile.id)
|
||||
|
||||
val defaultIdsExpected = AppData.get(profile.loginStoreType).eventTypes
|
||||
.map { it.id }
|
||||
val defaultIdsFound = eventTypes.filter { it.source == SOURCE_DEFAULT }
|
||||
.sortedBy { it.order }
|
||||
.map { it.id }
|
||||
|
||||
if (defaultIdsExpected == defaultIdsFound)
|
||||
return eventTypes
|
||||
|
||||
clearBySource(profile.id, SOURCE_DEFAULT)
|
||||
addDefaultTypes(profile)
|
||||
return eventTypes
|
||||
}
|
||||
}
|
||||
|
@ -5,31 +5,6 @@ package pl.szczodrzynski.edziennik.data.db.entity
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_CLASS_EVENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_DEFAULT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_ELEARNING
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_ESSAY
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_EXAM
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_EXCURSION
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_HOMEWORK
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_INFORMATION
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_PROJECT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_PT_MEETING
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_READING
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_SHORT_QUIZ
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_CLASS_EVENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_DEFAULT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_ELEARNING
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_ESSAY
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_EXAM
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_EXCURSION
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_HOMEWORK
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_INFORMATION
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_PROJECT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_PT_MEETING
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_READING
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_SHORT_QUIZ
|
||||
|
||||
@Entity(
|
||||
tableName = "eventTypes",
|
||||
@ -55,35 +30,5 @@ class EventType(
|
||||
const val SOURCE_REGISTER = 1
|
||||
const val SOURCE_CUSTOM = 2
|
||||
const val SOURCE_SHARED = 3
|
||||
|
||||
fun getTypeColorMap() = mapOf(
|
||||
TYPE_ELEARNING to COLOR_ELEARNING,
|
||||
TYPE_HOMEWORK to COLOR_HOMEWORK,
|
||||
TYPE_DEFAULT to COLOR_DEFAULT,
|
||||
TYPE_EXAM to COLOR_EXAM,
|
||||
TYPE_SHORT_QUIZ to COLOR_SHORT_QUIZ,
|
||||
TYPE_ESSAY to COLOR_ESSAY,
|
||||
TYPE_PROJECT to COLOR_PROJECT,
|
||||
TYPE_PT_MEETING to COLOR_PT_MEETING,
|
||||
TYPE_EXCURSION to COLOR_EXCURSION,
|
||||
TYPE_READING to COLOR_READING,
|
||||
TYPE_CLASS_EVENT to COLOR_CLASS_EVENT,
|
||||
TYPE_INFORMATION to COLOR_INFORMATION
|
||||
)
|
||||
|
||||
fun getTypeNameMap() = mapOf(
|
||||
TYPE_ELEARNING to R.string.event_type_elearning,
|
||||
TYPE_HOMEWORK to R.string.event_type_homework,
|
||||
TYPE_DEFAULT to R.string.event_other,
|
||||
TYPE_EXAM to R.string.event_exam,
|
||||
TYPE_SHORT_QUIZ to R.string.event_short_quiz,
|
||||
TYPE_ESSAY to R.string.event_essay,
|
||||
TYPE_PROJECT to R.string.event_project,
|
||||
TYPE_PT_MEETING to R.string.event_pt_meeting,
|
||||
TYPE_EXCURSION to R.string.event_excursion,
|
||||
TYPE_READING to R.string.event_reading,
|
||||
TYPE_CLASS_EVENT to R.string.event_class_event,
|
||||
TYPE_INFORMATION to R.string.event_information
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -142,13 +142,7 @@ class AgendaFragment : Fragment(), CoroutineScope {
|
||||
|
||||
private suspend fun checkEventTypes() {
|
||||
withContext(Dispatchers.Default) {
|
||||
val eventTypes = app.db.eventTypeDao().getAllNow(app.profileId).map {
|
||||
it.id
|
||||
}
|
||||
val defaultEventTypes = EventType.getTypeColorMap().keys
|
||||
if (!eventTypes.containsAll(defaultEventTypes)) {
|
||||
app.db.eventTypeDao().addDefaultTypes(app.profile)
|
||||
}
|
||||
app.db.eventTypeDao().getAllWithDefaults(app.profile)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import kotlinx.coroutines.launch
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.config.Config
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.interceptor.SignatureInterceptor
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.EventType.Companion.SOURCE_DEFAULT
|
||||
import pl.szczodrzynski.edziennik.databinding.LabFragmentBinding
|
||||
import pl.szczodrzynski.edziennik.ext.*
|
||||
import pl.szczodrzynski.edziennik.ui.base.lazypager.LazyFragment
|
||||
@ -65,6 +66,7 @@ class LabPageFragment : LazyFragment(), CoroutineScope {
|
||||
b.clearEndpointTimers.isVisible = false
|
||||
b.rodo.isVisible = false
|
||||
b.removeHomework.isVisible = false
|
||||
b.resetEventTypes.isVisible = false
|
||||
b.unarchive.isVisible = false
|
||||
b.profile.isVisible = false
|
||||
}
|
||||
@ -100,6 +102,11 @@ class LabPageFragment : LazyFragment(), CoroutineScope {
|
||||
app.db.eventDao().getRawNow("UPDATE events SET homeworkBody = NULL WHERE profileId = ${App.profileId}")
|
||||
}
|
||||
|
||||
b.resetEventTypes.onClick {
|
||||
app.db.eventTypeDao().clearBySource(App.profileId, SOURCE_DEFAULT)
|
||||
app.db.eventTypeDao().getAllWithDefaults(App.profile)
|
||||
}
|
||||
|
||||
b.chucker.isChecked = App.enableChucker
|
||||
b.chucker.onChange { _, isChecked ->
|
||||
app.config.enableChucker = isChecked
|
||||
|
@ -33,13 +33,8 @@ class EventTypeDropdown : TextInputDropDown {
|
||||
suspend fun loadItems() {
|
||||
val types = withContext(Dispatchers.Default) {
|
||||
val list = mutableListOf<Item>()
|
||||
|
||||
var types = db.eventTypeDao().getAllNow(profileId)
|
||||
|
||||
if (types.none { it.id in -1L..10L }) {
|
||||
val profile = db.profileDao().getByIdNow(profileId) ?: return@withContext listOf()
|
||||
types = db.eventTypeDao().addDefaultTypes(profile)
|
||||
}
|
||||
val types = db.eventTypeDao().getAllNow(profileId)
|
||||
.sortedBy { it.order }
|
||||
|
||||
list += types.map {
|
||||
Item(it.id, it.name, tag = it, icon = IconicsDrawable(context).apply {
|
||||
|
@ -100,6 +100,13 @@
|
||||
android:text="Remove all homework body (null)"
|
||||
android:textAllCaps="false" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/resetEventTypes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Reset event types"
|
||||
android:textAllCaps="false" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cookies"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -93,34 +93,29 @@
|
||||
},
|
||||
"eventTypes": [
|
||||
{
|
||||
"id": 1,
|
||||
"color": "#f44336",
|
||||
"name": "egzamin"
|
||||
"id": 3,
|
||||
"color": "#76ff03",
|
||||
"name": "kartkówka"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"color": "#e91e63",
|
||||
"name": "kolokwium"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"color": "#76ff03",
|
||||
"name": "kartkówka"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"color": "#ffeb3b",
|
||||
"name": "wejściówka"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"color": "#90caf9",
|
||||
"name": "zaliczenie"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"color": "#4050b5",
|
||||
"name": "zadanie"
|
||||
"id": 1,
|
||||
"color": "#f44336",
|
||||
"name": "egzamin"
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"color": "#3d5afe",
|
||||
"name": "poprawka"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
|
Loading…
Reference in New Issue
Block a user