]> git.ktnx.net Git - mobile-ledger.git/commitdiff
Room-based profile wipe
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 15 Apr 2021 18:46:05 +0000 (18:46 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 15 Apr 2021 18:46:05 +0000 (18:46 +0000)
used only in debug builds as before

app/src/main/java/net/ktnx/mobileledger/db/Profile.java

index 06728c0216a4e89e8b525d5bc5eff4d52288faee..76d0e0590704f8b161774451b82211655e017f7d 100644 (file)
 
 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);
+    }
+
 }