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
@ -18,12 +18,13 @@ const val ENDPOINT_LIBRUS_API_CLASSROOMS = 1008
|
||||
const val ENDPOINT_LIBRUS_API_PUSH_CONFIG = 1010
|
||||
const val ENDPOINT_LIBRUS_API_TIMETABLES = 1015
|
||||
const val ENDPOINT_LIBRUS_API_SUBSTITUTIONS = 1016
|
||||
const val ENDPOINT_LIBRUS_API_NORMAL_GC = 1021
|
||||
const val ENDPOINT_LIBRUS_API_POINT_GC = 1022
|
||||
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_GC = 1023
|
||||
const val ENDPOINT_LIBRUS_API_TEXT_GC = 1024
|
||||
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GC = 1025
|
||||
const val ENDPOINT_LIBRUS_API_BEHAVIOUR_GC = 1026
|
||||
const val ENDPOINT_LIBRUS_API_NORMAL_GRADE_CATEGORIES = 1021
|
||||
const val ENDPOINT_LIBRUS_API_POINT_GRADE_CATEGORIES = 1022
|
||||
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADE_CATEGORIES = 1023
|
||||
const val ENDPOINT_LIBRUS_API_TEXT_GRADE_CATEGORIES = 1024
|
||||
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GRADE_CATEGORIES = 1025
|
||||
const val ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_CATEGORIES = 1026
|
||||
const val ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_COMMENTS = 1027
|
||||
const val ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS = 1030
|
||||
const val ENDPOINT_LIBRUS_API_NORMAL_GRADES = 1031
|
||||
const val ENDPOINT_LIBRUS_API_POINT_GRADES = 1032
|
||||
@ -92,13 +93,14 @@ val LibrusFeatures = listOf(
|
||||
* All grades + categories.
|
||||
*/
|
||||
Feature(LOGIN_TYPE_LIBRUS, FEATURE_GRADES, listOf(
|
||||
ENDPOINT_LIBRUS_API_NORMAL_GC to LOGIN_METHOD_LIBRUS_API,
|
||||
ENDPOINT_LIBRUS_API_POINT_GC to LOGIN_METHOD_LIBRUS_API,
|
||||
ENDPOINT_LIBRUS_API_DESCRIPTIVE_GC to LOGIN_METHOD_LIBRUS_API,
|
||||
ENDPOINT_LIBRUS_API_TEXT_GC to LOGIN_METHOD_LIBRUS_API,
|
||||
ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GC to LOGIN_METHOD_LIBRUS_API,
|
||||
ENDPOINT_LIBRUS_API_BEHAVIOUR_GC to LOGIN_METHOD_LIBRUS_API,
|
||||
ENDPOINT_LIBRUS_API_NORMAL_GRADE_CATEGORIES to LOGIN_METHOD_LIBRUS_API,
|
||||
ENDPOINT_LIBRUS_API_POINT_GRADE_CATEGORIES to LOGIN_METHOD_LIBRUS_API,
|
||||
ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADE_CATEGORIES to LOGIN_METHOD_LIBRUS_API,
|
||||
ENDPOINT_LIBRUS_API_TEXT_GRADE_CATEGORIES to LOGIN_METHOD_LIBRUS_API,
|
||||
ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GRADE_CATEGORIES 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_BEHAVIOUR_GRADE_COMMENTS 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_DESCRIPTIVE_GRADES to LOGIN_METHOD_LIBRUS_API,
|
||||
|
@ -81,26 +81,30 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
LibrusApiTimetables(data, onSuccess)
|
||||
}
|
||||
|
||||
ENDPOINT_LIBRUS_API_NORMAL_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
LibrusApiGrades(data, onSuccess)
|
||||
ENDPOINT_LIBRUS_API_NORMAL_GRADE_CATEGORIES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grade_categories)
|
||||
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 -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grade_comments)
|
||||
LibrusApiGradeComments(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_NORMAL_GC -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grade_categories)
|
||||
LibrusApiGradeCategories(data, onSuccess)
|
||||
ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_COMMENTS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grade_comments)
|
||||
LibrusApiBehaviourGradeComments(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_NORMAL_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
LibrusApiGrades(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_behaviour_grades)
|
||||
LibrusApiBehaviourGrades(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_BEHAVIOUR_GC -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grade_categories)
|
||||
LibrusApiBehaviourGradeCategories(data, onSuccess)
|
||||
}
|
||||
// TODO grades
|
||||
|
||||
ENDPOINT_LIBRUS_API_EVENT_TYPES -> {
|
||||
|
@ -7,7 +7,7 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
import android.graphics.Color
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
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.data.db.modules.grades.GradeCategory
|
||||
|
||||
@ -39,7 +39,7 @@ class LibrusApiBehaviourGradeCategories(override val data: DataLibrus,
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
profileId,
|
||||
-1,
|
||||
-101,
|
||||
data.app.getString(R.string.grade_start_points),
|
||||
0xffbdbdbd.toInt(),
|
||||
data.app.getString(R.string.grade_start_points_format, 1),
|
||||
@ -44,7 +44,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
-1,
|
||||
semester1StartGradeObject.id,
|
||||
true,
|
||||
true,
|
||||
profile.getSemesterStart(1).inMillis
|
||||
@ -52,7 +52,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
|
||||
val semester2StartGradeObject = Grade(
|
||||
profileId,
|
||||
-2,
|
||||
-102,
|
||||
data.app.getString(R.string.grade_start_points),
|
||||
0xffbdbdbd.toInt(),
|
||||
data.app.getString(R.string.grade_start_points_format, 2),
|
||||
@ -68,7 +68,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
-2,
|
||||
semester2StartGradeObject.id,
|
||||
true,
|
||||
true,
|
||||
profile.getSemesterStart(2).inMillis
|
||||
@ -101,21 +101,35 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
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(
|
||||
profileId,
|
||||
id,
|
||||
category?.text ?: "",
|
||||
categoryName,
|
||||
color,
|
||||
"",
|
||||
description,
|
||||
name,
|
||||
value ?: category?.valueFrom ?: 0f,
|
||||
valueFrom,
|
||||
-1f,
|
||||
semester,
|
||||
teacherId,
|
||||
1
|
||||
).apply {
|
||||
type = Grade.TYPE_BEHAVIOUR
|
||||
valueMax = category?.valueTo ?: 0f
|
||||
valueMax = valueTo
|
||||
}
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
|
@ -7,7 +7,7 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
import android.graphics.Color
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
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.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||
@ -22,7 +22,7 @@ class LibrusApiGradeCategories(override val data: DataLibrus,
|
||||
apiGet(TAG, "Grades/Categories") { json ->
|
||||
json.getJsonArray("Categories")?.asJsonObjectList()?.forEach { category ->
|
||||
val id = category.getLong("Id") ?: return@forEach
|
||||
val name = category.getString("Name") ?: ""
|
||||
val name = category.getString("Name")?.fixWhiteSpaces() ?: ""
|
||||
val weight = when (category.getBoolean("CountToTheAverage")) {
|
||||
true -> category.getFloat("Weight") ?: 0f
|
||||
else -> 0f
|
||||
@ -41,7 +41,7 @@ class LibrusApiGradeCategories(override val data: DataLibrus,
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,12 @@
|
||||
|
||||
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_NORMAL_GRADE_COMMENTS
|
||||
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.grades.GradeCategory
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
|
||||
class LibrusApiGradeComments(override val data: DataLibrus,
|
||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||
@ -25,7 +22,7 @@ class LibrusApiGradeComments(override val data: DataLibrus,
|
||||
|
||||
json.getJsonArray("Comments")?.asJsonObjectList()?.forEach { comment ->
|
||||
val id = comment.getLong("Id") ?: return@forEach
|
||||
val text = comment.getString("Text")
|
||||
val text = comment.getString("Text")?.fixWhiteSpaces() ?: return@forEach
|
||||
|
||||
val gradeCategoryObject = GradeCategory(
|
||||
profileId,
|
||||
@ -34,7 +31,7 @@ class LibrusApiGradeComments(override val data: DataLibrus,
|
||||
-1,
|
||||
text
|
||||
).apply {
|
||||
type = GradeCategory.TYPE_COMMENT
|
||||
type = GradeCategory.TYPE_NORMAL_COMMENT
|
||||
}
|
||||
|
||||
data.gradeCategories.put(id, gradeCategoryObject)
|
||||
|
@ -46,7 +46,7 @@ class LibrusApiGrades(override val data: DataLibrus,
|
||||
val description = grade.getJsonArray("Comments")?.asJsonObjectList()?.let { comments ->
|
||||
if (comments.isNotEmpty()) {
|
||||
data.gradeCategories.singleOrNull {
|
||||
it.type == GradeCategory.TYPE_COMMENT
|
||||
it.type == GradeCategory.TYPE_NORMAL_COMMENT
|
||||
&& it.categoryId == comments[0].asJsonObject.getLong("Id")
|
||||
}?.text
|
||||
} else null
|
||||
|
@ -108,7 +108,7 @@ import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
AttendanceType.class,
|
||||
pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson.class,
|
||||
ConfigEntry.class,
|
||||
Metadata.class}, version = 66)
|
||||
Metadata.class}, version = 67)
|
||||
@TypeConverters({
|
||||
ConverterTime.class,
|
||||
ConverterDate.class,
|
||||
@ -788,6 +788,33 @@ public abstract class AppDb extends RoomDatabase {
|
||||
"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) {
|
||||
@ -851,7 +878,8 @@ public abstract class AppDb extends RoomDatabase {
|
||||
MIGRATION_62_63,
|
||||
MIGRATION_63_64,
|
||||
MIGRATION_64_65,
|
||||
MIGRATION_65_66
|
||||
MIGRATION_65_66,
|
||||
MIGRATION_66_67
|
||||
)
|
||||
.allowMainThreadQueries()
|
||||
//.fallbackToDestructiveMigration()
|
||||
|
@ -6,7 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity(tableName = "gradeCategories",
|
||||
primaryKeys = {"profileId", "categoryId"})
|
||||
primaryKeys = {"profileId", "categoryId", "type"})
|
||||
public class GradeCategory {
|
||||
public int profileId;
|
||||
|
||||
@ -26,8 +26,9 @@ public class GradeCategory {
|
||||
public int type = 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_COMMENT = 3;
|
||||
|
||||
public GradeCategory(int profileId, long categoryId, float weight, int color, String text) {
|
||||
this.profileId = profileId;
|
||||
|
Loading…
x
Reference in New Issue
Block a user