]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/db/Profile.java
new transaction: currency can't be null
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / Profile.java
index d23303807053b73c7e32847457d9782b771c7fd7..030ae1ba51d5215d1d4d5b04b6592317ba64e05c 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.OptionDAO;
+import net.ktnx.mobileledger.dao.TransactionDAO;
+import net.ktnx.mobileledger.utils.Misc;
+
+import org.jetbrains.annotations.NotNull;
 
 @Entity(tableName = "profiles")
 public class Profile {
+    public static final long NO_PROFILE_ID = 0;
     @ColumnInfo
     @PrimaryKey(autoGenerate = true)
     private long id;
     @NonNull
     @ColumnInfo
     private String name = "";
+    @ColumnInfo(name = "deprecated_uuid")
+    private String deprecatedUUID;
     @NonNull
     @ColumnInfo
     private String url = "";
@@ -63,6 +77,12 @@ public class Profile {
     private int detectedVersionMajor;
     @ColumnInfo(name = "detected_version_minor")
     private int detectedVersionMinor;
+    public String getDeprecatedUUID() {
+        return deprecatedUUID;
+    }
+    public void setDeprecatedUUID(String deprecatedUUID) {
+        this.deprecatedUUID = deprecatedUUID;
+    }
     public long getId() {
         return id;
     }
@@ -143,11 +163,12 @@ public class Profile {
     public void setShowCommodityByDefault(boolean showCommodityByDefault) {
         this.showCommodityByDefault = showCommodityByDefault;
     }
+    @NotNull
     public String getDefaultCommodity() {
         return defaultCommodity;
     }
-    public void setDefaultCommodity(String defaultCommodity) {
-        this.defaultCommodity = defaultCommodity;
+    public void setDefaultCommodity(@org.jetbrains.annotations.Nullable String defaultCommodity) {
+        this.defaultCommodity = Misc.nullIsEmpty(defaultCommodity);
     }
     public boolean getShowCommentsByDefault() {
         return showCommentsByDefault;
@@ -178,4 +199,42 @@ public class Profile {
     public String toString() {
         return getName();
     }
+    @Override
+    public boolean equals(@Nullable Object o) {
+        if (!(o instanceof Profile))
+            return false;
+        Profile p = (Profile) o;
+        return id == p.id && Misc.equalStrings(name, p.name) &&
+               Misc.equalStrings(deprecatedUUID, p.deprecatedUUID) &&
+               Misc.equalStrings(url, p.url) && useAuthentication == p.useAuthentication &&
+               Misc.equalStrings(authUser, p.authUser) &&
+               Misc.equalStrings(authPassword, p.authPassword) && orderNo == p.orderNo &&
+               permitPosting == p.permitPosting && theme == p.theme &&
+               Misc.equalStrings(preferredAccountsFilter, p.preferredAccountsFilter) &&
+               futureDates == p.futureDates && apiVersion == p.apiVersion &&
+               showCommentsByDefault == p.showCommentsByDefault &&
+               Misc.equalStrings(defaultCommodity, p.defaultCommodity) &&
+               showCommentsByDefault == p.showCommentsByDefault &&
+               detectedVersionPre_1_19 == p.detectedVersionPre_1_19 &&
+               detectedVersionMajor == p.detectedVersionMajor &&
+               detectedVersionMinor == p.detectedVersionMinor;
+    }
+    @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.getAllForProfileUnorderedSync(id));
+    }
+    public void wipeAllData() {
+        AsyncTask.execute(this::wipeAllDataSync);
+    }
+
 }