From 0e8b0673ca2013a7bf04d97cb9ea0ab4b5be6acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Mon, 8 Jul 2024 13:28:47 +0200 Subject: [PATCH] [App] Add Demo login method --- .../data/api/edziennik/EdziennikTask.kt | 2 + .../edziennik/data/api/edziennik/demo/Demo.kt | 84 +++++++++++++++++++ .../edziennik/data/db/enums/LoginMode.kt | 1 + .../edziennik/data/db/enums/LoginType.kt | 2 +- .../edziennik/ext/ProfileExtensions.kt | 3 + .../ui/login/LoginChooserFragment.kt | 14 ++-- .../edziennik/ui/login/LoginInfo.kt | 15 ++++ app/src/main/res/values-en/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 9 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/demo/Demo.kt diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/EdziennikTask.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/EdziennikTask.kt index e90813f2..44d0fca2 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/EdziennikTask.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/EdziennikTask.kt @@ -9,6 +9,7 @@ import org.greenrobot.eventbus.EventBus import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.data.api.ERROR_PROFILE_ARCHIVED +import pl.szczodrzynski.edziennik.data.api.edziennik.demo.Demo import pl.szczodrzynski.edziennik.data.api.edziennik.librus.Librus import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.Mobidziennik import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.Podlasie @@ -120,6 +121,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa LoginType.PODLASIE -> Podlasie(app, profile, loginStore, taskCallback) LoginType.TEMPLATE -> Template(app, profile, loginStore, taskCallback) LoginType.USOS -> Usos(app, profile, loginStore, taskCallback) + LoginType.DEMO -> Demo(app, profile, loginStore, taskCallback) else -> null } if (edziennikInterface == null) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/demo/Demo.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/demo/Demo.kt new file mode 100644 index 00000000..3858a885 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/demo/Demo.kt @@ -0,0 +1,84 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2024-7-8. + */ + +package pl.szczodrzynski.edziennik.data.api.edziennik.demo + +import com.google.gson.JsonObject +import org.greenrobot.eventbus.EventBus +import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.data.api.events.FirstLoginFinishedEvent +import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback +import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface +import pl.szczodrzynski.edziennik.data.db.entity.LoginStore +import pl.szczodrzynski.edziennik.data.db.entity.Profile +import pl.szczodrzynski.edziennik.data.db.entity.Teacher +import pl.szczodrzynski.edziennik.data.db.enums.FeatureType +import pl.szczodrzynski.edziennik.data.db.enums.LoginType +import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull +import pl.szczodrzynski.edziennik.data.db.full.EventFull +import pl.szczodrzynski.edziennik.data.db.full.MessageFull + +class Demo( + val app: App, + val profile: Profile?, + val loginStore: LoginStore, + val callback: EdziennikCallback, +) : EdziennikInterface { + + private fun completed() { + callback.onCompleted() + } + + override fun sync( + featureTypes: Set?, + onlyEndpoints: Set?, + arguments: JsonObject?, + ) = completed() + + override fun getMessage(message: MessageFull) = + completed() + + override fun sendMessage(recipients: Set, subject: String, text: String) = + completed() + + override fun markAllAnnouncementsAsRead() = + completed() + + override fun getAnnouncement(announcement: AnnouncementFull) = + completed() + + override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) = + completed() + + override fun getRecipientList() = + completed() + + override fun getEvent(eventFull: EventFull) = + completed() + + override fun firstLogin() { + val profile = Profile( + id = loginStore.id, + loginStoreId = loginStore.id, + loginStoreType = LoginType.DEMO, + name = "Jan Szkolny", + subname = "Szkolny.eu", + studentNameLong = "Jan Szkolny", + studentNameShort = "Jan S.", + accountName = null, + ) + profile.apply { + empty = false + syncEnabled = false + registration = Profile.REGISTRATION_DISABLED + studentClassName = "1A" + userCode = "nologin:1234" + dateYearEnd.month = 8 + } + EventBus.getDefault().postSticky(FirstLoginFinishedEvent(listOf(profile), loginStore)) + completed() + } + + override fun cancel() {} +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/enums/LoginMode.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/enums/LoginMode.kt index 9deb5310..a8c096d2 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/enums/LoginMode.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/enums/LoginMode.kt @@ -17,4 +17,5 @@ enum class LoginMode( VULCAN_HEBE(LoginType.VULCAN, id = 402), PODLASIE_API(LoginType.PODLASIE, id = 600), USOS_OAUTH(LoginType.USOS, id = 700), + DEMO(LoginType.DEMO, id = 800), } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/enums/LoginType.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/enums/LoginType.kt index de0ca2f8..20bc112a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/enums/LoginType.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/enums/LoginType.kt @@ -14,7 +14,7 @@ enum class LoginType( VULCAN(id = 4, features = FEATURES_VULCAN), PODLASIE(id = 6, features = FEATURES_PODLASIE), USOS(id = 7, features = FEATURES_USOS, schoolType = SchoolType.UNIVERSITY), - DEMO(id = 20, features = setOf()), + DEMO(id = 8, features = setOf()), TEMPLATE(id = 21, features = setOf()), // the graveyard diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ext/ProfileExtensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ext/ProfileExtensions.kt index a2ef0289..186a28bd 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ext/ProfileExtensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ext/ProfileExtensions.kt @@ -17,6 +17,7 @@ import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.config.AppData import pl.szczodrzynski.edziennik.data.db.entity.Profile import pl.szczodrzynski.edziennik.data.db.enums.FeatureType +import pl.szczodrzynski.edziennik.data.db.enums.LoginType import pl.szczodrzynski.edziennik.utils.ProfileImageHolder import pl.szczodrzynski.edziennik.utils.models.Date import pl.szczodrzynski.navlib.ImageHolder @@ -71,6 +72,8 @@ fun Profile.getAppData() = if (App.profileId == this.id) App.data else AppData.get(this.loginStoreType) fun Profile.shouldArchive(): Boolean { + if (loginStoreType == LoginType.DEMO) + return false // vulcan hotfix if (dateYearEnd.month > 6) { dateYearEnd.month = 6 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginChooserFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginChooserFragment.kt index f48258a9..54aaf81d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginChooserFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginChooserFragment.kt @@ -197,7 +197,7 @@ class LoginChooserFragment : Fragment(), CoroutineScope { adapter.items.removeAll { it !is LoginInfo.Register } adapter.items.add( LoginInfo.Register( - loginType = LoginType.DEMO, + loginType = LoginType.TEMPLATE, registerName = R.string.eggs, registerLogo = R.drawable.face_1, loginModes = listOf( @@ -241,13 +241,13 @@ class LoginChooserFragment : Fragment(), CoroutineScope { loginType: LoginInfo.Register, loginMode: LoginInfo.Mode ) { - if (loginType.loginType == LoginType.DEMO) { - nav.navigate(R.id.loginEggsFragment, null, activity.navOptions) - return - } - if (loginType.loginType == LoginType.TEMPLATE) { - nav.navigate(R.id.labFragment, null, activity.navOptions) + when (loginType.registerName) { + R.string.eggs -> + nav.navigate(R.id.loginEggsFragment, null, activity.navOptions) + R.string.menu_lab -> + nav.navigate(R.id.labFragment, null, activity.navOptions) + } return } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginInfo.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginInfo.kt index 33e191d7..ac311efc 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginInfo.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginInfo.kt @@ -328,6 +328,21 @@ object LoginInfo { ), ), ), + Register( + loginType = LoginType.DEMO, + registerName = R.string.login_type_demo, + registerLogo = R.mipmap.ic_launcher, + loginModes = listOf( + Mode( + loginMode = LoginMode.DEMO, + name = R.string.login_mode_demo, + icon = R.mipmap.ic_launcher, + guideText = R.string.login_mode_demo, + credentials = listOf(), + errorCodes = mapOf(), + ), + ), + ), ) } diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index ff2c1c3a..dea85350 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -1433,4 +1433,6 @@ Agenda settings Share notes All lessons: + Use without login + Demo version diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e4204e21..9731a603 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1553,4 +1553,6 @@ Wszystkie lekcje: Wyświetl nazwę przedmiotu zamiast rodzaju Odśwież wybrany tydzień + Użyj bez logowania + Wersja demonstracyjna