mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 19:04:38 -06:00
[APIv2] Add Librus Units. Add Classroom, NoticeType, AttendanceType entities.
This commit is contained in:
parent
ff7f015146
commit
05ce790587
@ -215,4 +215,21 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
get() { mUnitId = mUnitId ?: profile?.getStudentData("unitId", 0L); return mUnitId ?: 0L }
|
||||
set(value) { profile?.putStudentData("unitId", value) ?: return; mUnitId = value }
|
||||
|
||||
}
|
||||
private var mStartPointsSemester1: Int? = null
|
||||
var startPointsSemester1: Int
|
||||
get() { mStartPointsSemester1 = mStartPointsSemester1 ?: profile?.getStudentData("startPointsSemester1", 0); return mStartPointsSemester1 ?: 0 }
|
||||
set(value) { profile?.putStudentData("startPointsSemester1", value) ?: return; mStartPointsSemester1 = value }
|
||||
private var mStartPointsSemester2: Int? = null
|
||||
var startPointsSemester2: Int
|
||||
get() { mStartPointsSemester2 = mStartPointsSemester2 ?: profile?.getStudentData("startPointsSemester2", 0); return mStartPointsSemester2 ?: 0 }
|
||||
set(value) { profile?.putStudentData("startPointsSemester2", value) ?: return; mStartPointsSemester2 = value }
|
||||
|
||||
private var mEnablePointGrades: Boolean? = null
|
||||
var enablePointGrades: Boolean
|
||||
get() { mEnablePointGrades = mEnablePointGrades ?: profile?.getStudentData("enablePointGrades", true); return mEnablePointGrades ?: true }
|
||||
set(value) { profile?.putStudentData("enablePointGrades", value) ?: return; mEnablePointGrades = value }
|
||||
private var mEnableDescriptiveGrades: Boolean? = null
|
||||
var enableDescriptiveGrades: Boolean
|
||||
get() { mEnableDescriptiveGrades = mEnableDescriptiveGrades ?: profile?.getStudentData("enableDescriptiveGrades", true); return mEnableDescriptiveGrades ?: true }
|
||||
set(value) { profile?.putStudentData("enableDescriptiveGrades", value) ?: return; mEnableDescriptiveGrades = value }
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-23.
|
||||
*/
|
||||
|
||||
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_UNITS
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||
|
||||
class LibrusApiUnits(override val data: DataLibrus,
|
||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||
companion object {
|
||||
const val TAG = "LibrusApiUnits"
|
||||
}
|
||||
|
||||
init { run {
|
||||
if (data.unitId == 0L) {
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_UNITS, 12 * DAY)
|
||||
onSuccess()
|
||||
return@run
|
||||
}
|
||||
|
||||
apiGet(TAG, "Units") { json ->
|
||||
val units = json.getJsonArray("Units")
|
||||
units?.singleOrNull { it.asJsonObject.getLong("Id") == data.unitId }?.also { unitEl ->
|
||||
val unit = unitEl.asJsonObject
|
||||
val startPoints = unit.getJsonObject("BehaviourGradesSettings")?.getJsonObject("StartPoints")
|
||||
startPoints?.apply {
|
||||
data.startPointsSemester1 = getInt("Semester1", defaultValue = 0)
|
||||
data.startPointsSemester2 = getInt("Semester2", defaultValue = data.startPointsSemester1)
|
||||
}
|
||||
unit.getJsonObject("GradesSettings")?.apply {
|
||||
data.enablePointGrades = getBoolean("PointGradesEnabled", true)
|
||||
data.enableDescriptiveGrades = getBoolean("DescriptiveGradesEnabled", true)
|
||||
}
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_UNITS, 7 * DAY)
|
||||
onSuccess()
|
||||
}
|
||||
}}
|
||||
}
|
@ -22,6 +22,10 @@ import pl.szczodrzynski.edziennik.data.db.modules.api.EndpointTimer;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.EndpointTimerDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.attendance.AttendanceDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.attendance.AttendanceType;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.attendance.AttendanceTypeDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.classrooms.Classroom;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.classrooms.ClassroomDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.debuglog.DebugLog;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.debuglog.DebugLogDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event;
|
||||
@ -52,6 +56,8 @@ import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.MetadataDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notices.NoticeDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notices.NoticeType;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notices.NoticeTypeDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notification.Notification;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notification.NotificationDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile;
|
||||
@ -94,7 +100,10 @@ import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
EndpointTimer.class,
|
||||
LessonRange.class,
|
||||
Notification.class,
|
||||
Metadata.class}, version = 61)
|
||||
Classroom.class,
|
||||
NoticeType.class,
|
||||
AttendanceType.class,
|
||||
Metadata.class}, version = 62)
|
||||
@TypeConverters({
|
||||
ConverterTime.class,
|
||||
ConverterDate.class,
|
||||
@ -129,6 +138,9 @@ public abstract class AppDb extends RoomDatabase {
|
||||
public abstract EndpointTimerDao endpointTimerDao();
|
||||
public abstract LessonRangeDao lessonRangeDao();
|
||||
public abstract NotificationDao notificationDao();
|
||||
public abstract ClassroomDao classroomDao();
|
||||
public abstract NoticeTypeDao noticeTypeDao();
|
||||
public abstract AttendanceTypeDao attendanceTypeDao();
|
||||
public abstract MetadataDao metadataDao();
|
||||
|
||||
private static volatile AppDb INSTANCE;
|
||||
@ -684,6 +696,31 @@ public abstract class AppDb extends RoomDatabase {
|
||||
database.execSQL("ALTER TABLE teacherAbsence ADD COLUMN teacherAbsenceName TEXT DEFAULT NULL");
|
||||
}
|
||||
};
|
||||
private static final Migration MIGRATION_61_62 = new Migration(61, 62) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS classrooms (\n" +
|
||||
" profileId INTEGER NOT NULL,\n" +
|
||||
" id INTEGER NOT NULL,\n" +
|
||||
" name TEXT NOT NULL,\n" +
|
||||
" PRIMARY KEY(profileId, id)\n" +
|
||||
")");
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS noticeTypes (\n" +
|
||||
" profileId INTEGER NOT NULL,\n" +
|
||||
" id INTEGER NOT NULL,\n" +
|
||||
" name TEXT NOT NULL,\n" +
|
||||
" PRIMARY KEY(profileId, id)\n" +
|
||||
")");
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS attendanceTypes (\n" +
|
||||
" profileId INTEGER NOT NULL,\n" +
|
||||
" id INTEGER NOT NULL,\n" +
|
||||
" name TEXT NOT NULL,\n" +
|
||||
" type INTEGER NOT NULL,\n" +
|
||||
" color INTEGER NOT NULL,\n" +
|
||||
" PRIMARY KEY(profileId, id)\n" +
|
||||
")");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static AppDb getDatabase(final Context context) {
|
||||
@ -742,7 +779,8 @@ public abstract class AppDb extends RoomDatabase {
|
||||
MIGRATION_57_58,
|
||||
MIGRATION_58_59,
|
||||
MIGRATION_59_60,
|
||||
MIGRATION_60_61
|
||||
MIGRATION_60_61,
|
||||
MIGRATION_61_62
|
||||
)
|
||||
.allowMainThreadQueries()
|
||||
//.fallbackToDestructiveMigration()
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-23.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.attendance
|
||||
|
||||
import androidx.room.Entity
|
||||
|
||||
@Entity(tableName = "attendanceTypes",
|
||||
primaryKeys = ["profileId", "id"])
|
||||
data class AttendanceType (
|
||||
|
||||
val profileId: Int,
|
||||
|
||||
val id: Long,
|
||||
|
||||
val name: String,
|
||||
|
||||
val type: Int,
|
||||
|
||||
val color: Int
|
||||
|
||||
)
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-23.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.attendance
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
|
||||
@Dao
|
||||
interface AttendanceTypeDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun add(attendanceType: AttendanceType)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun addAll(attendanceTypeList: List<AttendanceType>)
|
||||
|
||||
@Query("DELETE FROM attendanceTypes WHERE profileId = :profileId")
|
||||
fun clear(profileId: Int)
|
||||
|
||||
@Query("SELECT * FROM attendanceTypes WHERE profileId = :profileId ORDER BY id ASC")
|
||||
fun getAllNow(profileId: Int): List<AttendanceType>
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-23.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.classrooms
|
||||
|
||||
import androidx.room.Entity
|
||||
|
||||
@Entity(tableName = "classrooms",
|
||||
primaryKeys = ["profileId", "id"])
|
||||
data class Classroom (
|
||||
|
||||
val profileId: Int,
|
||||
|
||||
val id: Long,
|
||||
|
||||
val name: String
|
||||
|
||||
)
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-23.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.classrooms
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
|
||||
@Dao
|
||||
interface ClassroomDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun add(classroom: Classroom)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun addAll(classroomList: List<Classroom>)
|
||||
|
||||
@Query("DELETE FROM classrooms WHERE profileId = :profileId")
|
||||
fun clear(profileId: Int)
|
||||
|
||||
@Query("SELECT * FROM classrooms WHERE profileId = :profileId ORDER BY id ASC")
|
||||
fun getAllNow(profileId: Int): List<Classroom>
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-23.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.notices
|
||||
|
||||
import androidx.room.Entity
|
||||
|
||||
@Entity(tableName = "noticeTypes",
|
||||
primaryKeys = ["profileId", "id"])
|
||||
data class NoticeType (
|
||||
|
||||
val profileId: Int,
|
||||
|
||||
val id: Long,
|
||||
|
||||
val name: String
|
||||
|
||||
)
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-23.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.notices
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
|
||||
@Dao
|
||||
interface NoticeTypeDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun add(noticeType: NoticeType)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun addAll(noticeTypeList: List<NoticeType>)
|
||||
|
||||
@Query("DELETE FROM noticeTypes WHERE profileId = :profileId")
|
||||
fun clear(profileId: Int)
|
||||
|
||||
@Query("SELECT * FROM noticeTypes WHERE profileId = :profileId ORDER BY id ASC")
|
||||
fun getAllNow(profileId: Int): List<NoticeType>
|
||||
}
|
Loading…
Reference in New Issue
Block a user