From 7c23deda854fcedc421a6aa1e939f537ceb03649 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 31 Jan 2021 15:22:49 +0200 Subject: [PATCH] fix IDs when creating new patterns --- .../java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java | 3 +-- .../mobileledger/ui/patterns/PatternDetailsViewModel.java | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java b/app/src/main/java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java index a8ef1533..c3f0535a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java +++ b/app/src/main/java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java @@ -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 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsViewModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsViewModel.java index 70a2b119..4a964acc 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsViewModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsViewModel.java @@ -55,7 +55,7 @@ public class PatternDetailsViewModel extends ViewModel { ArrayList 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); -- 2.39.5