From: Damyan Ivanov Date: Thu, 15 Apr 2021 18:46:05 +0000 (+0000) Subject: Room-based profile wipe X-Git-Tag: v0.18.0~86 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=8c92dd30f3703556f7edda057e997283311be873;p=mobile-ledger.git Room-based profile wipe used only in debug builds as before --- diff --git a/app/src/main/java/net/ktnx/mobileledger/db/Profile.java b/app/src/main/java/net/ktnx/mobileledger/db/Profile.java index 06728c02..76d0e059 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/Profile.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/Profile.java @@ -17,10 +17,19 @@ package net.ktnx.mobileledger.db; +import android.os.AsyncTask; + import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.PrimaryKey; +import androidx.room.Transaction; + +import net.ktnx.mobileledger.dao.AccountDAO; +import net.ktnx.mobileledger.dao.DescriptionHistoryDAO; +import net.ktnx.mobileledger.dao.OptionDAO; +import net.ktnx.mobileledger.dao.TransactionDAO; @Entity(tableName = "profiles") public class Profile { @@ -186,4 +195,26 @@ public class Profile { public String toString() { return getName(); } + @Transaction + public void wipeAllDataSync() { + OptionDAO optDao = DB.get() + .getOptionDAO(); + optDao.deleteSync(optDao.allForProfileSync(id)); + + AccountDAO accDao = DB.get() + .getAccountDAO(); + accDao.deleteSync(accDao.allForProfileSync(id)); + + TransactionDAO trnDao = DB.get() + .getTransactionDAO(); + trnDao.deleteSync(trnDao.allForProfileSync(id)); + + DescriptionHistoryDAO descDao = DB.get() + .getDescriptionHistoryDAO(); + descDao.sweepSync(); + } + public void wipeAllData() { + AsyncTask.execute(this::wipeAllDataSync); + } + }