mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[APIv2/Librus] Update endpoints: API/Schools, API/Events
This commit is contained in:
parent
648699547e
commit
fabacfdcca
@ -18,6 +18,12 @@ open class LibrusApi(open val data: DataLibrus) {
|
|||||||
const val TAG = "LibrusApi"
|
const val TAG = "LibrusApi"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val profileId
|
||||||
|
get() = data.profile?.id ?: -1
|
||||||
|
|
||||||
|
val profile
|
||||||
|
get() = data.profile
|
||||||
|
|
||||||
fun apiGet(tag: String, endpoint: String, method: Int = GET, payload: JsonObject? = null, onSuccess: (json: JsonObject?) -> Unit) {
|
fun apiGet(tag: String, endpoint: String, method: Int = GET, payload: JsonObject? = null, onSuccess: (json: JsonObject?) -> Unit) {
|
||||||
|
|
||||||
val callback = object : JsonCallbackHandler() {
|
val callback = object : JsonCallbackHandler() {
|
||||||
|
@ -14,13 +14,13 @@ class LibrusApiEvents(override val data: DataLibrus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
apiGet(LibrusApiMe.TAG, "") { json ->
|
/*apiGet(LibrusApiMe.TAG, "") { json ->
|
||||||
|
|
||||||
// on error
|
// on error
|
||||||
data.error(TAG, ERROR_LIBRUS_API_, response, json)
|
data.error(TAG, ERROR_LIBRUS_API_, response, json)
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_LIBRUS_API_, 2 * DAY)
|
data.setSyncNext(ENDPOINT_LIBRUS_API_, 2 * DAY)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,11 +6,11 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
|||||||
|
|
||||||
import android.util.Pair
|
import android.util.Pair
|
||||||
import com.google.gson.JsonNull
|
import com.google.gson.JsonNull
|
||||||
|
import pl.szczodrzynski.edziennik.*
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.ENDPOINT_LIBRUS_API_SCHOOLS
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.DataLibrus
|
import pl.szczodrzynski.edziennik.api.v2.librus.data.DataLibrus
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||||
import pl.szczodrzynski.edziennik.getInt
|
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonRange
|
||||||
import pl.szczodrzynski.edziennik.getJsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -26,6 +26,8 @@ class LibrusApiSchools(override val data: DataLibrus,
|
|||||||
val schoolId = school?.getInt("Id")
|
val schoolId = school?.getInt("Id")
|
||||||
val schoolNameLong = school?.getString("Name")
|
val schoolNameLong = school?.getString("Name")
|
||||||
|
|
||||||
|
// create the school's short name using first letters of each long name's word
|
||||||
|
// append the town name and save to student data
|
||||||
var schoolNameShort = ""
|
var schoolNameShort = ""
|
||||||
schoolNameLong?.split(" ")?.forEach {
|
schoolNameLong?.split(" ")?.forEach {
|
||||||
if (it.isBlank())
|
if (it.isBlank())
|
||||||
@ -35,21 +37,24 @@ class LibrusApiSchools(override val data: DataLibrus,
|
|||||||
val schoolTown = school?.getString("Town")?.toLowerCase(Locale.getDefault())
|
val schoolTown = school?.getString("Town")?.toLowerCase(Locale.getDefault())
|
||||||
data.schoolName = schoolId.toString() + schoolNameShort + "_" + schoolTown
|
data.schoolName = schoolId.toString() + schoolNameShort + "_" + schoolTown
|
||||||
|
|
||||||
/*lessonRanges.clear()
|
school?.getJsonArray("LessonsRange")?.let { ranges ->
|
||||||
for ((index, lessonRangeEl) in school.get("LessonsRange").getAsJsonArray().withIndex()) {
|
data.lessonRanges.clear()
|
||||||
val lr = lessonRangeEl.getAsJsonObject()
|
ranges.forEachIndexed { index, rangeEl ->
|
||||||
val from = lr.get("From")
|
val range = rangeEl.asJsonObject
|
||||||
val to = lr.get("To")
|
val from = range.getString("From") ?: return@forEachIndexed
|
||||||
if (from != null && to != null && from !is JsonNull && to !is JsonNull) {
|
val to = range.getString("To") ?: return@forEachIndexed
|
||||||
lessonRanges.put(index, Pair<Time, Time>(Time.fromH_m(from!!.getAsString()), Time.fromH_m(to!!.getAsString())))
|
data.lessonRanges.add(
|
||||||
|
LessonRange(
|
||||||
|
profileId,
|
||||||
|
index,
|
||||||
|
Time.fromH_m(from),
|
||||||
|
Time.fromH_m(to)
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
profile.putStudentData("lessonRanges", app.gson.toJson(lessonRanges))
|
|
||||||
// on error
|
|
||||||
data.error(TAG, ERROR_LIBRUS_API_, response, json)
|
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_LIBRUS_API_, 2 * DAY)
|
data.setSyncNext(ENDPOINT_LIBRUS_API_SCHOOLS, 4 * DAY)
|
||||||
onSuccess()*/
|
onSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,6 +17,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
|||||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.Lesson
|
import pl.szczodrzynski.edziennik.data.db.modules.lessons.Lesson
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange
|
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonRange
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipient
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipient
|
||||||
@ -90,6 +91,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
|||||||
val teacherList = LongSparseArray<Teacher>()
|
val teacherList = LongSparseArray<Teacher>()
|
||||||
val subjectList = LongSparseArray<Subject>()
|
val subjectList = LongSparseArray<Subject>()
|
||||||
val teamList = mutableListOf<Team>()
|
val teamList = mutableListOf<Team>()
|
||||||
|
var lessonRanges = mutableListOf<LessonRange>()
|
||||||
|
|
||||||
var lessonsToRemove: DataRemoveModel? = null
|
var lessonsToRemove: DataRemoveModel? = null
|
||||||
val lessonList = mutableListOf<Lesson>()
|
val lessonList = mutableListOf<Lesson>()
|
||||||
@ -129,6 +131,8 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
|||||||
db.endpointTimerDao().getAllNow(profile.id).forEach { endpointTimer ->
|
db.endpointTimerDao().getAllNow(profile.id).forEach { endpointTimer ->
|
||||||
endpointTimers.add(endpointTimer)
|
endpointTimers.add(endpointTimer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lessonRanges = db.lessonRangeDao().getAllNow(profile.id).toMutableList()
|
||||||
db.teacherDao().getAllNow(profile.id).forEach { teacher ->
|
db.teacherDao().getAllNow(profile.id).forEach { teacher ->
|
||||||
teacherList.put(teacher.id, teacher)
|
teacherList.put(teacher.id, teacher)
|
||||||
}
|
}
|
||||||
@ -151,6 +155,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
|||||||
teacherList.clear()
|
teacherList.clear()
|
||||||
subjectList.clear()
|
subjectList.clear()
|
||||||
teamList.clear()
|
teamList.clear()
|
||||||
|
lessonRanges.clear()
|
||||||
lessonList.clear()
|
lessonList.clear()
|
||||||
lessonChangeList.clear()
|
lessonChangeList.clear()
|
||||||
gradeCategoryList.clear()
|
gradeCategoryList.clear()
|
||||||
|
@ -35,6 +35,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.lessons.Lesson;
|
|||||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange;
|
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange;
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChangeDao;
|
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChangeDao;
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonDao;
|
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonDao;
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonRangeDao;
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore;
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore;
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStoreDao;
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStoreDao;
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.luckynumber.LuckyNumber;
|
import pl.szczodrzynski.edziennik.data.db.modules.luckynumber.LuckyNumber;
|
||||||
@ -84,7 +85,7 @@ import android.content.Context;
|
|||||||
MessageRecipient.class,
|
MessageRecipient.class,
|
||||||
DebugLog.class,
|
DebugLog.class,
|
||||||
EndpointTimer.class,
|
EndpointTimer.class,
|
||||||
Metadata.class}, version = 55)
|
Metadata.class}, version = 56)
|
||||||
@TypeConverters({
|
@TypeConverters({
|
||||||
ConverterTime.class,
|
ConverterTime.class,
|
||||||
ConverterDate.class,
|
ConverterDate.class,
|
||||||
@ -115,6 +116,7 @@ public abstract class AppDb extends RoomDatabase {
|
|||||||
public abstract MessageRecipientDao messageRecipientDao();
|
public abstract MessageRecipientDao messageRecipientDao();
|
||||||
public abstract DebugLogDao debugLogDao();
|
public abstract DebugLogDao debugLogDao();
|
||||||
public abstract EndpointTimerDao endpointTimerDao();
|
public abstract EndpointTimerDao endpointTimerDao();
|
||||||
|
public abstract LessonRangeDao lessonRangeDao();
|
||||||
public abstract MetadataDao metadataDao();
|
public abstract MetadataDao metadataDao();
|
||||||
|
|
||||||
private static volatile AppDb INSTANCE;
|
private static volatile AppDb INSTANCE;
|
||||||
@ -575,6 +577,18 @@ public abstract class AppDb extends RoomDatabase {
|
|||||||
")");
|
")");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private static final Migration MIGRATION_55_56 = new Migration(55, 56) {
|
||||||
|
@Override
|
||||||
|
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||||
|
database.execSQL("CREATE TABLE IF NOT EXISTS lessonRanges (" +
|
||||||
|
"profileId INTEGER NOT NULL," +
|
||||||
|
"lessonRangeNumber INTEGER NOT NULL," +
|
||||||
|
"lessonRangeStart TEXT NOT NULL," +
|
||||||
|
"lessonRangeEnd TEXT NOT NULL," +
|
||||||
|
"PRIMARY KEY(profileId, lessonRangeNumber)" +
|
||||||
|
")");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public static AppDb getDatabase(final Context context) {
|
public static AppDb getDatabase(final Context context) {
|
||||||
@ -627,7 +641,8 @@ public abstract class AppDb extends RoomDatabase {
|
|||||||
MIGRATION_51_52,
|
MIGRATION_51_52,
|
||||||
MIGRATION_52_53,
|
MIGRATION_52_53,
|
||||||
MIGRATION_53_54,
|
MIGRATION_53_54,
|
||||||
MIGRATION_54_55
|
MIGRATION_54_55,
|
||||||
|
MIGRATION_55_56
|
||||||
)
|
)
|
||||||
.allowMainThreadQueries()
|
.allowMainThreadQueries()
|
||||||
//.fallbackToDestructiveMigration()
|
//.fallbackToDestructiveMigration()
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kuba Szczodrzyński 2019-10-5.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.db.modules.lessons
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface LessonRangeDao {
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun add(lessonRange: LessonRange)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun addAll(lessonRangeList: List<LessonRange>)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM lessonRanges WHERE profileId = :profileId")
|
||||||
|
fun getAllNow(profileId: Int): List<LessonRange>
|
||||||
|
|
||||||
|
@Query("DELETE FROM lessonRanges WHERE profileId = :profileId")
|
||||||
|
fun clear(profileId: Int)
|
||||||
|
}
|
@ -924,4 +924,5 @@
|
|||||||
<string name="agenda_teacher_absence">Nieobecni nauczyciele</string>
|
<string name="agenda_teacher_absence">Nieobecni nauczyciele</string>
|
||||||
<string name="sync_action_syncing_grade_comments">Pobieranie komentarzy ocen</string>
|
<string name="sync_action_syncing_grade_comments">Pobieranie komentarzy ocen</string>
|
||||||
<string name="settings_register_show_teacher_absences_text">Pokazuj nieobecności nauczycieli w Terminarzu</string>
|
<string name="settings_register_show_teacher_absences_text">Pokazuj nieobecności nauczycieli w Terminarzu</string>
|
||||||
|
<string name="edziennik_progress_endpoint_school_info">Pobieram informacje o szkole...</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user