adding cache clearing to settings and avoiding delete crypto when clearing cache

This commit is contained in:
Adam Brown 2022-04-01 21:06:20 +01:00
parent 88bf6a2c78
commit 0cb307a56d
3 changed files with 10 additions and 8 deletions

View File

@ -77,17 +77,21 @@ internal class AppModule(context: Application, logger: MatrixLogger) {
preferences = SharedPreferencesDelegate(context.applicationContext, fileName = "dapk-user-preferences", coroutineDispatchers),
errorTracker = trackingModule.errorTracker,
credentialPreferences = SharedPreferencesDelegate(context.applicationContext, fileName = "dapk-credentials-preferences", coroutineDispatchers),
databaseDropper = { includeCryptoAccount ->
databaseDropper = { deleteCrypto ->
val cursor = driver.executeQuery(
identifier = null,
sql = "SELECT name FROM sqlite_master WHERE type = 'table' ${if (includeCryptoAccount) "" else "AND name != 'dbCryptoAccount'"}",
sql = "SELECT name FROM sqlite_master WHERE type = 'table'",
parameters = 0
)
cursor.use {
while (cursor.next()) {
cursor.getString(0)?.let {
log(AppLogTag.ERROR_NON_FATAL, "Deleting $it")
driver.execute(null, "DELETE FROM $it", 0)
if (!deleteCrypto && it.startsWith("dbCrypto")) {
// skip
} else {
log(AppLogTag.ERROR_NON_FATAL, "Deleting $it")
driver.execute(null, "DELETE FROM $it", 0)
}
}
}
}

View File

@ -8,6 +8,8 @@ internal class SettingsItemFactory(private val buildMeta: BuildMeta) {
SettingItem.Header("General"),
SettingItem.Text(SettingItem.Id.Encryption, "Encryption"),
SettingItem.Text(SettingItem.Id.EventLog, "Event log"),
SettingItem.Header("Data"),
SettingItem.Text(SettingItem.Id.ClearCache, "Clear cache"),
SettingItem.Header("Account"),
SettingItem.Text(SettingItem.Id.SignOut, "Sign out"),
SettingItem.Header("About"),

View File

@ -3,9 +3,7 @@ package app.dapk.st.settings
import android.content.ContentResolver
import android.net.Uri
import androidx.lifecycle.viewModelScope
import app.dapk.st.core.AppLogTag
import app.dapk.st.core.Lce
import app.dapk.st.core.log
import app.dapk.st.design.components.SpiderPage
import app.dapk.st.domain.StoreCleaner
import app.dapk.st.matrix.crypto.CryptoService
@ -37,7 +35,6 @@ internal class SettingsViewModel(
val root = Page.Root(Lce.Content(settingsItemFactory.root()))
val rootPage = SpiderPage(Page.Routes.root, "Settings", null, root)
updateState { copy(page = rootPage) }
println("state updated")
}
}
@ -49,7 +46,6 @@ internal class SettingsViewModel(
when (item.id) {
SignOut -> {
viewModelScope.launch {
log(AppLogTag.ERROR_NON_FATAL, "Sign out triggered")
cacheCleaner.cleanCache(removeCredentials = true)
_events.emit(SignedOut)
}