diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt index 55b0e878..d3fd18ed 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt @@ -129,6 +129,7 @@ const val VULCAN_HEBE_ENDPOINT_REGISTER_NEW = "api/mobile/register/new" const val VULCAN_HEBE_ENDPOINT_MAIN = "api/mobile/register/hebe" const val VULCAN_HEBE_ENDPOINT_EXAMS = "api/mobile/exam" const val VULCAN_HEBE_ENDPOINT_GRADES = "api/mobile/grade" +const val VULCAN_HEBE_ENDPOINT_HOMEWORK = "api/mobile/homework" const val EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/DataVulcan.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/DataVulcan.kt index 19e28e3a..90ba3dd6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/DataVulcan.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/DataVulcan.kt @@ -8,6 +8,7 @@ import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_API import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_HEBE import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_WEB_MAIN +import pl.szczodrzynski.edziennik.data.api.LOGIN_MODE_VULCAN_API import pl.szczodrzynski.edziennik.data.api.models.Data import pl.szczodrzynski.edziennik.data.db.entity.LoginStore import pl.szczodrzynski.edziennik.data.db.entity.Profile @@ -44,7 +45,8 @@ class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app init { // during the first sync `profile.studentClassName` is already set - if (teamList.values().none { it.type == Team.TYPE_CLASS }) { + if (loginStore.mode == LOGIN_MODE_VULCAN_API + && teamList.values().none { it.type == Team.TYPE_CLASS }) { profile?.studentClassName?.also { name -> val id = Utils.crc16(name.toByteArray()).toLong() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/VulcanFeatures.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/VulcanFeatures.kt index 547037ad..466f0dcf 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/VulcanFeatures.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/VulcanFeatures.kt @@ -23,6 +23,7 @@ const val ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS = 2010 const val ENDPOINT_VULCAN_HEBE_MAIN = 3000 const val ENDPOINT_VULCAN_HEBE_EXAMS = 3030 const val ENDPOINT_VULCAN_HEBE_GRADES = 3040 +const val ENDPOINT_VULCAN_HEBE_HOMEWORK = 3060 val VulcanFeatures = listOf( // timetable @@ -48,6 +49,9 @@ val VulcanFeatures = listOf( Feature(LOGIN_TYPE_VULCAN, FEATURE_HOMEWORK, listOf( ENDPOINT_VULCAN_API_HOMEWORK to LOGIN_METHOD_VULCAN_API ), listOf(LOGIN_METHOD_VULCAN_API)), + Feature(LOGIN_TYPE_VULCAN, FEATURE_HOMEWORK, listOf( + ENDPOINT_VULCAN_HEBE_HOMEWORK to LOGIN_METHOD_VULCAN_HEBE + ), listOf(LOGIN_METHOD_VULCAN_HEBE)), // behaviour Feature(LOGIN_TYPE_VULCAN, FEATURE_BEHAVIOUR, listOf( ENDPOINT_VULCAN_API_NOTICES to LOGIN_METHOD_VULCAN_API diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanData.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanData.kt index d0b93a27..fb568815 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanData.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanData.kt @@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.* import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.* import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeExams import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeGrades +import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeHomework import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.web.VulcanWebLuckyNumber import pl.szczodrzynski.edziennik.utils.Utils @@ -101,6 +102,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) { data.startProgress(R.string.edziennik_progress_endpoint_grades) VulcanHebeGrades(data, lastSync, onSuccess) } + ENDPOINT_VULCAN_HEBE_HOMEWORK -> { + data.startProgress(R.string.edziennik_progress_endpoint_homework) + VulcanHebeHomework(data, lastSync, onSuccess) + } else -> onSuccess(endpointId) } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanHebe.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanHebe.kt index 526099b4..d8df2f8c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanHebe.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanHebe.kt @@ -82,12 +82,16 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) { val team = json.getJsonObject(key) val teamId = team.getLong("Id") ?: return null if (data.teamList[teamId] == null) { + var name = team.getString("Shortcut") + ?: team.getString("Name") + ?: "" + name = "${profile?.studentClassName ?: ""} $name" data.teamList[teamId] = Team( data.profileId, teamId, - team.getString("Name") ?: "", + name, Team.TYPE_VIRTUAL, - team.getString("Shortcut") ?: "", + "${data.schoolCode}:$name", -1 ) } @@ -106,7 +110,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) { teamId, name, Team.TYPE_CLASS, - name, + "${data.schoolCode}:$name", -1 ) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeHomework.kt new file mode 100644 index 00000000..5e7f3e33 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeHomework.kt @@ -0,0 +1,71 @@ +package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe + +import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_HOMEWORK +import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan +import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_HOMEWORK +import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe +import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel +import pl.szczodrzynski.edziennik.data.db.entity.Event +import pl.szczodrzynski.edziennik.data.db.entity.Metadata +import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS +import pl.szczodrzynski.edziennik.getLong +import pl.szczodrzynski.edziennik.getString + +class VulcanHebeHomework( + override val data: DataVulcan, + override val lastSync: Long?, + val onSuccess: (endpointId: Int) -> Unit +) : VulcanHebe(data, lastSync) { + companion object { + const val TAG = "VulcanHebeHomework" + } + + init { + apiGetList( + TAG, + VULCAN_HEBE_ENDPOINT_HOMEWORK, + HebeFilterType.BY_PUPIL, + lastSync = lastSync + ) { list, _ -> + list.forEach { exam -> + val id = exam.getLong("IdHomework") ?: return@forEach + val eventDate = getDate(exam, "Deadline") ?: return@forEach + val subjectId = getSubjectId(exam, "Subject") + val teacherId = getTeacherId(exam, "Creator") + val teamId = data.teamClass?.id ?: -1 + val topic = exam.getString("Content")?.trim() ?: "" + + val lessonList = data.db.timetableDao().getAllForDateNow(profileId, eventDate) + val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.startTime + + val eventObject = Event( + profileId = profileId, + id = id, + date = eventDate, + time = startTime, + topic = topic, + color = null, + type = Event.TYPE_HOMEWORK, + teacherId = teacherId, + subjectId = subjectId, + teamId = teamId + ) + + data.eventList.add(eventObject) + data.metadataList.add( + Metadata( + profileId, + Metadata.TYPE_HOMEWORK, + id, + profile?.empty ?: true, + profile?.empty ?: true + ) + ) + } + + data.toRemove.add(DataRemoveModel.Events.futureWithType(Event.TYPE_HOMEWORK)) + data.setSyncNext(ENDPOINT_VULCAN_HEBE_HOMEWORK, SYNC_ALWAYS) + onSuccess(ENDPOINT_VULCAN_HEBE_HOMEWORK) + } + } +}