From cb5eb19abc09b41405c33fa21dae1d83709f7e33 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Tue, 24 Dec 2019 12:01:09 +0100 Subject: [PATCH] [API/Timetable] Move timetableNotPublic to student data. --- .../szczodrzynski/edziennik/data/api/Regexes.kt | 6 +++--- .../api/edziennik/edudziennik/DataEdudziennik.kt | 11 +++++++++++ .../data/api/edziennik/edudziennik/Edudziennik.kt | 2 +- .../data/web/EdudziennikWebTimetable.kt | 2 ++ .../data/api/edziennik/librus/DataLibrus.kt | 15 ++++++++++++--- .../edziennik/data/api/edziennik/librus/Librus.kt | 2 +- .../librus/data/api/LibrusApiTimetables.kt | 2 ++ .../vulcan/data/api/VulcanApiTimetable.kt | 4 ++-- .../ui/modules/home/cards/HomeTimetableCard.kt | 2 +- .../ui/modules/timetable/v2/TimetableFragment.kt | 2 +- .../timetable/v2/day/TimetableDayFragment.kt | 2 +- 11 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt index 07a1d8d6..fd15132c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt @@ -79,7 +79,7 @@ object Regexes { - val VULCAN_SHITFT_ANNOTATION by lazy { + val VULCAN_SHIFT_ANNOTATION by lazy { """\(przeniesiona (z|na) lekcj[ię] ([0-9]+), (.+)\)""".toRegex() } @@ -92,10 +92,10 @@ object Regexes { val EDUDZIENNIK_STUDENTS_START by lazy { - """
  • ([\w\s]+?)""".toRegex() + """
  • (.*?)""".toRegex() } val EDUDZIENNIK_ACCOUNT_NAME_START by lazy { - """([\w\s]+?)""".toRegex() + """(.*?)""".toRegex() } val EDUDZIENNIK_SUBJECT_ID by lazy { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/DataEdudziennik.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/DataEdudziennik.kt index 9ebc44ed..8afce532 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/DataEdudziennik.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/DataEdudziennik.kt @@ -69,6 +69,17 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat get() { mWebSessionIdExpiryTime = mWebSessionIdExpiryTime ?: loginStore.getLoginData("webSessionIdExpiryTime", 0L); return mWebSessionIdExpiryTime ?: 0L } set(value) { loginStore.putLoginData("webSessionIdExpiryTime", value); mWebSessionIdExpiryTime = value } + /* ____ _ _ + / __ \| | | | + | | | | |_| |__ ___ _ __ + | | | | __| '_ \ / _ \ '__| + | |__| | |_| | | | __/ | + \____/ \__|_| |_|\___|*/ + private var mTimetableNotPublic: Boolean? = null + var timetableNotPublic: Boolean + get() { mTimetableNotPublic = mTimetableNotPublic ?: profile?.getStudentData("timetableNotPublic", false); return mTimetableNotPublic ?: false } + set(value) { profile?.putStudentData("timetableNotPublic", value) ?: return; mTimetableNotPublic = value } + val studentEndpoint: String get() = "Students/$studentId/" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/Edudziennik.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/Edudziennik.kt index 4148cf5b..3317b348 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/Edudziennik.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/Edudziennik.kt @@ -135,7 +135,7 @@ class Edudziennik(val app: App, val profile: Profile?, val loginStore: LoginStor login() } ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC -> { - loginStore.putLoginData("timetableNotPublic", true) + data.timetableNotPublic = true data() } else -> callback.onError(apiError) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTimetable.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTimetable.kt index c92790f6..ef06c58e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTimetable.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTimetable.kt @@ -137,6 +137,8 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik, d(TAG, "Clearing lessons between ${weekStart.stringY_m_d} and ${weekEnd.stringY_m_d} - timetable downloaded for $getDate") + if (data.timetableNotPublic) data.timetableNotPublic = false + data.toRemove.add(DataRemoveModel.Timetable.between(weekStart, weekEnd)) data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE, SYNC_ALWAYS) onSuccess() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/DataLibrus.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/DataLibrus.kt index 9ccdf5c6..a4ca17ba 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/DataLibrus.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/DataLibrus.kt @@ -6,12 +6,12 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.librus import okhttp3.Cookie import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.currentTimeUnix import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_LIBRUS_API import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_LIBRUS_MESSAGES import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_LIBRUS_PORTAL import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_LIBRUS_SYNERGIA import pl.szczodrzynski.edziennik.data.api.models.Data -import pl.szczodrzynski.edziennik.currentTimeUnix import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile import pl.szczodrzynski.edziennik.isNotNullNorEmpty @@ -149,7 +149,8 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app private var mApiCode: String? = null var apiCode: String? get() { mApiCode = mApiCode ?: loginStore.getLoginData("accountCode", null); return mApiCode } - set(value) { loginStore.putLoginData("accountCode", value) ?: return; mApiCode = value } + set(value) { + loginStore.putLoginData("accountCode", value); mApiCode = value } /** * A JST login PIN. * Used only during first login in JST mode. @@ -157,7 +158,8 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app private var mApiPin: String? = null var apiPin: String? get() { mApiPin = mApiPin ?: loginStore.getLoginData("accountPin", null); return mApiPin } - set(value) { loginStore.putLoginData("accountPin", value) ?: return; mApiPin = value } + set(value) { + loginStore.putLoginData("accountPin", value); mApiPin = value } /** * A Synergia API access token. @@ -256,6 +258,7 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app 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 } @@ -265,8 +268,14 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app 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 } + + private var mTimetableNotPublic: Boolean? = null + var timetableNotPublic: Boolean + get() { mTimetableNotPublic = mTimetableNotPublic ?: profile?.getStudentData("timetableNotPublic", false); return mTimetableNotPublic ?: false } + set(value) { profile?.putStudentData("timetableNotPublic", value) ?: return; mTimetableNotPublic = value } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/Librus.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/Librus.kt index 842938c6..bf33bbdb 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/Librus.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/Librus.kt @@ -204,7 +204,7 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va } // TODO PORTAL CAPTCHA ERROR_LIBRUS_API_TIMETABLE_NOT_PUBLIC -> { - loginStore.putLoginData("timetableNotPublic", true) + data.timetableNotPublic = true data() } ERROR_LIBRUS_API_LUCKY_NUMBER_NOT_ACTIVE, diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTimetables.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTimetables.kt index ce2af163..a43d6e34 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTimetables.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTimetables.kt @@ -69,6 +69,8 @@ class LibrusApiTimetables(override val data: DataLibrus, d(TAG, "Clearing lessons between ${weekStart.stringY_m_d} and ${weekEnd.stringY_m_d} - timetable downloaded for $getDate") + if (data.timetableNotPublic) data.timetableNotPublic = false + data.toRemove.add(DataRemoveModel.Timetable.between(weekStart, weekEnd)) data.setSyncNext(ENDPOINT_LIBRUS_API_TIMETABLES, SYNC_ALWAYS) onSuccess() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiTimetable.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiTimetable.kt index 41badfeb..c2ec8f97 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiTimetable.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiTimetable.kt @@ -6,7 +6,7 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api import androidx.core.util.set import pl.szczodrzynski.edziennik.* -import pl.szczodrzynski.edziennik.data.api.Regexes +import pl.szczodrzynski.edziennik.data.api.Regexes.VULCAN_SHIFT_ANNOTATION import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_TIMETABLE import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_TIMETABLE @@ -144,7 +144,7 @@ class VulcanApiTimetable(override val data: DataVulcan, val onSuccess: () -> Uni } if (type == Lesson.TYPE_SHIFTED_SOURCE || type == Lesson.TYPE_SHIFTED_TARGET) { - val shift = Regexes.VULCAN_SHITFT_ANNOTATION.find(changeAnnotation) + val shift = VULCAN_SHIFT_ANNOTATION.find(changeAnnotation) val oldLessonNumber = shift?.get(2)?.toInt() val oldLessonDate = shift?.get(3)?.let { Date.fromd_m_Y(it) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt index 28372356..14e665cc 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt @@ -115,7 +115,7 @@ class HomeTimetableCard( }) } - if (app.profile.getLoginData("timetableNotPublic", false)) { + if (app.profile.getStudentData("timetableNotPublic", false)) { b.timetableLayout.visibility = View.GONE b.notPublicLayout.visibility = View.VISIBLE return diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetableFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetableFragment.kt index 098153b1..76fdabba 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetableFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetableFragment.kt @@ -87,7 +87,7 @@ class TimetableFragment : Fragment(), CoroutineScope { if (app.profile == null || !isAdded) return@launch - if (app.profile.getLoginData("timetableNotPublic", false)) { + if (app.profile.getStudentData("timetableNotPublic", false)) { b.timetableLayout.visibility = View.GONE b.timetableNotPublicLayout.visibility = View.VISIBLE return@launch diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/day/TimetableDayFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/day/TimetableDayFragment.kt index 5ea3dec0..adee7094 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/day/TimetableDayFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/day/TimetableDayFragment.kt @@ -150,7 +150,7 @@ class TimetableDayFragment : Fragment(), CoroutineScope { } // reload the fragment when: no lessons, user wants to sync the week, the timetable is not public, pager gets removed - if (app.profile.getLoginData("timetableNotPublic", false)) { + if (app.profile.getStudentData("timetableNotPublic", false)) { activity.reloadTarget() // TODO fix for (not really)possible infinite loops return