[App] Add Demo login method

This commit is contained in:
Kuba Szczodrzyński 2024-07-08 13:28:47 +02:00
parent cefb0deba8
commit 0e8b0673ca
No known key found for this signature in database
GPG Key ID: 43037AC62A600562
9 changed files with 117 additions and 8 deletions

View File

@ -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) {

View File

@ -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<FeatureType>?,
onlyEndpoints: Set<Int>?,
arguments: JsonObject?,
) = completed()
override fun getMessage(message: MessageFull) =
completed()
override fun sendMessage(recipients: Set<Teacher>, 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() {}
}

View File

@ -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),
}

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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(),
),
),
),
)
}

View File

@ -1433,4 +1433,6 @@
<string name="menu_agenda_config">Agenda settings</string>
<string name="registration_config_note_sharing_title">Share notes</string>
<string name="home_timetable_all_lessons">All lessons:</string>
<string name="login_type_demo">Use without login</string>
<string name="login_mode_demo">Demo version</string>
</resources>

View File

@ -1553,4 +1553,6 @@
<string name="home_timetable_all_lessons">Wszystkie lekcje:</string>
<string name="agenda_config_subject_important">Wyświetl nazwę przedmiotu zamiast rodzaju</string>
<string name="menu_timetable_sync">Odśwież wybrany tydzień</string>
<string name="login_type_demo">Użyj bez logowania</string>
<string name="login_mode_demo">Wersja demonstracyjna</string>
</resources>