Skip to content

Commit

Permalink
Show confirmation prompt before signing out. Closes #153.
Browse files Browse the repository at this point in the history
Fixing crash happening during immediate Login after Sign Out.

Upping versionCode to 96
  • Loading branch information
Dima-Android committed Aug 29, 2024
1 parent 5f41d81 commit b25c77a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 29 deletions.
30 changes: 24 additions & 6 deletions app/src/main/java/org/zotero/android/database/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.zotero.android.database
import io.realm.DynamicRealm
import io.realm.FieldAttribute
import io.realm.RealmConfiguration
import io.realm.RealmMigration
import io.realm.annotations.RealmModule
import org.zotero.android.database.objects.AllItemsDbRow
import org.zotero.android.database.objects.FieldKeys
Expand All @@ -29,7 +30,6 @@ import org.zotero.android.database.objects.RUser
import org.zotero.android.database.objects.RVersions
import org.zotero.android.database.objects.RWebDavDeletion
import org.zotero.android.database.requests.key
import org.zotero.android.files.FileStore
import java.io.File

class Database {
Expand All @@ -43,15 +43,33 @@ class Database {
.modules(MainConfigurationDbModule())
.schemaVersion(schemaVersion)
.allowWritesOnUiThread(true)
.migration { dynamicRealm, oldVersion, newVersion ->
if (oldVersion < 2) {
migrateAllItemsDbRowTypeIconNameTypeChange(dynamicRealm)
}
}
.migration(MainDbMigration(fileName = dbFile.name))

return builder.build()
}

internal class MainDbMigration(private val fileName: String): RealmMigration {
override fun migrate(dynamicRealm: DynamicRealm, oldVersion: Long, newVersion: Long) {
if (oldVersion < 2) {
migrateAllItemsDbRowTypeIconNameTypeChange(dynamicRealm)
}
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as MainDbMigration

return fileName == other.fileName
}

override fun hashCode(): Int {
return fileName.hashCode()
}

}

private fun migrateAllItemsDbRowTypeIconNameTypeChange(dynamicRealm: DynamicRealm) {
val realmSchema = dynamicRealm.schema

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ internal fun SettingsAccountScreen(
)
}

val shouldShowSignOutDialog = viewState.shouldShowSignOutDialog
if (shouldShowSignOutDialog) {
SignOutDialog(
onCancel = viewModel::onDismissSignOutDialog,
onSignOut = viewModel::onSignOut
)
}

}
}
}
Expand Down Expand Up @@ -118,3 +126,25 @@ private fun DirectoryNotFoundDialog (
onDismiss = onCancel
)
}

@Composable
private fun SignOutDialog (
onSignOut: () -> Unit,
onCancel: () -> Unit,
) {
CustomAlertDialog(
title = stringResource(id = Strings.warning),
description = stringResource(
id = Strings.settings_logout_warning
),
descriptionTextColor = CustomTheme.colors.primaryContent,
primaryAction = CustomAlertDialog.ActionConfig(
text = stringResource(id = Strings.no),
),
secondaryAction = CustomAlertDialog.ActionConfig(
text = stringResource(id = Strings.yes),
onClick = onSignOut
),
onDismiss = onCancel
)
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
package org.zotero.android.screens.settings.account

import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import org.zotero.android.screens.settings.SettingsDivider
import org.zotero.android.screens.settings.SettingsItem
import org.zotero.android.screens.settings.SettingsSection
import org.zotero.android.screens.settings.SettingsSectionTitle
import org.zotero.android.uicomponents.Drawables
import org.zotero.android.uicomponents.Strings
import org.zotero.android.uicomponents.foundation.safeClickable
import org.zotero.android.uicomponents.theme.CustomPalette
import org.zotero.android.uicomponents.theme.CustomTheme
import org.zotero.android.webdav.data.FileSyncType




@Composable
Expand All @@ -47,7 +26,7 @@ internal fun SettingsAccountDataSyncSection(
SettingsItem(
textColor = CustomPalette.ErrorRed,
title = stringResource(id = Strings.settings_logout),
onItemTapped = viewModel::onSignOut
onItemTapped = viewModel::onShowSignOutDialog
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,22 @@ internal class SettingsAccountViewModel @Inject constructor(
}
}

fun onShowSignOutDialog() {
updateState {
copy(
shouldShowSignOutDialog = true,
)
}
}

fun onDismissSignOutDialog() {
updateState {
copy(
shouldShowSignOutDialog = false,
)
}
}

fun onCreateWebDavDirectory() {
verify(tryCreatingZoteroDir = true)
}
Expand All @@ -458,6 +474,7 @@ internal data class SettingsAccountViewState(
val isVerifyingWebDav: Boolean = false,
val webDavVerificationResult: CustomResult<Unit>? = null,
val createWebDavDirectoryDialogData: CreateWebDavDirectoryDialogData? = null,
val shouldShowSignOutDialog: Boolean = false
) : ViewState {
val canVerifyServer: Boolean get() {
return !url.isEmpty() && !username.isEmpty() && !password.isEmpty()
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object BuildConfig {
const val compileSdkVersion = 34
const val targetSdk = 34

val versionCode = 95 // Must be updated on every build
val versionCode = 96 // Must be updated on every build
val version = Version(
major = 1,
minor = 0,
Expand Down

0 comments on commit b25c77a

Please sign in to comment.