]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix IDs when creating new patterns
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 31 Jan 2021 13:22:49 +0000 (15:22 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 31 Jan 2021 13:22:49 +0000 (15:22 +0200)
app/src/main/java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java
app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsViewModel.java

index a8ef1533720c9ed1da0df2cb6dda5f1570b6dc04..c3f0535aec274393c526765fb0d82d7c47b773ec 100644 (file)
@@ -21,7 +21,6 @@ import androidx.lifecycle.LiveData;
 import androidx.room.Dao;
 import androidx.room.Delete;
 import androidx.room.Insert;
-import androidx.room.OnConflictStrategy;
 import androidx.room.Query;
 import androidx.room.Transaction;
 import androidx.room.Update;
@@ -33,7 +32,7 @@ import java.util.List;
 
 @Dao
 public interface PatternHeaderDAO {
-    @Insert(onConflict = OnConflictStrategy.REPLACE)
+    @Insert()
     long insert(PatternHeader item);
 
     @Update
index 70a2b119c5c2b577d16fce274f75a83460a003c7..4a964accfa2b053a01ea9c7417a13c9822a1f894 100644 (file)
@@ -55,7 +55,7 @@ public class PatternDetailsViewModel extends ViewModel {
         ArrayList<PatternDetailsItem> newList = new ArrayList<>();
         final PatternDetailsItem.Header header = PatternDetailsItem.createHeader();
         header.setName(mDefaultPatternName);
-        header.setId(1);
+        header.setId(0);
         newList.add(header);
 
         while (newList.size() < 3) {
@@ -143,6 +143,7 @@ public class PatternDetailsViewModel extends ViewModel {
                                            .getPatternDAO();
             PatternHeader dbHeader = modelHeader.toDBO();
             if (newPattern) {
+                dbHeader.setId(null);
                 dbHeader.setId(mPatternId = headerDAO.insert(dbHeader));
             }
             else
@@ -161,8 +162,10 @@ public class PatternDetailsViewModel extends ViewModel {
                 PatternAccount dbAccount = accRowItem.toDBO(dbHeader.getId());
                 dbAccount.setPatternId(mPatternId);
                 dbAccount.setPosition(i);
-                if (newPattern)
+                if (newPattern) {
+                    dbAccount.setId(null);
                     dbAccount.setId(paDAO.insert(dbAccount));
+                }
                 else
                     paDAO.update(dbAccount);