diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index 5c251a37..c9e2d7c6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -391,4 +391,21 @@ fun List.concat(delimiter: String? = null): CharSequence { fun TextView.setText(@StringRes resid: Int, vararg formatArgs: Any) { text = context.getString(resid, *formatArgs) -} \ No newline at end of file +} + +fun JsonObject(vararg properties: Pair): JsonObject { + return JsonObject().apply { + for (property in properties) { + when (property.second) { + is JsonElement -> add(property.first, property.second as JsonElement) + is String -> addProperty(property.first, property.second as String) + is Char -> addProperty(property.first, property.second as Char) + is Number -> addProperty(property.first, property.second as Number) + is Boolean -> addProperty(property.first, property.second as Boolean) + } + } + } +} + +fun JsonArray?.isNullOrEmpty(): Boolean = (this?.size() ?: 0) == 0 +fun JsonArray.isEmpty(): Boolean = this.size() == 0 \ No newline at end of file diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/events/task/EdziennikTask.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/events/task/EdziennikTask.kt index 0e8e945b..6fd170ca 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/events/task/EdziennikTask.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/events/task/EdziennikTask.kt @@ -1,5 +1,6 @@ package pl.szczodrzynski.edziennik.api.v2.events.task +import com.google.gson.JsonObject import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.api.v2.* @@ -18,7 +19,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa fun firstLogin(loginStore: LoginStore) = EdziennikTask(-1, FirstLoginRequest(loginStore)) fun sync() = EdziennikTask(-1, SyncRequest()) - fun syncProfile(profileId: Int, viewIds: List>? = null) = EdziennikTask(profileId, SyncProfileRequest(viewIds)) + fun syncProfile(profileId: Int, viewIds: List>? = null, arguments: JsonObject? = null) = EdziennikTask(profileId, SyncProfileRequest(viewIds, arguments)) fun syncProfileList(profileList: List) = EdziennikTask(-1, SyncProfileListRequest(profileList)) fun messageGet(profileId: Int, messageId: Int) = EdziennikTask(profileId, MessageGetRequest(messageId)) fun announcementsRead(profileId: Int) = EdziennikTask(profileId, AnnouncementsReadRequest()) @@ -50,7 +51,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa private var edziennikInterface: EdziennikInterface? = null - fun run(app: App, taskCallback: EdziennikCallback) { + internal fun run(app: App, taskCallback: EdziennikCallback) { edziennikInterface = when (loginStore.type) { LOGIN_TYPE_LIBRUS -> Librus(app, profile, loginStore, taskCallback) LOGIN_TYPE_MOBIDZIENNIK -> Mobidziennik(app, profile, loginStore, taskCallback) @@ -66,7 +67,8 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa when (request) { is SyncProfileRequest -> edziennikInterface?.sync( featureIds = request.viewIds?.flatMap { Features.getIdsByView(it.first, it.second) } ?: Features.getAllIds(), - viewId = request.viewIds?.get(0)?.first) + viewId = request.viewIds?.get(0)?.first, + arguments = request.arguments) is MessageGetRequest -> edziennikInterface?.getMessage(request.messageId) is FirstLoginRequest -> edziennikInterface?.firstLogin() is AnnouncementsReadRequest -> edziennikInterface?.markAllAnnouncementsAsRead() @@ -83,7 +85,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa data class FirstLoginRequest(val loginStore: LoginStore) class SyncRequest - data class SyncProfileRequest(val viewIds: List>? = null) + data class SyncProfileRequest(val viewIds: List>? = null, val arguments: JsonObject? = null) data class SyncProfileListRequest(val profileList: List) data class MessageGetRequest(val messageId: Int) class AnnouncementsReadRequest diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/idziennik/Idziennik.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/idziennik/Idziennik.kt index 03b1bbf0..3667a2c6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/idziennik/Idziennik.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/idziennik/Idziennik.kt @@ -4,6 +4,7 @@ package pl.szczodrzynski.edziennik.api.v2.idziennik +import com.google.gson.JsonObject import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410 import pl.szczodrzynski.edziennik.api.v2.idziennik.data.IdziennikData @@ -48,7 +49,8 @@ class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore, |_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| __/ | |__*/ - override fun sync(featureIds: List, viewId: Int?) { + override fun sync(featureIds: List, viewId: Int?, arguments: JsonObject?) { + data.arguments = arguments data.prepare(idziennikLoginMethods, IdziennikFeatures, featureIds, viewId) d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}") d(TAG, "Endpoint IDs: ${data.targetEndpointIds}") diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/interfaces/EdziennikInterface.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/interfaces/EdziennikInterface.kt index 935b778d..80596d2a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/interfaces/EdziennikInterface.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/interfaces/EdziennikInterface.kt @@ -4,8 +4,10 @@ package pl.szczodrzynski.edziennik.api.v2.interfaces +import com.google.gson.JsonObject + interface EdziennikInterface { - fun sync(featureIds: List, viewId: Int? = null) + fun sync(featureIds: List, viewId: Int? = null, arguments: JsonObject? = null) fun getMessage(messageId: Int) fun markAllAnnouncementsAsRead() fun firstLogin() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/Librus.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/Librus.kt index eeb2b759..dc55fa1a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/Librus.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/Librus.kt @@ -4,6 +4,7 @@ package pl.szczodrzynski.edziennik.api.v2.librus +import com.google.gson.JsonObject import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.api.v2.* import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback @@ -49,7 +50,8 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va |_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| __/ | |__*/ - override fun sync(featureIds: List, viewId: Int?) { + override fun sync(featureIds: List, viewId: Int?, arguments: JsonObject?) { + data.arguments = arguments data.prepare(librusLoginMethods, LibrusFeatures, featureIds, viewId) login() } @@ -173,7 +175,10 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va login() } // TODO PORTAL CAPTCHA - ERROR_LIBRUS_API_TIMETABLE_NOT_PUBLIC, + ERROR_LIBRUS_API_TIMETABLE_NOT_PUBLIC -> { + loginStore.putLoginData("timetableNotPublic", true) + data() + } ERROR_LIBRUS_API_LUCKY_NUMBER_NOT_ACTIVE, ERROR_LIBRUS_API_NOTES_NOT_ACTIVE -> { data() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTimetables.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTimetables.kt index ceb4b2b2..898e5ea7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTimetables.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTimetables.kt @@ -4,11 +4,13 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api +import androidx.core.util.isEmpty import com.google.gson.JsonObject import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_TIMETABLES import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi +import pl.szczodrzynski.edziennik.api.v2.models.DataRemoveModel import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson @@ -22,20 +24,42 @@ class LibrusApiTimetables(override val data: DataLibrus, } init { - apiGet(TAG, "Timetables") { json -> + if (data.classrooms.isEmpty()) { + data.db.classroomDao().getAllNow(profileId).toSparseArray(data.classrooms) { it.id } + } + + val currentWeekStart = Date.getToday().let { it.stepForward(0, 0, -it.weekDay) } + val getDate = data.arguments?.getString("weekStart") ?: currentWeekStart.stringY_m_d + apiGet(TAG, "Timetables?weekStart=$getDate") { json -> val days = json.getJsonObject("Timetable") days?.entrySet()?.forEach { (dateString, dayEl) -> - val lessonDate = dateString?.let { Date.fromY_m_d(it) } ?: return@forEach val day = dayEl?.asJsonArray + + val lessonDate = dateString?.let { Date.fromY_m_d(it) } ?: return@forEach + + var lessonsFound = false day?.forEach { lessonRangeEl -> val lessonRange = lessonRangeEl?.asJsonArray?.asJsonObjectList() + if (lessonRange?.isNullOrEmpty() == false) + lessonsFound = true lessonRange?.forEachIndexed { index, lesson -> parseLesson(lessonDate, lesson) } } + + if (day.isNullOrEmpty() || !lessonsFound) { + data.lessonNewList += Lesson(profileId, lessonDate.inUnix).apply { + type = Lesson.TYPE_NO_LESSONS + date = lessonDate + } + } } + val weekStart = Date.fromY_m_d(getDate) + val weekEnd = weekStart.clone().stepForward(0, 0, 6) + + 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/api/v2/mobidziennik/Mobidziennik.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/mobidziennik/Mobidziennik.kt index 337da3b2..7a652392 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/mobidziennik/Mobidziennik.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/mobidziennik/Mobidziennik.kt @@ -4,6 +4,7 @@ package pl.szczodrzynski.edziennik.api.v2.mobidziennik +import com.google.gson.JsonObject import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410 import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback @@ -48,7 +49,8 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto |_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| __/ | |__*/ - override fun sync(featureIds: List, viewId: Int?) { + override fun sync(featureIds: List, viewId: Int?, arguments: JsonObject?) { + data.arguments = arguments data.prepare(mobidziennikLoginMethods, MobidziennikFeatures, featureIds, viewId) d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}") d(TAG, "Endpoint IDs: ${data.targetEndpointIds}") diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt index 2db316d3..a176ecd1 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt @@ -57,6 +57,8 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) val profileId get() = profile?.id ?: -1 + var arguments: JsonObject? = null + /** * A callback passed to all [Feature]s and [LoginMethod]s */ @@ -130,24 +132,20 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) mTeamClass = value } - var lessonsToRemove: DataRemoveModel? = null + var toRemove = mutableListOf() + val lessonList = mutableListOf() val lessonChangeList = mutableListOf() val lessonNewList = mutableListOf() - var gradesToRemove: DataRemoveModel? = null val gradeList = mutableListOf() - var eventsToRemove: DataRemoveModel? = null val eventList = mutableListOf() - var noticesToRemove: DataRemoveModel? = null val noticeList = mutableListOf() - var attendancesToRemove: DataRemoveModel? = null val attendanceList = mutableListOf() - var announcementsToRemove: DataRemoveModel? = null val announcementList = mutableListOf() val luckyNumberList = mutableListOf() @@ -250,6 +248,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) app.profile.loginStoreData = loginStore.data } + // always present and not empty, during every sync db.endpointTimerDao().addAll(endpointTimers) db.teacherDao().clear(profileId) db.teacherDao().addAll(teacherList.values()) @@ -262,6 +261,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) db.gradeCategoryDao().clear(profileId) db.gradeCategoryDao().addAll(gradeCategories.values()) + // may be empty - extracted from DB on demand, by an endpoint if (classrooms.size > 0) db.classroomDao().addAll(classrooms.values()) if (attendanceTypes.size > 0) @@ -273,11 +273,15 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) if (teacherAbsenceTypes.size > 0) db.teacherAbsenceTypeDao().addAll(teacherAbsenceTypes.values()) - gradesToRemove?.let { it -> - it.removeAll?.let { _ -> db.gradeDao().clear(profileId) } - it.removeSemester?.let { semester -> db.gradeDao().clearForSemester(profileId, semester) } + // clear DB with DataRemoveModels added by endpoints + for (model in toRemove) { + when (model) { + is DataRemoveModel.Timetable -> model.commit(profileId, db.timetableDao()) + is DataRemoveModel.Grades -> model.commit(profileId, db.gradeDao()) + } } + // not extracted from DB - always new data if (lessonList.isNotEmpty()) { db.lessonDao().clear(profile.id) db.lessonDao().addAll(lessonList) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/DataRemoveModel.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/DataRemoveModel.kt index 1e97d733..c23b28d9 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/DataRemoveModel.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/DataRemoveModel.kt @@ -4,28 +4,37 @@ package pl.szczodrzynski.edziennik.api.v2.models +import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeDao +import pl.szczodrzynski.edziennik.data.db.modules.timetable.TimetableDao import pl.szczodrzynski.edziennik.utils.models.Date -class DataRemoveModel { - var removeAll: Boolean? = null - var removeSemester: Int? = null - var removeDateFrom: Date? = null - var removeDateTo: Date? = null - - constructor() { - this.removeAll = true +open class DataRemoveModel { + class Timetable(private val dateFrom: Date?, private val dateTo: Date?) : DataRemoveModel() { + companion object { + fun from(dateFrom: Date) = Timetable(dateFrom, null) + fun to(dateTo: Date) = Timetable(null, dateTo) + fun between(dateFrom: Date, dateTo: Date) = Timetable(dateFrom, dateTo) + } + fun commit(profileId: Int, dao: TimetableDao) { + if (dateFrom != null && dateTo != null) { + dao.clearBetweenDates(profileId, dateFrom, dateTo) + } + else { + dateFrom?.let { dateFrom -> dao.clearFromDate(profileId, dateFrom) } + dateTo?.let { dateTo -> dao.clearToDate(profileId, dateTo) } + } + } } - - constructor(semester: Int) { - this.removeSemester = semester - } - - constructor(dateFrom: Date?, dateTo: Date) { - this.removeDateFrom = dateFrom - this.removeDateTo = dateTo - } - - constructor(dateFrom: Date) { - this.removeDateFrom = dateFrom + class Grades(val all: Boolean, val semester: Int?) : DataRemoveModel() { + companion object { + fun all() = Grades(true, null) + fun semester(semester: Int) = Grades(false, semester) + } + fun commit(profileId: Int, dao: GradeDao) { + if (all) { + dao.clear(profileId) + } + semester?.let { dao.clearForSemester(profileId, it) } + } } } \ No newline at end of file diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/template/Template.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/template/Template.kt index 9e80c2bf..a7d44574 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/template/Template.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/template/Template.kt @@ -4,6 +4,7 @@ package pl.szczodrzynski.edziennik.api.v2.template +import com.google.gson.JsonObject import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410 import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback @@ -48,7 +49,8 @@ class Template(val app: App, val profile: Profile?, val loginStore: LoginStore, |_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| __/ | |__*/ - override fun sync(featureIds: List, viewId: Int?) { + override fun sync(featureIds: List, viewId: Int?, arguments: JsonObject?) { + data.arguments = arguments data.prepare(templateLoginMethods, TemplateFeatures, featureIds, viewId) d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}") d(TAG, "Endpoint IDs: ${data.targetEndpointIds}") diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/Vulcan.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/Vulcan.kt index 209fec47..9a7167a9 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/Vulcan.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/Vulcan.kt @@ -4,6 +4,7 @@ package pl.szczodrzynski.edziennik.api.v2.vulcan +import com.google.gson.JsonObject import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410 import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback @@ -48,7 +49,8 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va |_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| __/ | |__*/ - override fun sync(featureIds: List, viewId: Int?) { + override fun sync(featureIds: List, viewId: Int?, arguments: JsonObject?) { + data.arguments = arguments data.prepare(vulcanLoginMethods, VulcanFeatures, featureIds, viewId) d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}") d(TAG, "Endpoint IDs: ${data.targetEndpointIds}") diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/timetable/Lesson.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/timetable/Lesson.kt index abc75820..38834b30 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/timetable/Lesson.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/timetable/Lesson.kt @@ -17,6 +17,7 @@ import pl.szczodrzynski.edziennik.utils.models.Time ]) open class Lesson(val profileId: Int, @PrimaryKey val id: Long) { companion object { + const val TYPE_NO_LESSONS = -1 const val TYPE_NORMAL = 0 const val TYPE_CANCELLED = 1 const val TYPE_CHANGE = 2 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/timetable/TimetableDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/timetable/TimetableDao.kt index f9ab8b84..f5beeaf3 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/timetable/TimetableDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/timetable/TimetableDao.kt @@ -17,6 +17,13 @@ interface TimetableDao { @Query("DELETE FROM timetable WHERE profileId = :profileId") fun clear(profileId: Int) + @Query("DELETE FROM timetable WHERE profileId = :profileId AND (type != 3 AND date >= :dateFrom) OR ((type = 3 OR type = 1) AND oldDate >= :dateFrom)") + fun clearFromDate(profileId: Int, dateFrom: Date) + @Query("DELETE FROM timetable WHERE profileId = :profileId AND (type != 3 AND date <= :dateTo) OR ((type = 3 OR type = 1) AND oldDate <= :dateTo)") + fun clearToDate(profileId: Int, dateTo: Date) + @Query("DELETE FROM timetable WHERE profileId = :profileId AND (type != 3 AND date >= :dateFrom AND date <= :dateTo) OR ((type = 3 OR type = 1) AND oldDate >= :dateFrom AND oldDate <= :dateTo)") + fun clearBetweenDates(profileId: Int, dateFrom: Date, dateTo: Date) + @Query(""" SELECT timetable.*, diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java b/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java index 6347b1e1..45630fe9 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java @@ -112,7 +112,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { app.notifier.postAll(profile); app.saveConfig("notifications");*/ d(TAG, "Syncing profile " + profile.getId()); - EdziennikTask.Companion.syncProfile(profile.getId(), null).enqueue(app); + EdziennikTask.Companion.syncProfile(profile.getId(), null, null).enqueue(app); } else { /*app.notifier.add(new Notification(app.getContext(), remoteMessage.getData().get("message")) .withProfileData(profile.id, profile.name) @@ -123,7 +123,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { app.notifier.postAll(profile); app.saveConfig("notifications");*/ d(TAG, "Syncing profile " + profile.getId()); - EdziennikTask.Companion.syncProfile(profile.getId(), null).enqueue(app); + EdziennikTask.Companion.syncProfile(profile.getId(), null, null).enqueue(app); } } }); 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 b29a7e72..31b40e52 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 @@ -10,6 +10,7 @@ import com.mikepenz.iconics.typeface.library.community.material.CommunityMateria import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.MainActivity import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.api.v2.LOGIN_TYPE_LIBRUS import pl.szczodrzynski.edziennik.databinding.FragmentTimetableV2Binding import pl.szczodrzynski.edziennik.utils.Themes import pl.szczodrzynski.edziennik.utils.models.Date @@ -42,6 +43,14 @@ class TimetableFragment : Fragment() { if (app.profile == null || !isAdded) return + if (app.profile.loginStoreType == LOGIN_TYPE_LIBRUS && app.profile.getLoginData("timetableNotPublic", false)) { + b.timetableLayout.visibility = View.GONE + b.timetableNotPublicLayout.visibility = View.VISIBLE + return + } + b.timetableLayout.visibility = View.VISIBLE + b.timetableNotPublicLayout.visibility = View.GONE + val items = mutableListOf() val monthDayCount = listOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) 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 817774cf..4642aa9e 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 @@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import com.linkedin.android.tachyon.DayView import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.api.v2.events.task.EdziennikTask import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull import pl.szczodrzynski.edziennik.databinding.FragmentTimetableV2DayBinding @@ -45,7 +46,6 @@ class TimetableDayFragment(val date: Date) : Fragment() { return Log.d(TAG, "onViewCreated, date=$date") - b.date.text = date.formattedString // Inflate a label view for each hour the day view will display val hourLabelViews = ArrayList() @@ -62,6 +62,31 @@ class TimetableDayFragment(val date: Date) : Fragment() { } private fun buildLessonViews(lessons: List) { + if (lessons.isEmpty()) { + b.dayScroll.visibility = View.GONE + b.noTimetableLayout.visibility = View.VISIBLE + b.noLessonsLayout.visibility = View.GONE + b.noTimetableSync.setOnClickListener { + EdziennikTask.syncProfile( + profileId = App.profileId, + arguments = JsonObject( + "weekStart" to date.clone().stepForward(0, 0, -date.weekDay).stringY_m_d + ) + ).enqueue(activity) + } + return + } + if (lessons.size == 1 && lessons[0].type == Lesson.TYPE_NO_LESSONS) { + b.dayScroll.visibility = View.GONE + b.noTimetableLayout.visibility = View.GONE + b.noLessonsLayout.visibility = View.VISIBLE + return + } + + b.dayScroll.visibility = View.VISIBLE + b.noTimetableLayout.visibility = View.GONE + b.noLessonsLayout.visibility = View.GONE + val eventViews = mutableListOf() val eventTimeRanges = mutableListOf() diff --git a/app/src/main/res/drawable/ic_no_timetable.xml b/app/src/main/res/drawable/ic_no_timetable.xml new file mode 100644 index 00000000..8c93d926 --- /dev/null +++ b/app/src/main/res/drawable/ic_no_timetable.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_sync.xml b/app/src/main/res/drawable/ic_sync.xml new file mode 100644 index 00000000..2374a3e5 --- /dev/null +++ b/app/src/main/res/drawable/ic_sync.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_timetable.xml b/app/src/main/res/drawable/ic_timetable.xml new file mode 100644 index 00000000..9bd05e1e --- /dev/null +++ b/app/src/main/res/drawable/ic_timetable.xml @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_timetable_v2.xml b/app/src/main/res/layout/fragment_timetable_v2.xml index 78893ddf..56644931 100644 --- a/app/src/main/res/layout/fragment_timetable_v2.xml +++ b/app/src/main/res/layout/fragment_timetable_v2.xml @@ -1,15 +1,16 @@ - + + android:layout_height="match_parent"> + android:layout_height="match_parent" + tools:visibility="gone"> - + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_timetable_v2_day.xml b/app/src/main/res/layout/fragment_timetable_v2_day.xml index 9912a5ef..2fa0f81a 100644 --- a/app/src/main/res/layout/fragment_timetable_v2_day.xml +++ b/app/src/main/res/layout/fragment_timetable_v2_day.xml @@ -1,24 +1,16 @@ - + - - - - + app:startHour="5" + tools:visibility="gone"/> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file