From a5bb7d9c6e46377224b743bda4a00b61ada16bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Wed, 24 Feb 2021 21:53:59 +0100 Subject: [PATCH] [Lab] Add option to full sync and clear profile. --- .../ui/dialogs/settings/ProfileRemoveDialog.kt | 14 +++++++++----- .../ui/modules/debug/LabPageFragment.kt | 10 ++++++++++ .../modules/settings/SettingsNewFragment.java | 2 +- app/src/main/res/layout/lab_fragment.xml | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/ProfileRemoveDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/ProfileRemoveDialog.kt index 14321317..1fa16230 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/ProfileRemoveDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/ProfileRemoveDialog.kt @@ -17,7 +17,8 @@ import kotlin.coroutines.CoroutineContext class ProfileRemoveDialog( val activity: MainActivity, val profileId: Int, - val profileName: String + val profileName: String, + val noProfileRemoval: Boolean = false ) : CoroutineScope { companion object { private const val TAG = "ProfileRemoveDialog" @@ -52,7 +53,6 @@ class ProfileRemoveDialog( app.db.attendanceDao().clear(profileId) app.db.attendanceTypeDao().clear(profileId) app.db.classroomDao().clear(profileId) - app.db.configDao().clear(profileId) app.db.endpointTimerDao().clear(profileId) app.db.eventDao().clear(profileId) app.db.eventTypeDao().clear(profileId) @@ -65,23 +65,27 @@ class ProfileRemoveDialog( app.db.messageRecipientDao().clear(profileId) app.db.noticeDao().clear(profileId) app.db.noticeTypeDao().clear(profileId) - app.db.noticeTypeDao().clear(profileId) app.db.notificationDao().clear(profileId) app.db.subjectDao().clear(profileId) app.db.teacherAbsenceDao().clear(profileId) - app.db.teacherAbsenceDao().clear(profileId) app.db.teacherAbsenceTypeDao().clear(profileId) app.db.teacherDao().clear(profileId) app.db.teamDao().clear(profileId) app.db.timetableDao().clear(profileId) + app.db.metadataDao().deleteAll(profileId) + + if (noProfileRemoval) + return@async + + app.db.configDao().clear(profileId) + val loginStoreId = profileObject.loginStoreId val profilesUsingLoginStore = app.db.profileDao().getIdsByLoginStoreIdNow(loginStoreId) if (profilesUsingLoginStore.size == 1) { app.db.loginStoreDao().remove(loginStoreId) } app.db.profileDao().remove(profileId) - app.db.metadataDao().deleteAll(profileId) if (App.profileId == profileId) { app.profileLoadLast { } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabPageFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabPageFragment.kt index c6fbcbc6..29a0b2b3 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabPageFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabPageFragment.kt @@ -16,6 +16,7 @@ import kotlinx.coroutines.launch import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.data.db.entity.Event import pl.szczodrzynski.edziennik.databinding.LabFragmentBinding +import pl.szczodrzynski.edziennik.ui.dialogs.settings.ProfileRemoveDialog import pl.szczodrzynski.edziennik.ui.modules.base.lazypager.LazyFragment import pl.szczodrzynski.edziennik.utils.TextInputDropDown import pl.szczodrzynski.fslogin.decode @@ -60,6 +61,15 @@ class LabPageFragment : LazyFragment(), CoroutineScope { b.rodo.onClick { app.db.teacherDao().query(SimpleSQLiteQuery("UPDATE teachers SET teacherSurname = \"\" WHERE profileId = ${App.profileId}")) } + + b.fullSync.onClick { + app.db.query(SimpleSQLiteQuery("UPDATE profiles SET empty = 1 WHERE profileId = ${App.profileId}")) + app.db.query(SimpleSQLiteQuery("DELETE FROM endpointTimers WHERE profileId = ${App.profileId}")) + } + + b.clearProfile.onClick { + ProfileRemoveDialog(activity, App.profileId, "FAKE", noProfileRemoval = true) + } b.removeHomework.onClick { app.db.eventDao().getRawNow("UPDATE events SET homeworkBody = NULL WHERE profileId = ${App.profileId}") diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java index 551efd01..555bc3fd 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java @@ -258,7 +258,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { .color(IconicsColor.colorInt(iconColor)) ) .setOnClickAction(() -> { - new ProfileRemoveDialog(activity, app.getProfile().getId(), app.getProfile().getName()); + new ProfileRemoveDialog(activity, app.getProfile().getId(), app.getProfile().getName(), false); }) ); diff --git a/app/src/main/res/layout/lab_fragment.xml b/app/src/main/res/layout/lab_fragment.xml index 356c11c0..8152f917 100644 --- a/app/src/main/res/layout/lab_fragment.xml +++ b/app/src/main/res/layout/lab_fragment.xml @@ -45,6 +45,22 @@ android:text="Set last 10 as unseen" android:textAllCaps="false" /> +