From 3ab99e1679326277d6ba7f8ce28f17a96dfa07aa Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Tue, 2 Feb 2021 19:23:35 +0200 Subject: [PATCH] rename Patterns to Templates better reflects the purpose and function also drop unnecessary unique index on a primary key and explicit foreign key constraint names --- .../net.ktnx.mobileledger.db.DB/54.json | 276 ++++++++++++++++++ ...ccountDAO.java => TemplateAccountDAO.java} | 8 +- ...nHeaderDAO.java => TemplateHeaderDAO.java} | 16 +- .../java/net/ktnx/mobileledger/db/DB.java | 66 ++++- .../ktnx/mobileledger/db/TemplateAccount.java | 27 +- .../ktnx/mobileledger/db/TemplateHeader.java | 4 +- ...ccounts.java => TemplateWithAccounts.java} | 4 +- .../NewTransactionFragment.java | 8 +- .../ui/templates/TemplateDetailsFragment.java | 2 +- .../templates/TemplateDetailsViewModel.java | 24 +- .../ui/templates/TemplateListFragment.java | 8 +- .../utils/MobileLedgerDatabase.java | 2 +- app/src/main/res/layout/activity_main.xml | 2 +- .../res/layout/template_details_account.xml | 8 +- .../res/layout/template_details_header.xml | 16 +- app/src/main/res/raw/sql_54.sql | 16 + app/src/main/res/values-bg/strings.xml | 36 +-- app/src/main/res/values/strings.xml | 46 +-- 18 files changed, 457 insertions(+), 112 deletions(-) create mode 100644 app/schemas/net.ktnx.mobileledger.db.DB/54.json rename app/src/main/java/net/ktnx/mobileledger/dao/{PatternAccountDAO.java => TemplateAccountDAO.java} (84%) rename app/src/main/java/net/ktnx/mobileledger/dao/{PatternHeaderDAO.java => TemplateHeaderDAO.java} (73%) rename app/src/main/java/net/ktnx/mobileledger/db/{PatternWithAccounts.java => TemplateWithAccounts.java} (90%) create mode 100644 app/src/main/res/raw/sql_54.sql diff --git a/app/schemas/net.ktnx.mobileledger.db.DB/54.json b/app/schemas/net.ktnx.mobileledger.db.DB/54.json new file mode 100644 index 00000000..fcaec8c8 --- /dev/null +++ b/app/schemas/net.ktnx.mobileledger.db.DB/54.json @@ -0,0 +1,276 @@ +{ + "formatVersion": 1, + "database": { + "version": 54, + "identityHash": "c5ddfa995546d7931ec2655613654949", + "entities": [ + { + "tableName": "templates", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `regular_expression` TEXT NOT NULL, `test_text` TEXT, `transaction_description` TEXT, `transaction_description_match_group` INTEGER, `transaction_comment` TEXT, `transaction_comment_match_group` INTEGER, `date_year` INTEGER, `date_year_match_group` INTEGER, `date_month` INTEGER, `date_month_match_group` INTEGER, `date_day` INTEGER, `date_day_match_group` INTEGER)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "regularExpression", + "columnName": "regular_expression", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "testText", + "columnName": "test_text", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "transactionDescription", + "columnName": "transaction_description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "transactionDescriptionMatchGroup", + "columnName": "transaction_description_match_group", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "transactionComment", + "columnName": "transaction_comment", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "transactionCommentMatchGroup", + "columnName": "transaction_comment_match_group", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "dateYear", + "columnName": "date_year", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "dateYearMatchGroup", + "columnName": "date_year_match_group", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "dateMonth", + "columnName": "date_month", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "dateMonthMatchGroup", + "columnName": "date_month_match_group", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "dateDay", + "columnName": "date_day", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "dateDayMatchGroup", + "columnName": "date_day_match_group", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "template_accounts", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `template_id` INTEGER NOT NULL, `acc` TEXT, `position` INTEGER NOT NULL, `acc_match_group` INTEGER, `currency` INTEGER, `currency_match_group` INTEGER, `amount` REAL, `amount_match_group` INTEGER, `comment` TEXT, `comment_match_group` INTEGER, `negate_amount` INTEGER, FOREIGN KEY(`template_id`) REFERENCES `templates`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION , FOREIGN KEY(`currency`) REFERENCES `currencies`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "templateId", + "columnName": "template_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "accountName", + "columnName": "acc", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "position", + "columnName": "position", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "accountNameMatchGroup", + "columnName": "acc_match_group", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "currencyMatchGroup", + "columnName": "currency_match_group", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "amountMatchGroup", + "columnName": "amount_match_group", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "accountComment", + "columnName": "comment", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "accountCommentMatchGroup", + "columnName": "comment_match_group", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "negateAmount", + "columnName": "negate_amount", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [ + { + "name": "fk_template_accounts_template", + "unique": false, + "columnNames": [ + "template_id" + ], + "createSql": "CREATE INDEX IF NOT EXISTS `fk_template_accounts_template` ON `${TABLE_NAME}` (`template_id`)" + }, + { + "name": "fk_template_accounts_currency", + "unique": false, + "columnNames": [ + "currency" + ], + "createSql": "CREATE INDEX IF NOT EXISTS `fk_template_accounts_currency` ON `${TABLE_NAME}` (`currency`)" + } + ], + "foreignKeys": [ + { + "table": "templates", + "onDelete": "NO ACTION", + "onUpdate": "NO ACTION", + "columns": [ + "template_id" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "currencies", + "onDelete": "NO ACTION", + "onUpdate": "NO ACTION", + "columns": [ + "currency" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "currencies", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `position` TEXT NOT NULL, `has_gap` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "position", + "columnName": "position", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "hasGap", + "columnName": "has_gap", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c5ddfa995546d7931ec2655613654949')" + ] + } +} \ No newline at end of file diff --git a/app/src/main/java/net/ktnx/mobileledger/dao/PatternAccountDAO.java b/app/src/main/java/net/ktnx/mobileledger/dao/TemplateAccountDAO.java similarity index 84% rename from app/src/main/java/net/ktnx/mobileledger/dao/PatternAccountDAO.java rename to app/src/main/java/net/ktnx/mobileledger/dao/TemplateAccountDAO.java index 1ee0cd0d..4fd1d204 100644 --- a/app/src/main/java/net/ktnx/mobileledger/dao/PatternAccountDAO.java +++ b/app/src/main/java/net/ktnx/mobileledger/dao/TemplateAccountDAO.java @@ -29,7 +29,7 @@ import net.ktnx.mobileledger.db.TemplateAccount; import java.util.List; @Dao -public interface PatternAccountDAO { +public interface TemplateAccountDAO { @Insert Long insert(TemplateAccount item); @@ -39,10 +39,10 @@ public interface PatternAccountDAO { @Delete void delete(TemplateAccount item); - @Query("SELECT * FROM pattern_accounts WHERE pattern_id=:pattern_id") - LiveData> getPatternAccounts(Long pattern_id); + @Query("SELECT * FROM template_accounts WHERE template_id=:template_id") + LiveData> getTemplateAccounts(Long template_id); - @Query("SELECT * FROM pattern_accounts WHERE id = :id") + @Query("SELECT * FROM template_accounts WHERE id = :id") LiveData getPatternAccountById(Long id); // not useful for now diff --git a/app/src/main/java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java b/app/src/main/java/net/ktnx/mobileledger/dao/TemplateHeaderDAO.java similarity index 73% rename from app/src/main/java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java rename to app/src/main/java/net/ktnx/mobileledger/dao/TemplateHeaderDAO.java index b4713d32..faef98fb 100644 --- a/app/src/main/java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java +++ b/app/src/main/java/net/ktnx/mobileledger/dao/TemplateHeaderDAO.java @@ -25,13 +25,13 @@ import androidx.room.Query; import androidx.room.Transaction; import androidx.room.Update; -import net.ktnx.mobileledger.db.PatternWithAccounts; import net.ktnx.mobileledger.db.TemplateHeader; +import net.ktnx.mobileledger.db.TemplateWithAccounts; import java.util.List; @Dao -public interface PatternHeaderDAO { +public interface TemplateHeaderDAO { @Insert() long insert(TemplateHeader item); @@ -41,13 +41,13 @@ public interface PatternHeaderDAO { @Delete void delete(TemplateHeader item); - @Query("SELECT * FROM patterns ORDER BY UPPER(name)") - LiveData> getPatterns(); + @Query("SELECT * FROM templates ORDER BY UPPER(name)") + LiveData> getTemplates(); - @Query("SELECT * FROM patterns WHERE id = :id") - LiveData getPattern(Long id); + @Query("SELECT * FROM templates WHERE id = :id") + LiveData getTemplate(Long id); @Transaction - @Query("SELECT * FROM patterns WHERE id = :id") - LiveData getPatternWithAccounts(Long id); + @Query("SELECT * FROM templates WHERE id = :id") + LiveData getTemplateWithAccounts(Long id); } diff --git a/app/src/main/java/net/ktnx/mobileledger/db/DB.java b/app/src/main/java/net/ktnx/mobileledger/db/DB.java index 80652ed1..f65f503f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/DB.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/DB.java @@ -26,11 +26,11 @@ import androidx.sqlite.db.SupportSQLiteDatabase; import net.ktnx.mobileledger.App; import net.ktnx.mobileledger.dao.CurrencyDAO; -import net.ktnx.mobileledger.dao.PatternAccountDAO; -import net.ktnx.mobileledger.dao.PatternHeaderDAO; +import net.ktnx.mobileledger.dao.TemplateAccountDAO; +import net.ktnx.mobileledger.dao.TemplateHeaderDAO; import net.ktnx.mobileledger.utils.MobileLedgerDatabase; -@Database(version = 53, entities = {TemplateHeader.class, TemplateAccount.class, Currency.class}) +@Database(version = 54, entities = {TemplateHeader.class, TemplateAccount.class, Currency.class}) abstract public class DB extends RoomDatabase { private static DB instance; public static DB get() { @@ -63,14 +63,70 @@ abstract public class DB extends RoomDatabase { db.execSQL( "alter table pattern_accounts add negate_amount boolean;"); } + }, new Migration(53, 54) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase db) { + db.execSQL("CREATE TABLE templates (id INTEGER PRIMARY KEY " + + "AUTOINCREMENT NOT NULL, name TEXT NOT NULL, " + + "regular_expression TEXT NOT NULL, test_text TEXT, " + + "transaction_description TEXT, " + + "transaction_description_match_group INTEGER, " + + "transaction_comment TEXT, " + + "transaction_comment_match_group INTEGER, date_year " + + "INTEGER, date_year_match_group INTEGER, date_month " + + "INTEGER, date_month_match_group INTEGER, date_day " + + "INTEGER, date_day_match_group INTEGER)"); + db.execSQL( + "CREATE TABLE template_accounts (id INTEGER PRIMARY KEY " + + "AUTOINCREMENT NOT NULL, template_id INTEGER NOT NULL, " + + "acc TEXT, position INTEGER NOT NULL, acc_match_group " + + "INTEGER, currency INTEGER, currency_match_group INTEGER," + + " amount REAL, amount_match_group INTEGER, comment TEXT, " + + "comment_match_group INTEGER, negate_amount INTEGER, " + + "FOREIGN KEY(template_id) REFERENCES templates(id) ON " + + "UPDATE NO ACTION ON DELETE NO ACTION , FOREIGN KEY" + + "(currency) REFERENCES currencies(id) ON UPDATE NO ACTION" + + " ON DELETE NO ACTION )"); + db.execSQL("insert into templates(id, name, regular_expression, " + + "test_text, transaction_description, " + + "transaction_description_match_group, " + + "transaction_comment, transaction_comment_match_group," + + " date_year, date_year_match_group, date_month, " + + "date_month_match_group, date_day, " + + "date_day_match_group)" + + " select id, name, regular_expression, test_text, " + + "transaction_description, " + + "transaction_description_match_group, " + + "transaction_comment, transaction_comment_match_group," + + " date_year, date_year_match_group, date_month, " + + "date_month_match_group, date_day, " + + "date_day_match_group from patterns"); + db.execSQL("insert into template_accounts(id, template_id, acc, " + + "position, acc_match_group, currency, " + + "currency_match_group, amount, amount_match_group, " + + "amount, amount_match_group, comment, " + + "comment_match_group, negate_amount) select id, " + + "pattern_id, acc, position, acc_match_group, " + + "currency, " + + "currency_match_group, amount, amount_match_group, " + + "amount, amount_match_group, comment, " + + "comment_match_group, negate_amount from " + + "pattern_accounts"); + db.execSQL("create index fk_template_accounts_template on " + + "template_accounts(template_id)"); + db.execSQL("create index fk_template_accounts_currency on " + + "template_accounts(currency)"); + db.execSQL("drop table pattern_accounts"); + db.execSQL("drop table patterns"); + } } }) .build(); } } - public abstract PatternHeaderDAO getPatternDAO(); + public abstract TemplateHeaderDAO getPatternDAO(); - public abstract PatternAccountDAO getPatternAccountDAO(); + public abstract TemplateAccountDAO getPatternAccountDAO(); public abstract CurrencyDAO getCurrencyDAO(); } diff --git a/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java index 92b29080..c662ff1c 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java @@ -26,22 +26,21 @@ import androidx.room.PrimaryKey; import org.jetbrains.annotations.NotNull; -@Entity(tableName = "pattern_accounts", - indices = {@Index(name = "un_pattern_accounts", unique = true, value = "id"), - @Index(name = "fk_pattern_accounts_pattern", value = "pattern_id"), - @Index(name = "fk_pattern_accounts_currency", value = "currency") - }, foreignKeys = {@ForeignKey(childColumns = "pattern_id", parentColumns = "id", +@Entity(tableName = "template_accounts", + indices = {@Index(name = "fk_template_accounts_template", value = "template_id"), + @Index(name = "fk_template_accounts_currency", value = "currency") + }, foreignKeys = {@ForeignKey(childColumns = "template_id", parentColumns = "id", entity = TemplateHeader.class), @ForeignKey(childColumns = "currency", parentColumns = "id", entity = Currency.class) }) public class TemplateAccount extends TemplateBase { - @NonNull - @ColumnInfo(name = "pattern_id") - private Long patternId; @PrimaryKey(autoGenerate = true) @NotNull private Long id; + @NonNull + @ColumnInfo(name = "template_id") + private Long templateId; @ColumnInfo(name = "acc") private String accountName; @ColumnInfo(name = "position") @@ -63,9 +62,9 @@ public class TemplateAccount extends TemplateBase { private Integer accountCommentMatchGroup; @ColumnInfo(name = "negate_amount") private Boolean negateAmount; - public TemplateAccount(@NotNull Long id, @NonNull Long patternId, @NonNull Long position) { + public TemplateAccount(@NotNull Long id, @NonNull Long templateId, @NonNull Long position) { this.id = id; - this.patternId = patternId; + this.templateId = templateId; this.position = position; } public Long getId() { @@ -80,11 +79,11 @@ public class TemplateAccount extends TemplateBase { public void setNegateAmount(Boolean negateAmount) { this.negateAmount = negateAmount; } - public @NotNull Long getPatternId() { - return patternId; + public @NotNull Long getTemplateId() { + return templateId; } - public void setPatternId(@NonNull Long patternId) { - this.patternId = patternId; + public void setTemplateId(@NonNull Long templateId) { + this.templateId = templateId; } @NonNull public String getAccountName() { 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 301b100c..5422767f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java @@ -21,15 +21,13 @@ 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 = "patterns", - indices = {@Index(name = "un_patterns_id", value = "id", unique = true)}) +@Entity(tableName = "templates") public class TemplateHeader extends TemplateBase { @PrimaryKey(autoGenerate = true) @NonNull diff --git a/app/src/main/java/net/ktnx/mobileledger/db/PatternWithAccounts.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java similarity index 90% rename from app/src/main/java/net/ktnx/mobileledger/db/PatternWithAccounts.java rename to app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java index 9f171b1b..a40ecae9 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/PatternWithAccounts.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java @@ -22,10 +22,10 @@ import androidx.room.Relation; import java.util.List; -public class PatternWithAccounts { +public class TemplateWithAccounts { @Embedded public TemplateHeader header; - @Relation(parentColumn = "id", entityColumn = "pattern_id") + @Relation(parentColumn = "id", entityColumn = "template_id") public List accounts; public Long getId() { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java index e708c5fe..8499d6f0 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java @@ -98,7 +98,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { private void alertNoPatternMatch(String scanned) { MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()); builder.setCancelable(true) - .setMessage(R.string.no_pattern_matches) + .setMessage(R.string.no_template_matches) .setPositiveButton(R.string.add_button, (dialog, which) -> startNewPatternActivity(scanned)) .create() @@ -112,7 +112,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { LiveData> allPatterns = DB.get() .getPatternDAO() - .getPatterns(); + .getTemplates(); allPatterns.observe(getViewLifecycleOwner(), patternHeaders -> { ArrayList matchingPatterns = new ArrayList<>(); @@ -199,7 +199,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()); builder.setCancelable(true) - .setTitle(R.string.choose_pattern_to_apply) + .setTitle(R.string.choose_template_to_apply) .setSingleChoiceItems(cursor, -1, patternNameColumn, (dialog, which) -> { applyPattern(matchingPatterns.get(which), matchedText); dialog.dismiss(); @@ -258,7 +258,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { DB.get() .getPatternDAO() - .getPatternWithAccounts(patternHeader.getId()) + .getTemplateWithAccounts(patternHeader.getId()) .observe(getViewLifecycleOwner(), entry -> { int rowIndex = 0; final boolean accountsInInitialState = viewModel.accountsInInitialState(); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsFragment.java index 94e6989e..b95ae29b 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsFragment.java @@ -75,7 +75,7 @@ public class TemplateDetailsFragment extends QRScanCapableFragment { final ViewModelStoreOwner viewModelStoreOwner = controller.getViewModelStoreOwner(R.id.template_list_navigation); mViewModel = new ViewModelProvider(viewModelStoreOwner).get(TemplateDetailsViewModel.class); - mViewModel.setDefaultPatternName(getString(R.string.unnamed_pattern)); + mViewModel.setDefaultPatternName(getString(R.string.unnamed_template)); Logger.debug("flow", "PatternDetailsFragment.onCreateView(): model=" + mViewModel); b = TemplateDetailsFragmentBinding.inflate(inflater); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java index 088b1b77..a24b9767 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java @@ -24,12 +24,12 @@ import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModel; -import net.ktnx.mobileledger.dao.PatternAccountDAO; -import net.ktnx.mobileledger.dao.PatternHeaderDAO; +import net.ktnx.mobileledger.dao.TemplateAccountDAO; +import net.ktnx.mobileledger.dao.TemplateHeaderDAO; import net.ktnx.mobileledger.db.DB; -import net.ktnx.mobileledger.db.PatternWithAccounts; import net.ktnx.mobileledger.db.TemplateAccount; import net.ktnx.mobileledger.db.TemplateHeader; +import net.ktnx.mobileledger.db.TemplateWithAccounts; import net.ktnx.mobileledger.model.TemplateDetailsItem; import net.ktnx.mobileledger.utils.Logger; @@ -96,11 +96,11 @@ public class TemplateDetailsViewModel extends ViewModel { } DB db = DB.get(); - LiveData dbList = db.getPatternDAO() - .getPatternWithAccounts(mPatternId); - Observer observer = new Observer() { + LiveData dbList = db.getPatternDAO() + .getTemplateWithAccounts(mPatternId); + Observer observer = new Observer() { @Override - public void onChanged(PatternWithAccounts src) { + public void onChanged(TemplateWithAccounts src) { ArrayList l = new ArrayList<>(); TemplateDetailsItem header = TemplateDetailsItem.fromRoomObject(src.header); @@ -139,8 +139,8 @@ public class TemplateDetailsViewModel extends ViewModel { TemplateDetailsItem.Header modelHeader = list.get(0) .asHeaderItem(); - PatternHeaderDAO headerDAO = DB.get() - .getPatternDAO(); + TemplateHeaderDAO headerDAO = DB.get() + .getPatternDAO(); TemplateHeader dbHeader = modelHeader.toDBO(); if (newPattern) { dbHeader.setId(null); @@ -154,13 +154,13 @@ public class TemplateDetailsViewModel extends ViewModel { modelHeader)); - PatternAccountDAO paDAO = DB.get() - .getPatternAccountDAO(); + TemplateAccountDAO paDAO = DB.get() + .getPatternAccountDAO(); for (int i = 1; i < list.size(); i++) { final TemplateDetailsItem.AccountRow accRowItem = list.get(i) .asAccountRowItem(); TemplateAccount dbAccount = accRowItem.toDBO(dbHeader.getId()); - dbAccount.setPatternId(mPatternId); + dbAccount.setTemplateId(mPatternId); dbAccount.setPosition(i); if (newPattern) { dbAccount.setId(null); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateListFragment.java index cc5c7988..53564278 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateListFragment.java @@ -32,7 +32,7 @@ import androidx.lifecycle.LiveData; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import net.ktnx.mobileledger.dao.PatternHeaderDAO; +import net.ktnx.mobileledger.dao.TemplateHeaderDAO; import net.ktnx.mobileledger.databinding.FragmentTemplateListBinding; import net.ktnx.mobileledger.db.DB; import net.ktnx.mobileledger.db.TemplateHeader; @@ -85,9 +85,9 @@ public class TemplateListFragment extends Fragment { TemplatesRecyclerViewAdapter modelAdapter = new TemplatesRecyclerViewAdapter(); b.templateList.setAdapter(modelAdapter); - PatternHeaderDAO pDao = DB.get() - .getPatternDAO(); - LiveData> templates = pDao.getPatterns(); + TemplateHeaderDAO pDao = DB.get() + .getPatternDAO(); + LiveData> templates = pDao.getTemplates(); templates.observe(getViewLifecycleOwner(), modelAdapter::setTemplates); LinearLayoutManager llm = new LinearLayoutManager(getContext()); llm.setOrientation(RecyclerView.VERTICAL); diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java b/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java index f08f7302..3785ddd3 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java @@ -39,7 +39,7 @@ import static net.ktnx.mobileledger.utils.Logger.debug; public class MobileLedgerDatabase extends SQLiteOpenHelper { public static final MutableLiveData initComplete = new MutableLiveData<>(false); public static final String DB_NAME = "MoLe.db"; - private static final int LATEST_REVISION = 53; + private static final int LATEST_REVISION = 54; private static final String CREATE_DB_SQL = "create_db"; private final Application mContext; diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ede0f620..02c51e06 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -406,7 +406,7 @@ diff --git a/app/src/main/res/layout/template_details_account.xml b/app/src/main/res/layout/template_details_account.xml index 0eeb78b9..93372b7a 100644 --- a/app/src/main/res/layout/template_details_account.xml +++ b/app/src/main/res/layout/template_details_account.xml @@ -28,7 +28,7 @@ android:layout_height="match_parent" android:gravity="end" android:paddingTop="@dimen/text_margin" - android:text="@string/pattern_details_account_row_label" + android:text="@string/template_details_account_row_label" app:drawableBottomCompat="@drawable/dashed_border_8dp" /> @@ -107,7 +107,7 @@ android:id="@+id/template_details_account_comment" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/pattern_details_account_comment_label" + android:hint="@string/template_details_account_comment_label" android:inputType="text" /> @@ -154,7 +154,7 @@ android:id="@+id/template_details_account_amount" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/pattern_details_account_amount_label" + android:hint="@string/template_details_account_amount_label" android:inputType="number|numberDecimal|numberSigned" /> diff --git a/app/src/main/res/layout/template_details_header.xml b/app/src/main/res/layout/template_details_header.xml index bc5b851e..d16ce4eb 100644 --- a/app/src/main/res/layout/template_details_header.xml +++ b/app/src/main/res/layout/template_details_header.xml @@ -34,7 +34,7 @@ android:id="@+id/template_name" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/pattern_name_label" + android:hint="@string/template_name_label" android:inputType="text" /> @@ -51,7 +51,7 @@ android:id="@+id/pattern" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/pattern_details_pattern_label" + android:hint="@string/template_details_pattern_label" android:inputType="text" /> @@ -68,7 +68,7 @@ android:id="@+id/test_text" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/pattern_details_test_text_label" + android:hint="@string/template_details_test_text_label" android:inputType="text" /> @@ -91,21 +91,21 @@ android:layout_height="wrap_content" android:gravity="end" android:paddingTop="@dimen/text_margin" - android:text="@string/pattern_transaction_parameters_label" + android:text="@string/template_transaction_parameters_label" app:layout_constraintTop_toBottomOf="@id/test_text_layout" /> . + +-- this is handled in a Room migration \ No newline at end of file diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 0b97052c..75ffb64d 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -168,36 +168,36 @@ Вероятно настроената версия на протокола не се поддържа. Възможно е програмния интерфейс на сървъра да не се поддържа от MoLe Сканиране на QR код - Макети + Макети Макети Шаблон (regex) Помощ Бутон за промяна - Бележка към сметката - Сума + Бележка към сметката + Сума Прихващане от шаблона Липсва шаблон Липсва примерен текст Шаблонът няма прихващания Шаблонът не съвпада с примерния текст - Данни за движението + Данни за движението Описание на движението Бележка към движението Източник на описанието на движението Източник на бележката към движението - Дата на движението + Дата на движението година месец ден - година - ден - месец - Макет без име + година + ден + месец + Макет без име Добавяне на макет Запазване на макета - Няма съвпадение с нито един макет - Избор на макет - Име на макет + Няма съвпадение с нито един макет + Избор на макет + Име на макет Функцията още не е готова Промяна на макет Създаване на макет @@ -205,12 +205,12 @@ Липсва сметка Липсва шаблон Невалиден номер на прихващане - Име на макет - Шаблон - Сума - Примерен текст - Сметка - Данни за сметката + Име на макет + Шаблон + Сума + Примерен текст + Сметка + Данни за сметката Източник на името на сметката ръчно въвеждане Източник на бележка към сметката diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b77d382..d9d1ab3b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -178,8 +178,8 @@ A mismatch in the configured API version could be causing this Perhaps the API of the backend server is not supported by MoLe Scan QR code - Patterns - Patterns + Templates + Templates Pattern (regular expression) Help Edit button @@ -187,42 +187,42 @@ Account name missing Pattern missing Invalid matching group number - Pattern name - Pattern - Amount - Test text - Account name - Transaction account details + Template name + Pattern + Amount + Test text + Account name + Transaction account details Account name source literal Account comment source Amount source - Account comment - Amount + Account comment + Amount Pattern match group Missing pattern Missing test text Pattern has no capturing groups Pattern doesn\'t match the test text - Transaction parameters + Transaction parameters Transaction description Transaction comment Transaction description source Transaction comment source - Transaction date + Transaction date year month date - year - date - month - Pattern with no name - Add pattern - Save pattern - No pattern matches - Choose pattern to apply - Pattern name + year + date + month + Template with no name + Add template + Save template + No template matches + Choose template to apply + Template name Not implemented yet - Edit pattern - New pattern + Edit template + New template -- 2.39.5