X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fdb%2FTemplateHeader.java;h=994c33098454a5ca09be19e0eddc3b2e44b64bce;hb=8c7bfd97117ef46093f368d2246346f53ba40cc9;hp=b5afb89eef9814b09fe497fd29beb44f4528a1da;hpb=55f4f1b5f101d0f9874fe3d3406d53c6df931a40;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java index b5afb89e..994c3309 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Damyan Ivanov. + * Copyright © 2022 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -21,21 +21,27 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.room.ColumnInfo; import androidx.room.Entity; +import androidx.room.Index; import androidx.room.PrimaryKey; import net.ktnx.mobileledger.utils.Misc; import org.jetbrains.annotations.NotNull; -@Entity(tableName = "templates") +import java.util.UUID; + +@Entity(tableName = "templates", + indices = {@Index(name = "templates_uuid_idx", unique = true, value = "uuid")}) public class TemplateHeader extends TemplateBase { @PrimaryKey(autoGenerate = true) - @NonNull - private Long id; + private long id; @ColumnInfo(name = "name") @NonNull private String name; @NonNull + @ColumnInfo + private String uuid; + @NonNull @ColumnInfo(name = "regular_expression") private String regularExpression; @ColumnInfo(name = "test_text") @@ -67,10 +73,13 @@ public class TemplateHeader extends TemplateBase { this.id = id; this.name = name; this.regularExpression = regularExpression; + this.uuid = UUID.randomUUID() + .toString(); } public TemplateHeader(TemplateHeader origin) { id = origin.id; name = origin.name; + uuid = origin.uuid; regularExpression = origin.regularExpression; testText = origin.testText; transactionDescription = origin.transactionDescription; @@ -85,6 +94,13 @@ public class TemplateHeader extends TemplateBase { dateDayMatchGroup = origin.dateDayMatchGroup; isFallback = origin.isFallback; } + @NonNull + public String getUuid() { + return uuid; + } + public void setUuid(@NonNull String uuid) { + this.uuid = uuid; + } public boolean isFallback() { return isFallback; } @@ -127,11 +143,10 @@ public class TemplateHeader extends TemplateBase { public void setDateDay(Integer dateDay) { this.dateDay = dateDay; } - @NonNull - public Long getId() { + public long getId() { return id; } - public void setId(@NonNull Long id) { + public void setId(long id) { this.id = id; } @NonNull @@ -203,7 +218,9 @@ public class TemplateHeader extends TemplateBase { } public TemplateHeader createDuplicate() { TemplateHeader dup = new TemplateHeader(this); - dup.id = null; + dup.id = 0; + dup.uuid = UUID.randomUUID() + .toString(); return dup; }