Skip to content

Commit

Permalink
Clear all data on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
kamerok committed Sep 3, 2024
1 parent f77e1ed commit c5d7ba6
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal class LocalDataSourceDecorator(defaultSource: LocalDataSource) : LocalD

override suspend fun deleteChange(id: Long) = source.deleteChange(id)

override suspend fun removeAllData() = source.removeAllData()

fun switchToSandbox() {
source = SandboxLocalDataSource()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import androidx.navigation.navOptions
import easydone.core.domain.DomainRepository
import easydone.core.domain.LocalDataSource
import easydone.core.domain.RemoteDataSource
import easydone.core.domain.SyncScheduler
import easydone.core.domain.model.Task
Expand Down Expand Up @@ -98,6 +99,7 @@ class MainNavigationScreenHolder(
private val syncScheduler: SyncScheduler by activity.inject()
private val domainRepository: DomainRepository by activity.inject()
private val remoteDataSource: RemoteDataSource by activity.inject()
private val localDataSource: LocalDataSource by activity.inject()
private val trelloRemoteDataSource: TrelloRemoteDataSource by activity.inject()
private val trelloApi: TrelloApi by activity.inject()
private val trelloApiKey: String by lazy { trelloRemoteDataSource.apiKey }
Expand Down Expand Up @@ -217,7 +219,7 @@ class MainNavigationScreenHolder(
}

composable("settings") {
SettingScreen(remoteDataSource, object : SettingsNavigator {
SettingScreen(remoteDataSource, localDataSource, object : SettingsNavigator {
override fun navigateToSetup() {
navController.navigate("setup", navOptions {
popUpTo("home") { inclusive = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ class DatabaseLocalDataSource(private val database: Database) : LocalDataSource
changesQueries.deleteChange(id)
}

override suspend fun removeAllData() {
taskQueries.clear()
changesQueries.clearChange()
changesQueries.clearDelta()
}

private suspend fun transaction(body: LocalDataSource.() -> Unit) =
withContext(Dispatchers.IO) {
database.transaction { body() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ CREATE TABLE delta (
FOREIGN KEY (change_id) REFERENCES change(id) ON DELETE CASCADE
);

clearDelta:
DELETE FROM delta;

clearChange:
DELETE FROM change;

lastInsertedRow:
SELECT last_insert_rowid();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ interface LocalDataSource {

suspend fun deleteChange(id: Long)

suspend fun removeAllData()

}
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,6 @@ class SandboxLocalDataSource : LocalDataSource {
override suspend fun refreshData(tasks: List<Task>, updatedTasks: List<Task>) {}

override suspend fun deleteChange(id: Long) {}

override suspend fun removeAllData() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class TrelloRemoteDataSource(

override suspend fun disconnect() {
authInfoHolder.clear()
idMappings.clear()
}

suspend fun connect(token: String, boardId: String) = withContext(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import easydone.core.domain.LocalDataSource
import easydone.core.domain.RemoteDataSource
import easydone.core.strings.R
import easydone.coreui.design.EasyDoneAppBar
Expand All @@ -21,6 +22,7 @@ import kotlinx.coroutines.launch
@Composable
fun SettingScreen(
remoteDataSource: RemoteDataSource,
localDataSource: LocalDataSource,
navigator: SettingsNavigator
) {
Surface(modifier = Modifier.fillMaxSize()) {
Expand All @@ -39,6 +41,7 @@ fun SettingScreen(
onClick = {
scope.launch {
remoteDataSource.disconnect()
localDataSource.removeAllData()
navigator.navigateToSetup()
}
}
Expand Down

0 comments on commit c5d7ba6

Please sign in to comment.