forked from github/szkolny
[APIv2/Librus] Add behaviour grade comments, change features names and fix semester start points
This commit is contained in:
parent
c1ca104021
commit
2e18c5a668
@ -7,52 +7,53 @@ package pl.szczodrzynski.edziennik.api.v2.librus
|
|||||||
import pl.szczodrzynski.edziennik.api.v2.*
|
import pl.szczodrzynski.edziennik.api.v2.*
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.Feature
|
import pl.szczodrzynski.edziennik.api.v2.models.Feature
|
||||||
|
|
||||||
const val ENDPOINT_LIBRUS_API_ME = 1001
|
const val ENDPOINT_LIBRUS_API_ME = 1001
|
||||||
const val ENDPOINT_LIBRUS_API_SCHOOLS = 1002
|
const val ENDPOINT_LIBRUS_API_SCHOOLS = 1002
|
||||||
const val ENDPOINT_LIBRUS_API_CLASSES = 1003
|
const val ENDPOINT_LIBRUS_API_CLASSES = 1003
|
||||||
const val ENDPOINT_LIBRUS_API_VIRTUAL_CLASSES = 1004
|
const val ENDPOINT_LIBRUS_API_VIRTUAL_CLASSES = 1004
|
||||||
const val ENDPOINT_LIBRUS_API_UNITS = 1005
|
const val ENDPOINT_LIBRUS_API_UNITS = 1005
|
||||||
const val ENDPOINT_LIBRUS_API_USERS = 1006
|
const val ENDPOINT_LIBRUS_API_USERS = 1006
|
||||||
const val ENDPOINT_LIBRUS_API_SUBJECTS = 1007
|
const val ENDPOINT_LIBRUS_API_SUBJECTS = 1007
|
||||||
const val ENDPOINT_LIBRUS_API_CLASSROOMS = 1008
|
const val ENDPOINT_LIBRUS_API_CLASSROOMS = 1008
|
||||||
const val ENDPOINT_LIBRUS_API_PUSH_CONFIG = 1010
|
const val ENDPOINT_LIBRUS_API_PUSH_CONFIG = 1010
|
||||||
const val ENDPOINT_LIBRUS_API_TIMETABLES = 1015
|
const val ENDPOINT_LIBRUS_API_TIMETABLES = 1015
|
||||||
const val ENDPOINT_LIBRUS_API_SUBSTITUTIONS = 1016
|
const val ENDPOINT_LIBRUS_API_SUBSTITUTIONS = 1016
|
||||||
const val ENDPOINT_LIBRUS_API_NORMAL_GC = 1021
|
const val ENDPOINT_LIBRUS_API_NORMAL_GRADE_CATEGORIES = 1021
|
||||||
const val ENDPOINT_LIBRUS_API_POINT_GC = 1022
|
const val ENDPOINT_LIBRUS_API_POINT_GRADE_CATEGORIES = 1022
|
||||||
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_GC = 1023
|
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADE_CATEGORIES = 1023
|
||||||
const val ENDPOINT_LIBRUS_API_TEXT_GC = 1024
|
const val ENDPOINT_LIBRUS_API_TEXT_GRADE_CATEGORIES = 1024
|
||||||
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GC = 1025
|
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GRADE_CATEGORIES = 1025
|
||||||
const val ENDPOINT_LIBRUS_API_BEHAVIOUR_GC = 1026
|
const val ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_CATEGORIES = 1026
|
||||||
const val ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS = 1030
|
const val ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_COMMENTS = 1027
|
||||||
const val ENDPOINT_LIBRUS_API_NORMAL_GRADES = 1031
|
const val ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS = 1030
|
||||||
const val ENDPOINT_LIBRUS_API_POINT_GRADES = 1032
|
const val ENDPOINT_LIBRUS_API_NORMAL_GRADES = 1031
|
||||||
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADES = 1033
|
const val ENDPOINT_LIBRUS_API_POINT_GRADES = 1032
|
||||||
const val ENDPOINT_LIBRUS_API_TEXT_GRADES = 1034
|
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADES = 1033
|
||||||
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GRADES = 1035
|
const val ENDPOINT_LIBRUS_API_TEXT_GRADES = 1034
|
||||||
const val ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADES = 1036
|
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GRADES = 1035
|
||||||
const val ENDPOINT_LIBRUS_API_EVENT_TYPES = 1040
|
const val ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADES = 1036
|
||||||
const val ENDPOINT_LIBRUS_API_EVENTS = 1041
|
const val ENDPOINT_LIBRUS_API_EVENT_TYPES = 1040
|
||||||
const val ENDPOINT_LIBRUS_API_HOMEWORK = 1050
|
const val ENDPOINT_LIBRUS_API_EVENTS = 1041
|
||||||
const val ENDPOINT_LIBRUS_API_LUCKY_NUMBER = 1060
|
const val ENDPOINT_LIBRUS_API_HOMEWORK = 1050
|
||||||
const val ENDPOINT_LIBRUS_API_NOTICE_TYPES = 1070
|
const val ENDPOINT_LIBRUS_API_LUCKY_NUMBER = 1060
|
||||||
const val ENDPOINT_LIBRUS_API_NOTICES = 1071
|
const val ENDPOINT_LIBRUS_API_NOTICE_TYPES = 1070
|
||||||
const val ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES = 1080
|
const val ENDPOINT_LIBRUS_API_NOTICES = 1071
|
||||||
const val ENDPOINT_LIBRUS_API_ATTENDANCES = 1081
|
const val ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES = 1080
|
||||||
const val ENDPOINT_LIBRUS_API_ANNOUNCEMENTS = 1090
|
const val ENDPOINT_LIBRUS_API_ATTENDANCES = 1081
|
||||||
const val ENDPOINT_LIBRUS_API_PT_MEETINGS = 1100
|
const val ENDPOINT_LIBRUS_API_ANNOUNCEMENTS = 1090
|
||||||
const val ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES = 1109
|
const val ENDPOINT_LIBRUS_API_PT_MEETINGS = 1100
|
||||||
const val ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS = 1110
|
const val ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES = 1109
|
||||||
const val ENDPOINT_LIBRUS_API_SCHOOL_FREE_DAYS = 1120
|
const val ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS = 1110
|
||||||
const val ENDPOINT_LIBRUS_API_CLASS_FREE_DAYS = 1130
|
const val ENDPOINT_LIBRUS_API_SCHOOL_FREE_DAYS = 1120
|
||||||
const val ENDPOINT_LIBRUS_SYNERGIA_INFO = 2010
|
const val ENDPOINT_LIBRUS_API_CLASS_FREE_DAYS = 1130
|
||||||
const val ENDPOINT_LIBRUS_SYNERGIA_GRADES = 2020
|
const val ENDPOINT_LIBRUS_SYNERGIA_INFO = 2010
|
||||||
const val ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK = 2030
|
const val ENDPOINT_LIBRUS_SYNERGIA_GRADES = 2020
|
||||||
const val ENDPOINT_LIBRUS_MESSAGES_RECEIVED = 3010
|
const val ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK = 2030
|
||||||
const val ENDPOINT_LIBRUS_MESSAGES_SENT = 3020
|
const val ENDPOINT_LIBRUS_MESSAGES_RECEIVED = 3010
|
||||||
const val ENDPOINT_LIBRUS_MESSAGES_TRASH = 3030
|
const val ENDPOINT_LIBRUS_MESSAGES_SENT = 3020
|
||||||
const val ENDPOINT_LIBRUS_MESSAGES_RECEIVERS = 3040
|
const val ENDPOINT_LIBRUS_MESSAGES_TRASH = 3030
|
||||||
const val ENDPOINT_LIBRUS_MESSAGES_GET = 3040
|
const val ENDPOINT_LIBRUS_MESSAGES_RECEIVERS = 3040
|
||||||
|
const val ENDPOINT_LIBRUS_MESSAGES_GET = 3040
|
||||||
|
|
||||||
val LibrusFeatures = listOf(
|
val LibrusFeatures = listOf(
|
||||||
|
|
||||||
@ -92,13 +93,14 @@ val LibrusFeatures = listOf(
|
|||||||
* All grades + categories.
|
* All grades + categories.
|
||||||
*/
|
*/
|
||||||
Feature(LOGIN_TYPE_LIBRUS, FEATURE_GRADES, listOf(
|
Feature(LOGIN_TYPE_LIBRUS, FEATURE_GRADES, listOf(
|
||||||
ENDPOINT_LIBRUS_API_NORMAL_GC to LOGIN_METHOD_LIBRUS_API,
|
ENDPOINT_LIBRUS_API_NORMAL_GRADE_CATEGORIES to LOGIN_METHOD_LIBRUS_API,
|
||||||
ENDPOINT_LIBRUS_API_POINT_GC to LOGIN_METHOD_LIBRUS_API,
|
ENDPOINT_LIBRUS_API_POINT_GRADE_CATEGORIES to LOGIN_METHOD_LIBRUS_API,
|
||||||
ENDPOINT_LIBRUS_API_DESCRIPTIVE_GC to LOGIN_METHOD_LIBRUS_API,
|
ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADE_CATEGORIES to LOGIN_METHOD_LIBRUS_API,
|
||||||
ENDPOINT_LIBRUS_API_TEXT_GC to LOGIN_METHOD_LIBRUS_API,
|
ENDPOINT_LIBRUS_API_TEXT_GRADE_CATEGORIES to LOGIN_METHOD_LIBRUS_API,
|
||||||
ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GC to LOGIN_METHOD_LIBRUS_API,
|
ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GRADE_CATEGORIES to LOGIN_METHOD_LIBRUS_API,
|
||||||
ENDPOINT_LIBRUS_API_BEHAVIOUR_GC to LOGIN_METHOD_LIBRUS_API,
|
ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_CATEGORIES to LOGIN_METHOD_LIBRUS_API,
|
||||||
ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS to LOGIN_METHOD_LIBRUS_API,
|
ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS to LOGIN_METHOD_LIBRUS_API,
|
||||||
|
ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_COMMENTS to LOGIN_METHOD_LIBRUS_API,
|
||||||
ENDPOINT_LIBRUS_API_NORMAL_GRADES to LOGIN_METHOD_LIBRUS_API,
|
ENDPOINT_LIBRUS_API_NORMAL_GRADES to LOGIN_METHOD_LIBRUS_API,
|
||||||
ENDPOINT_LIBRUS_API_POINT_GRADES to LOGIN_METHOD_LIBRUS_API,
|
ENDPOINT_LIBRUS_API_POINT_GRADES to LOGIN_METHOD_LIBRUS_API,
|
||||||
ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADES to LOGIN_METHOD_LIBRUS_API,
|
ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADES to LOGIN_METHOD_LIBRUS_API,
|
||||||
|
@ -81,26 +81,30 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
|||||||
LibrusApiTimetables(data, onSuccess)
|
LibrusApiTimetables(data, onSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
ENDPOINT_LIBRUS_API_NORMAL_GRADES -> {
|
ENDPOINT_LIBRUS_API_NORMAL_GRADE_CATEGORIES -> {
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
data.startProgress(R.string.edziennik_progress_endpoint_grade_categories)
|
||||||
LibrusApiGrades(data, onSuccess)
|
LibrusApiGradeCategories(data, onSuccess)
|
||||||
|
}
|
||||||
|
ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_CATEGORIES -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_grade_categories)
|
||||||
|
LibrusApiBehaviourGradeCategories(data, onSuccess)
|
||||||
}
|
}
|
||||||
ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS -> {
|
ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS -> {
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_grade_comments)
|
data.startProgress(R.string.edziennik_progress_endpoint_grade_comments)
|
||||||
LibrusApiGradeComments(data, onSuccess)
|
LibrusApiGradeComments(data, onSuccess)
|
||||||
}
|
}
|
||||||
ENDPOINT_LIBRUS_API_NORMAL_GC -> {
|
ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_COMMENTS -> {
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_grade_categories)
|
data.startProgress(R.string.edziennik_progress_endpoint_grade_comments)
|
||||||
LibrusApiGradeCategories(data, onSuccess)
|
LibrusApiBehaviourGradeComments(data, onSuccess)
|
||||||
|
}
|
||||||
|
ENDPOINT_LIBRUS_API_NORMAL_GRADES -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||||
|
LibrusApiGrades(data, onSuccess)
|
||||||
}
|
}
|
||||||
ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADES -> {
|
ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADES -> {
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_behaviour_grades)
|
data.startProgress(R.string.edziennik_progress_endpoint_behaviour_grades)
|
||||||
LibrusApiBehaviourGrades(data, onSuccess)
|
LibrusApiBehaviourGrades(data, onSuccess)
|
||||||
}
|
}
|
||||||
ENDPOINT_LIBRUS_API_BEHAVIOUR_GC -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_grade_categories)
|
|
||||||
LibrusApiBehaviourGradeCategories(data, onSuccess)
|
|
||||||
}
|
|
||||||
// TODO grades
|
// TODO grades
|
||||||
|
|
||||||
ENDPOINT_LIBRUS_API_EVENT_TYPES -> {
|
ENDPOINT_LIBRUS_API_EVENT_TYPES -> {
|
||||||
|
@ -7,7 +7,7 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
|||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_BEHAVIOUR_GC
|
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_CATEGORIES
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class LibrusApiBehaviourGradeCategories(override val data: DataLibrus,
|
|||||||
data.gradeCategories.put(id, gradeCategoryObject)
|
data.gradeCategories.put(id, gradeCategoryObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_LIBRUS_API_BEHAVIOUR_GC, 1 * WEEK)
|
data.setSyncNext(ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_CATEGORIES, 1 * WEEK)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-12-7
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.*
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_COMMENTS
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||||
|
|
||||||
|
class LibrusApiBehaviourGradeComments(override val data: DataLibrus,
|
||||||
|
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "LibrusApiBehaviourGradeComments"
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
apiGet(TAG, "BehaviourGrades/Points/Comments") { json ->
|
||||||
|
|
||||||
|
json.getJsonArray("Comments")?.asJsonObjectList()?.forEach { comment ->
|
||||||
|
val id = comment.getLong("Id") ?: return@forEach
|
||||||
|
val text = comment.getString("Text")?.fixWhiteSpaces() ?: return@forEach
|
||||||
|
|
||||||
|
val gradeCategoryObject = GradeCategory(
|
||||||
|
profileId,
|
||||||
|
id,
|
||||||
|
-1f,
|
||||||
|
-1,
|
||||||
|
text
|
||||||
|
).apply {
|
||||||
|
type = GradeCategory.TYPE_BEHAVIOUR_COMMENT
|
||||||
|
}
|
||||||
|
|
||||||
|
data.gradeCategories.put(id, gradeCategoryObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_COMMENTS, SYNC_ALWAYS)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
|||||||
|
|
||||||
val semester1StartGradeObject = Grade(
|
val semester1StartGradeObject = Grade(
|
||||||
profileId,
|
profileId,
|
||||||
-1,
|
-101,
|
||||||
data.app.getString(R.string.grade_start_points),
|
data.app.getString(R.string.grade_start_points),
|
||||||
0xffbdbdbd.toInt(),
|
0xffbdbdbd.toInt(),
|
||||||
data.app.getString(R.string.grade_start_points_format, 1),
|
data.app.getString(R.string.grade_start_points_format, 1),
|
||||||
@ -44,7 +44,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
|||||||
data.metadataList.add(Metadata(
|
data.metadataList.add(Metadata(
|
||||||
profileId,
|
profileId,
|
||||||
Metadata.TYPE_GRADE,
|
Metadata.TYPE_GRADE,
|
||||||
-1,
|
semester1StartGradeObject.id,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
profile.getSemesterStart(1).inMillis
|
profile.getSemesterStart(1).inMillis
|
||||||
@ -52,7 +52,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
|||||||
|
|
||||||
val semester2StartGradeObject = Grade(
|
val semester2StartGradeObject = Grade(
|
||||||
profileId,
|
profileId,
|
||||||
-2,
|
-102,
|
||||||
data.app.getString(R.string.grade_start_points),
|
data.app.getString(R.string.grade_start_points),
|
||||||
0xffbdbdbd.toInt(),
|
0xffbdbdbd.toInt(),
|
||||||
data.app.getString(R.string.grade_start_points_format, 2),
|
data.app.getString(R.string.grade_start_points_format, 2),
|
||||||
@ -68,7 +68,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
|||||||
data.metadataList.add(Metadata(
|
data.metadataList.add(Metadata(
|
||||||
profileId,
|
profileId,
|
||||||
Metadata.TYPE_GRADE,
|
Metadata.TYPE_GRADE,
|
||||||
-2,
|
semester2StartGradeObject.id,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
profile.getSemesterStart(2).inMillis
|
profile.getSemesterStart(2).inMillis
|
||||||
@ -101,21 +101,35 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
|||||||
it.categoryId == categoryId && it.type == GradeCategory.TYPE_BEHAVIOUR
|
it.categoryId == categoryId && it.type == GradeCategory.TYPE_BEHAVIOUR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val categoryName = category?.text ?: ""
|
||||||
|
|
||||||
|
val description = grade.getJsonArray("Comments")?.asJsonObjectList()?.let { comments ->
|
||||||
|
if (comments.isNotEmpty()) {
|
||||||
|
data.gradeCategories.singleOrNull {
|
||||||
|
it.type == GradeCategory.TYPE_BEHAVIOUR_COMMENT
|
||||||
|
&& it.categoryId == comments[0].asJsonObject.getLong("Id")
|
||||||
|
}?.text
|
||||||
|
} else null
|
||||||
|
} ?: ""
|
||||||
|
|
||||||
|
val valueFrom = value ?: category?.valueFrom ?: 0f
|
||||||
|
val valueTo = category?.valueTo ?: 0f
|
||||||
|
|
||||||
val gradeObject = Grade(
|
val gradeObject = Grade(
|
||||||
profileId,
|
profileId,
|
||||||
id,
|
id,
|
||||||
category?.text ?: "",
|
categoryName,
|
||||||
color,
|
color,
|
||||||
"",
|
description,
|
||||||
name,
|
name,
|
||||||
value ?: category?.valueFrom ?: 0f,
|
valueFrom,
|
||||||
-1f,
|
-1f,
|
||||||
semester,
|
semester,
|
||||||
teacherId,
|
teacherId,
|
||||||
1
|
1
|
||||||
).apply {
|
).apply {
|
||||||
type = Grade.TYPE_BEHAVIOUR
|
type = Grade.TYPE_BEHAVIOUR
|
||||||
valueMax = category?.valueTo ?: 0f
|
valueMax = valueTo
|
||||||
}
|
}
|
||||||
|
|
||||||
data.gradeList.add(gradeObject)
|
data.gradeList.add(gradeObject)
|
||||||
|
@ -7,7 +7,7 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
|||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GC
|
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GRADE_CATEGORIES
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||||
@ -22,7 +22,7 @@ class LibrusApiGradeCategories(override val data: DataLibrus,
|
|||||||
apiGet(TAG, "Grades/Categories") { json ->
|
apiGet(TAG, "Grades/Categories") { json ->
|
||||||
json.getJsonArray("Categories")?.asJsonObjectList()?.forEach { category ->
|
json.getJsonArray("Categories")?.asJsonObjectList()?.forEach { category ->
|
||||||
val id = category.getLong("Id") ?: return@forEach
|
val id = category.getLong("Id") ?: return@forEach
|
||||||
val name = category.getString("Name") ?: ""
|
val name = category.getString("Name")?.fixWhiteSpaces() ?: ""
|
||||||
val weight = when (category.getBoolean("CountToTheAverage")) {
|
val weight = when (category.getBoolean("CountToTheAverage")) {
|
||||||
true -> category.getFloat("Weight") ?: 0f
|
true -> category.getFloat("Weight") ?: 0f
|
||||||
else -> 0f
|
else -> 0f
|
||||||
@ -41,7 +41,7 @@ class LibrusApiGradeCategories(override val data: DataLibrus,
|
|||||||
data.gradeCategories.put(id, gradeCategoryObject)
|
data.gradeCategories.put(id, gradeCategoryObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_LIBRUS_API_NORMAL_GC, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_LIBRUS_API_NORMAL_GRADE_CATEGORIES, SYNC_ALWAYS)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,12 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS
|
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||||
import pl.szczodrzynski.edziennik.getJsonArray
|
|
||||||
import pl.szczodrzynski.edziennik.getLong
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
|
|
||||||
class LibrusApiGradeComments(override val data: DataLibrus,
|
class LibrusApiGradeComments(override val data: DataLibrus,
|
||||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||||
@ -25,7 +22,7 @@ class LibrusApiGradeComments(override val data: DataLibrus,
|
|||||||
|
|
||||||
json.getJsonArray("Comments")?.asJsonObjectList()?.forEach { comment ->
|
json.getJsonArray("Comments")?.asJsonObjectList()?.forEach { comment ->
|
||||||
val id = comment.getLong("Id") ?: return@forEach
|
val id = comment.getLong("Id") ?: return@forEach
|
||||||
val text = comment.getString("Text")
|
val text = comment.getString("Text")?.fixWhiteSpaces() ?: return@forEach
|
||||||
|
|
||||||
val gradeCategoryObject = GradeCategory(
|
val gradeCategoryObject = GradeCategory(
|
||||||
profileId,
|
profileId,
|
||||||
@ -34,7 +31,7 @@ class LibrusApiGradeComments(override val data: DataLibrus,
|
|||||||
-1,
|
-1,
|
||||||
text
|
text
|
||||||
).apply {
|
).apply {
|
||||||
type = GradeCategory.TYPE_COMMENT
|
type = GradeCategory.TYPE_NORMAL_COMMENT
|
||||||
}
|
}
|
||||||
|
|
||||||
data.gradeCategories.put(id, gradeCategoryObject)
|
data.gradeCategories.put(id, gradeCategoryObject)
|
||||||
|
@ -46,7 +46,7 @@ class LibrusApiGrades(override val data: DataLibrus,
|
|||||||
val description = grade.getJsonArray("Comments")?.asJsonObjectList()?.let { comments ->
|
val description = grade.getJsonArray("Comments")?.asJsonObjectList()?.let { comments ->
|
||||||
if (comments.isNotEmpty()) {
|
if (comments.isNotEmpty()) {
|
||||||
data.gradeCategories.singleOrNull {
|
data.gradeCategories.singleOrNull {
|
||||||
it.type == GradeCategory.TYPE_COMMENT
|
it.type == GradeCategory.TYPE_NORMAL_COMMENT
|
||||||
&& it.categoryId == comments[0].asJsonObject.getLong("Id")
|
&& it.categoryId == comments[0].asJsonObject.getLong("Id")
|
||||||
}?.text
|
}?.text
|
||||||
} else null
|
} else null
|
||||||
|
@ -108,7 +108,7 @@ import pl.szczodrzynski.edziennik.utils.models.Date;
|
|||||||
AttendanceType.class,
|
AttendanceType.class,
|
||||||
pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson.class,
|
pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson.class,
|
||||||
ConfigEntry.class,
|
ConfigEntry.class,
|
||||||
Metadata.class}, version = 66)
|
Metadata.class}, version = 67)
|
||||||
@TypeConverters({
|
@TypeConverters({
|
||||||
ConverterTime.class,
|
ConverterTime.class,
|
||||||
ConverterDate.class,
|
ConverterDate.class,
|
||||||
@ -788,6 +788,33 @@ public abstract class AppDb extends RoomDatabase {
|
|||||||
"PRIMARY KEY(profileId, `key`));");
|
"PRIMARY KEY(profileId, `key`));");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private static final Migration MIGRATION_66_67 = new Migration(66, 67) {
|
||||||
|
@Override
|
||||||
|
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||||
|
database.execSQL("DELETE FROM grades WHERE (gradeId=-1 OR gradeId=-2) AND gradeType=20");
|
||||||
|
database.execSQL("DELETE FROM metadata WHERE (thingId=-1 OR thingId=-2) AND thingType=1");
|
||||||
|
|
||||||
|
database.execSQL("ALTER TABLE gradeCategories RENAME TO _gradeCategories");
|
||||||
|
database.execSQL("CREATE TABLE gradeCategories (" +
|
||||||
|
"profileId INTEGER NOT NULL," +
|
||||||
|
"categoryId INTEGER NOT NULL," +
|
||||||
|
"weight REAL NOT NULL," +
|
||||||
|
"color INTEGER NOT NULL," +
|
||||||
|
"`text` TEXT," +
|
||||||
|
"columns TEXT," +
|
||||||
|
"valueFrom REAL NOT NULL," +
|
||||||
|
"valueTo REAL NOT NULL," +
|
||||||
|
"type INTEGER NOT NULL," +
|
||||||
|
"PRIMARY KEY(profileId, categoryId, type))");
|
||||||
|
|
||||||
|
database.execSQL("INSERT INTO gradeCategories (profileId, categoryId, weight, color," +
|
||||||
|
"`text`, columns, valueFrom, valueTo, type) " +
|
||||||
|
"SELECT profileId, categoryId, weight, color, `text`, columns, valueFrom," +
|
||||||
|
"valueTo, type FROM _gradeCategories");
|
||||||
|
|
||||||
|
database.execSQL("DROP TABLE _gradeCategories");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public static AppDb getDatabase(final Context context) {
|
public static AppDb getDatabase(final Context context) {
|
||||||
@ -851,7 +878,8 @@ public abstract class AppDb extends RoomDatabase {
|
|||||||
MIGRATION_62_63,
|
MIGRATION_62_63,
|
||||||
MIGRATION_63_64,
|
MIGRATION_63_64,
|
||||||
MIGRATION_64_65,
|
MIGRATION_64_65,
|
||||||
MIGRATION_65_66
|
MIGRATION_65_66,
|
||||||
|
MIGRATION_66_67
|
||||||
)
|
)
|
||||||
.allowMainThreadQueries()
|
.allowMainThreadQueries()
|
||||||
//.fallbackToDestructiveMigration()
|
//.fallbackToDestructiveMigration()
|
||||||
|
@ -6,7 +6,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity(tableName = "gradeCategories",
|
@Entity(tableName = "gradeCategories",
|
||||||
primaryKeys = {"profileId", "categoryId"})
|
primaryKeys = {"profileId", "categoryId", "type"})
|
||||||
public class GradeCategory {
|
public class GradeCategory {
|
||||||
public int profileId;
|
public int profileId;
|
||||||
|
|
||||||
@ -26,8 +26,9 @@ public class GradeCategory {
|
|||||||
public int type = 0;
|
public int type = 0;
|
||||||
|
|
||||||
public static final int TYPE_NORMAL = 0;
|
public static final int TYPE_NORMAL = 0;
|
||||||
public static final int TYPE_COMMENT = 1;
|
public static final int TYPE_NORMAL_COMMENT = 1;
|
||||||
public static final int TYPE_BEHAVIOUR = 2;
|
public static final int TYPE_BEHAVIOUR = 2;
|
||||||
|
public static final int TYPE_BEHAVIOUR_COMMENT = 3;
|
||||||
|
|
||||||
public GradeCategory(int profileId, long categoryId, float weight, int color, String text) {
|
public GradeCategory(int profileId, long categoryId, float weight, int color, String text) {
|
||||||
this.profileId = profileId;
|
this.profileId = profileId;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user