From d95839304defead7c7d605cab2e612f1227cbfed Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Tue, 2 Feb 2021 08:35:48 +0200 Subject: [PATCH] rename patterns to templates "pattern" is the regular expression that is used to match templates --- app/src/main/AndroidManifest.xml | 4 +- .../mobileledger/dao/PatternAccountDAO.java | 12 +- .../mobileledger/dao/PatternHeaderDAO.java | 12 +- .../java/net/ktnx/mobileledger/db/DB.java | 2 +- .../mobileledger/db/PatternWithAccounts.java | 4 +- ...tternAccount.java => TemplateAccount.java} | 6 +- .../{PatternBase.java => TemplateBase.java} | 2 +- ...PatternHeader.java => TemplateHeader.java} | 27 +- ...lSource.java => TemplateDetailSource.java} | 18 +- ...ailsItem.java => TemplateDetailsItem.java} | 38 +-- ...TemplateDetailSourceSelectorFragment.java} | 46 +-- ...=> TemplateDetailSourceSelectorModel.java} | 12 +- ...ailSourceSelectorRecyclerViewAdapter.java} | 32 +- .../ui/activity/MainActivity.java | 4 +- .../NewTransactionFragment.java | 26 +- .../TemplateDetailsAdapter.java} | 293 +++++++++--------- .../TemplateDetailsFragment.java} | 34 +- .../TemplateDetailsViewModel.java} | 58 ++-- .../TemplateListFragment.java} | 44 +-- .../TemplateViewHolder.java} | 18 +- .../ui/templates/TemplatesActivity.java | 55 ++-- .../TemplatesRecyclerViewAdapter.java} | 36 +-- ...ty_patterns.xml => activity_templates.xml} | 4 +- .../main/res/layout/fragment_item_list.xml | 4 +- ...gment_template_detail_source_selector.xml} | 2 +- ..._template_detail_source_selector_list.xml} | 12 +- ...rn_list.xml => fragment_template_list.xml} | 4 +- ...count.xml => template_details_account.xml} | 44 +-- ...ment.xml => template_details_fragment.xml} | 2 +- ...header.xml => template_details_header.xml} | 86 ++--- ...ut.xml => template_list_template_item.xml} | 2 +- ...n_list_menu.xml => template_list_menu.xml} | 0 ...ation.xml => template_list_navigation.xml} | 26 +- app/src/main/res/values-bg/strings.xml | 14 +- app/src/main/res/values/strings.xml | 14 +- 35 files changed, 509 insertions(+), 488 deletions(-) rename app/src/main/java/net/ktnx/mobileledger/db/{PatternAccount.java => TemplateAccount.java} (95%) rename app/src/main/java/net/ktnx/mobileledger/db/{PatternBase.java => TemplateBase.java} (96%) rename app/src/main/java/net/ktnx/mobileledger/db/{PatternHeader.java => TemplateHeader.java} (85%) rename app/src/main/java/net/ktnx/mobileledger/model/{PatternDetailSource.java => TemplateDetailSource.java} (70%) rename app/src/main/java/net/ktnx/mobileledger/model/{PatternDetailsItem.java => TemplateDetailsItem.java} (95%) rename app/src/main/java/net/ktnx/mobileledger/ui/{PatternDetailSourceSelectorFragment.java => TemplateDetailSourceSelectorFragment.java} (80%) rename app/src/main/java/net/ktnx/mobileledger/ui/{PatternDetailSourceSelectorModel.java => TemplateDetailSourceSelectorModel.java} (77%) rename app/src/main/java/net/ktnx/mobileledger/ui/{PatternDetailSourceSelectorRecyclerViewAdapter.java => TemplateDetailSourceSelectorRecyclerViewAdapter.java} (71%) rename app/src/main/java/net/ktnx/mobileledger/ui/{patterns/PatternDetailsAdapter.java => templates/TemplateDetailsAdapter.java} (65%) rename app/src/main/java/net/ktnx/mobileledger/ui/{patterns/PatternDetailsFragment.java => templates/TemplateDetailsFragment.java} (77%) rename app/src/main/java/net/ktnx/mobileledger/ui/{patterns/PatternDetailsViewModel.java => templates/TemplateDetailsViewModel.java} (72%) rename app/src/main/java/net/ktnx/mobileledger/ui/{patterns/PatternListFragment.java => templates/TemplateListFragment.java} (74%) rename app/src/main/java/net/ktnx/mobileledger/ui/{patterns/PatternViewHolder.java => templates/TemplateViewHolder.java} (63%) rename app/src/main/java/net/ktnx/mobileledger/ui/{patterns/PatternsRecyclerViewAdapter.java => templates/TemplatesRecyclerViewAdapter.java} (58%) rename app/src/main/res/layout/{activity_patterns.xml => activity_templates.xml} (96%) rename app/src/main/res/layout/{fragment_pattern_detail_source_selector.xml => fragment_template_detail_source_selector.xml} (98%) rename app/src/main/res/layout/{fragment_pattern_detail_source_selector_list.xml => fragment_template_detail_source_selector_list.xml} (88%) rename app/src/main/res/layout/{fragment_pattern_list.xml => fragment_template_list.xml} (91%) rename app/src/main/res/layout/{pattern_details_account.xml => template_details_account.xml} (78%) rename app/src/main/res/layout/{pattern_details_fragment.xml => template_details_fragment.xml} (91%) rename app/src/main/res/layout/{pattern_details_header.xml => template_details_header.xml} (77%) rename app/src/main/res/layout/{pattern_layout.xml => template_list_template_item.xml} (95%) rename app/src/main/res/menu/{pattern_list_menu.xml => template_list_menu.xml} (100%) rename app/src/main/res/navigation/{pattern_list_navigation.xml => template_list_navigation.xml} (61%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 21a7e5ad..81183ea6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,8 +32,8 @@ android:supportsRtl="true" tools:ignore="GoogleAppIndexingWarning"> > getPatternAccounts(Long pattern_id); + LiveData> getPatternAccounts(Long pattern_id); @Query("SELECT * FROM pattern_accounts WHERE id = :id") - LiveData getPatternAccountById(Long id); + LiveData getPatternAccountById(Long id); // not useful for now // @Transaction 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 c3f0535a..b4713d32 100644 --- a/app/src/main/java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java +++ b/app/src/main/java/net/ktnx/mobileledger/dao/PatternHeaderDAO.java @@ -25,27 +25,27 @@ import androidx.room.Query; import androidx.room.Transaction; import androidx.room.Update; -import net.ktnx.mobileledger.db.PatternHeader; import net.ktnx.mobileledger.db.PatternWithAccounts; +import net.ktnx.mobileledger.db.TemplateHeader; import java.util.List; @Dao public interface PatternHeaderDAO { @Insert() - long insert(PatternHeader item); + long insert(TemplateHeader item); @Update - void update(PatternHeader... items); + void update(TemplateHeader... items); @Delete - void delete(PatternHeader item); + void delete(TemplateHeader item); @Query("SELECT * FROM patterns ORDER BY UPPER(name)") - LiveData> getPatterns(); + LiveData> getPatterns(); @Query("SELECT * FROM patterns WHERE id = :id") - LiveData getPattern(Long id); + LiveData getPattern(Long id); @Transaction @Query("SELECT * FROM patterns WHERE id = :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 6bcae84f..80652ed1 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/DB.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/DB.java @@ -30,7 +30,7 @@ import net.ktnx.mobileledger.dao.PatternAccountDAO; import net.ktnx.mobileledger.dao.PatternHeaderDAO; import net.ktnx.mobileledger.utils.MobileLedgerDatabase; -@Database(version = 53, entities = {PatternHeader.class, PatternAccount.class, Currency.class}) +@Database(version = 53, entities = {TemplateHeader.class, TemplateAccount.class, Currency.class}) abstract public class DB extends RoomDatabase { private static DB instance; public static DB get() { diff --git a/app/src/main/java/net/ktnx/mobileledger/db/PatternWithAccounts.java b/app/src/main/java/net/ktnx/mobileledger/db/PatternWithAccounts.java index 8992fe18..9f171b1b 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/PatternWithAccounts.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/PatternWithAccounts.java @@ -24,9 +24,9 @@ import java.util.List; public class PatternWithAccounts { @Embedded - public PatternHeader header; + public TemplateHeader header; @Relation(parentColumn = "id", entityColumn = "pattern_id") - public List accounts; + public List accounts; public Long getId() { return header.getId(); diff --git a/app/src/main/java/net/ktnx/mobileledger/db/PatternAccount.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java similarity index 95% rename from app/src/main/java/net/ktnx/mobileledger/db/PatternAccount.java rename to app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java index 3ebd51da..92b29080 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/PatternAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java @@ -31,11 +31,11 @@ import org.jetbrains.annotations.NotNull; @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 = PatternHeader.class), + entity = TemplateHeader.class), @ForeignKey(childColumns = "currency", parentColumns = "id", entity = Currency.class) }) -public class PatternAccount extends PatternBase { +public class TemplateAccount extends TemplateBase { @NonNull @ColumnInfo(name = "pattern_id") private Long patternId; @@ -63,7 +63,7 @@ public class PatternAccount extends PatternBase { private Integer accountCommentMatchGroup; @ColumnInfo(name = "negate_amount") private Boolean negateAmount; - public PatternAccount(@NotNull Long id, @NonNull Long patternId, @NonNull Long position) { + public TemplateAccount(@NotNull Long id, @NonNull Long patternId, @NonNull Long position) { this.id = id; this.patternId = patternId; this.position = position; diff --git a/app/src/main/java/net/ktnx/mobileledger/db/PatternBase.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateBase.java similarity index 96% rename from app/src/main/java/net/ktnx/mobileledger/db/PatternBase.java rename to app/src/main/java/net/ktnx/mobileledger/db/TemplateBase.java index 5d048e84..83a963ac 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/PatternBase.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateBase.java @@ -17,4 +17,4 @@ package net.ktnx.mobileledger.db; -public class PatternBase {} +public class TemplateBase {} diff --git a/app/src/main/java/net/ktnx/mobileledger/db/PatternHeader.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java similarity index 85% rename from app/src/main/java/net/ktnx/mobileledger/db/PatternHeader.java rename to app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java index c6223c4f..301b100c 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/PatternHeader.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java @@ -1,3 +1,20 @@ +/* + * Copyright © 2021 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your opinion), any later version. + * + * MoLe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License terms for details. + * + * You should have received a copy of the GNU General Public License + * along with MoLe. If not, see . + */ + package net.ktnx.mobileledger.db; import androidx.annotation.NonNull; @@ -13,7 +30,7 @@ import org.jetbrains.annotations.NotNull; @Entity(tableName = "patterns", indices = {@Index(name = "un_patterns_id", value = "id", unique = true)}) -public class PatternHeader extends PatternBase { +public class TemplateHeader extends TemplateBase { @PrimaryKey(autoGenerate = true) @NonNull private Long id; @@ -45,8 +62,8 @@ public class PatternHeader extends PatternBase { private Integer dateDay; @ColumnInfo(name = "date_day_match_group") private Integer dateDayMatchGroup; - public PatternHeader(@NotNull Long id, @NonNull String name, - @NonNull String regularExpression) { + public TemplateHeader(@NotNull Long id, @NonNull String name, + @NonNull String regularExpression) { this.id = id; this.name = name; this.regularExpression = regularExpression; @@ -142,10 +159,10 @@ public class PatternHeader extends PatternBase { public boolean equals(@Nullable Object obj) { if (obj == null) return false; - if (!(obj instanceof PatternHeader)) + if (!(obj instanceof TemplateHeader)) return false; - PatternHeader o = (PatternHeader) obj; + TemplateHeader o = (TemplateHeader) obj; return Misc.equalLongs(id, o.id) && Misc.equalStrings(name, o.name) && Misc.equalStrings(regularExpression, o.regularExpression) && diff --git a/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailSource.java b/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailSource.java similarity index 70% rename from app/src/main/java/net/ktnx/mobileledger/model/PatternDetailSource.java rename to app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailSource.java index 5b8f378d..611bcfca 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailSource.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailSource.java @@ -22,26 +22,26 @@ import androidx.recyclerview.widget.DiffUtil; import java.io.Serializable; -public class PatternDetailSource implements Serializable { - public static final DiffUtil.ItemCallback DIFF_CALLBACK = - new DiffUtil.ItemCallback() { +public class TemplateDetailSource implements Serializable { + public static final DiffUtil.ItemCallback DIFF_CALLBACK = + new DiffUtil.ItemCallback() { @Override - public boolean areItemsTheSame(@NonNull PatternDetailSource oldItem, - @NonNull PatternDetailSource newItem) { + public boolean areItemsTheSame(@NonNull TemplateDetailSource oldItem, + @NonNull TemplateDetailSource newItem) { return oldItem.groupNumber == newItem.groupNumber; } @Override - public boolean areContentsTheSame(@NonNull PatternDetailSource oldItem, - @NonNull PatternDetailSource newItem) { + public boolean areContentsTheSame(@NonNull TemplateDetailSource oldItem, + @NonNull TemplateDetailSource newItem) { return oldItem.matchedText.equals(newItem.matchedText); } }; private short groupNumber; private String matchedText; - public PatternDetailSource() { + public TemplateDetailSource() { } - public PatternDetailSource(short groupNumber, String matchedText) { + public TemplateDetailSource(short groupNumber, String matchedText) { this.groupNumber = groupNumber; this.matchedText = matchedText; } diff --git a/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java b/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java similarity index 95% rename from app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java rename to app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java index eeab37ae..71992276 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java @@ -22,9 +22,9 @@ import android.content.res.Resources; import androidx.annotation.NonNull; import net.ktnx.mobileledger.R; -import net.ktnx.mobileledger.db.PatternAccount; -import net.ktnx.mobileledger.db.PatternBase; -import net.ktnx.mobileledger.db.PatternHeader; +import net.ktnx.mobileledger.db.TemplateAccount; +import net.ktnx.mobileledger.db.TemplateBase; +import net.ktnx.mobileledger.db.TemplateHeader; import net.ktnx.mobileledger.utils.Misc; import org.jetbrains.annotations.Contract; @@ -34,28 +34,28 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -abstract public class PatternDetailsItem { +abstract public class TemplateDetailsItem { private final Type type; protected Long id; protected Long position; - protected PatternDetailsItem(Type type) { + protected TemplateDetailsItem(Type type) { this.type = type; } @Contract(" -> new") - public static @NotNull PatternDetailsItem.Header createHeader() { + public static @NotNull TemplateDetailsItem.Header createHeader() { return new Header(); } - public static @NotNull PatternDetailsItem.Header createHeader(Header origin) { + public static @NotNull TemplateDetailsItem.Header createHeader(Header origin) { return new Header(origin); } @Contract("-> new") - public static @NotNull PatternDetailsItem.AccountRow createAccountRow() { + public static @NotNull TemplateDetailsItem.AccountRow createAccountRow() { return new AccountRow(); } - public static PatternDetailsItem fromRoomObject(PatternBase p) { - if (p instanceof PatternHeader) { - PatternHeader ph = (PatternHeader) p; + public static TemplateDetailsItem fromRoomObject(TemplateBase p) { + if (p instanceof TemplateHeader) { + TemplateHeader ph = (TemplateHeader) p; Header header = createHeader(); header.setId(ph.getId()); header.setName(ph.getName()); @@ -90,8 +90,8 @@ abstract public class PatternDetailsItem { return header; } - else if (p instanceof PatternAccount) { - PatternAccount pa = (PatternAccount) p; + else if (p instanceof TemplateAccount) { + TemplateAccount pa = (TemplateAccount) p; AccountRow acc = createAccountRow(); acc.setId(pa.getId()); @@ -269,7 +269,7 @@ abstract public class PatternDetailsItem { public static final int accountItem = 1; } - public static class AccountRow extends PatternDetailsItem { + public static class AccountRow extends TemplateDetailsItem { private final PossiblyMatchedValue accountName = PossiblyMatchedValue.withLiteralString(""); private final PossiblyMatchedValue accountComment = @@ -364,8 +364,8 @@ abstract public class PatternDetailsItem { public void switchToLiteralAccountComment() { accountComment.switchToLiteral(); } - public PatternAccount toDBO(@NonNull Long patternId) { - PatternAccount result = new PatternAccount(id, patternId, position); + public TemplateAccount toDBO(@NonNull Long patternId) { + TemplateAccount result = new TemplateAccount(id, patternId, position); if (accountName.hasLiteralValue()) result.setAccountName(accountName.getValue()); @@ -390,7 +390,7 @@ abstract public class PatternDetailsItem { } } - public static class Header extends PatternDetailsItem { + public static class Header extends TemplateDetailsItem { private String pattern = ""; private String testText = ""; private Pattern compiledPattern; @@ -590,8 +590,8 @@ abstract public class PatternDetailsItem { dateMonth.switchToLiteral(); } public void switchToLiteralDateDay() { dateDay.switchToLiteral(); } - public PatternHeader toDBO() { - PatternHeader result = new PatternHeader(id, name, pattern); + public TemplateHeader toDBO() { + TemplateHeader result = new TemplateHeader(id, name, pattern); if (Misc.emptyIsNull(testText) != null) result.setTestText(testText); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/PatternDetailSourceSelectorFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/TemplateDetailSourceSelectorFragment.java similarity index 80% rename from app/src/main/java/net/ktnx/mobileledger/ui/PatternDetailSourceSelectorFragment.java rename to app/src/main/java/net/ktnx/mobileledger/ui/TemplateDetailSourceSelectorFragment.java index 7a8a954d..1bb48404 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/PatternDetailSourceSelectorFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/TemplateDetailSourceSelectorFragment.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2021 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 @@ -33,8 +33,8 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import net.ktnx.mobileledger.R; -import net.ktnx.mobileledger.databinding.FragmentPatternDetailSourceSelectorListBinding; -import net.ktnx.mobileledger.model.PatternDetailSource; +import net.ktnx.mobileledger.databinding.FragmentTemplateDetailSourceSelectorListBinding; +import net.ktnx.mobileledger.model.TemplateDetailSource; import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.Misc; @@ -48,7 +48,7 @@ import java.util.regex.Pattern; * Activities containing this fragment MUST implement the {@link OnSourceSelectedListener} * interface. */ -public class PatternDetailSourceSelectorFragment extends AppCompatDialogFragment +public class TemplateDetailSourceSelectorFragment extends AppCompatDialogFragment implements OnSourceSelectedListener { public static final int DEFAULT_COLUMN_COUNT = 1; @@ -56,8 +56,8 @@ public class PatternDetailSourceSelectorFragment extends AppCompatDialogFragment public static final String ARG_PATTERN = "pattern"; public static final String ARG_TEST_TEXT = "test-text"; private int mColumnCount = DEFAULT_COLUMN_COUNT; - private ArrayList mSources; - private PatternDetailSourceSelectorModel model; + private ArrayList mSources; + private TemplateDetailSourceSelectorModel model; private OnSourceSelectedListener onSourceSelectedListener; private @StringRes int mPatternProblem; @@ -66,16 +66,16 @@ public class PatternDetailSourceSelectorFragment extends AppCompatDialogFragment * Mandatory empty constructor for the fragment manager to instantiate the * fragment (e.g. upon screen orientation changes). */ - public PatternDetailSourceSelectorFragment() { + public TemplateDetailSourceSelectorFragment() { } @SuppressWarnings("unused") - public static PatternDetailSourceSelectorFragment newInstance() { + public static TemplateDetailSourceSelectorFragment newInstance() { return newInstance(DEFAULT_COLUMN_COUNT, null, null); } - public static PatternDetailSourceSelectorFragment newInstance(int columnCount, - @Nullable String pattern, - @Nullable String testText) { - PatternDetailSourceSelectorFragment fragment = new PatternDetailSourceSelectorFragment(); + public static TemplateDetailSourceSelectorFragment newInstance(int columnCount, + @Nullable String pattern, + @Nullable String testText) { + TemplateDetailSourceSelectorFragment fragment = new TemplateDetailSourceSelectorFragment(); Bundle args = new Bundle(); args.putInt(ARG_COLUMN_COUNT, columnCount); if (pattern != null) @@ -103,14 +103,14 @@ public class PatternDetailSourceSelectorFragment extends AppCompatDialogFragment else { Pattern pattern = Pattern.compile(patternText); Matcher matcher = pattern.matcher(testText); - Logger.debug("patterns", + Logger.debug("templates", String.format("Trying to match pattern '%s' against text '%s'", patternText, testText)); if (matcher.matches()) { if (matcher.groupCount() >= 0) { - ArrayList list = new ArrayList<>(); + ArrayList list = new ArrayList<>(); for (short g = 1; g <= matcher.groupCount(); g++) { - list.add(new PatternDetailSource(g, matcher.group(g))); + list.add(new TemplateDetailSource(g, matcher.group(g))); } mSources = list; } @@ -130,11 +130,11 @@ public class PatternDetailSourceSelectorFragment extends AppCompatDialogFragment public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { Context context = requireContext(); Dialog csd = new Dialog(context); - FragmentPatternDetailSourceSelectorListBinding b = - FragmentPatternDetailSourceSelectorListBinding.inflate( + FragmentTemplateDetailSourceSelectorListBinding b = + FragmentTemplateDetailSourceSelectorListBinding.inflate( LayoutInflater.from(context)); csd.setContentView(b.getRoot()); - csd.setTitle(R.string.choose_pattern_detail_source_label); + csd.setTitle(R.string.choose_template_detail_source_label); if (mSources != null && !mSources.isEmpty()) { RecyclerView recyclerView = b.list; @@ -145,13 +145,13 @@ public class PatternDetailSourceSelectorFragment extends AppCompatDialogFragment else { recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount)); } - model = new ViewModelProvider(this).get(PatternDetailSourceSelectorModel.class); + model = new ViewModelProvider(this).get(TemplateDetailSourceSelectorModel.class); if (onSourceSelectedListener != null) model.setOnSourceSelectedListener(onSourceSelectedListener); model.setSourcesList(mSources); - PatternDetailSourceSelectorRecyclerViewAdapter adapter = - new PatternDetailSourceSelectorRecyclerViewAdapter(); + TemplateDetailSourceSelectorRecyclerViewAdapter adapter = + new TemplateDetailSourceSelectorRecyclerViewAdapter(); model.groups.observe(this, adapter::submitList); recyclerView.setAdapter(adapter); @@ -159,8 +159,8 @@ public class PatternDetailSourceSelectorFragment extends AppCompatDialogFragment } else { b.list.setVisibility(View.GONE); - b.patternError.setText(mPatternProblem); - b.patternError.setVisibility(View.VISIBLE); + b.templateError.setText(mPatternProblem); + b.templateError.setVisibility(View.VISIBLE); } b.literalButton.setOnClickListener(v -> onSourceSelected(true, (short) -1)); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/PatternDetailSourceSelectorModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/TemplateDetailSourceSelectorModel.java similarity index 77% rename from app/src/main/java/net/ktnx/mobileledger/ui/PatternDetailSourceSelectorModel.java rename to app/src/main/java/net/ktnx/mobileledger/ui/TemplateDetailSourceSelectorModel.java index b88c6765..46f58852 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/PatternDetailSourceSelectorModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/TemplateDetailSourceSelectorModel.java @@ -1,5 +1,5 @@ /* - * Copyright © 2020 Damyan Ivanov. + * Copyright © 2021 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 @@ -20,15 +20,15 @@ package net.ktnx.mobileledger.ui; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; -import net.ktnx.mobileledger.model.PatternDetailSource; +import net.ktnx.mobileledger.model.TemplateDetailSource; import java.util.ArrayList; import java.util.List; -public class PatternDetailSourceSelectorModel extends ViewModel { - public final MutableLiveData> groups = new MutableLiveData<>(); +public class TemplateDetailSourceSelectorModel extends ViewModel { + public final MutableLiveData> groups = new MutableLiveData<>(); private OnSourceSelectedListener selectionListener; - public PatternDetailSourceSelectorModel() { + public TemplateDetailSourceSelectorModel() { } void setOnSourceSelectedListener(OnSourceSelectedListener listener) { selectionListener = listener; @@ -40,7 +40,7 @@ public class PatternDetailSourceSelectorModel extends ViewModel { if (selectionListener != null) selectionListener.onSourceSelected(literal, group); } - public void setSourcesList(ArrayList mSources) { + public void setSourcesList(ArrayList mSources) { groups.setValue(mSources); } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/PatternDetailSourceSelectorRecyclerViewAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/TemplateDetailSourceSelectorRecyclerViewAdapter.java similarity index 71% rename from app/src/main/java/net/ktnx/mobileledger/ui/PatternDetailSourceSelectorRecyclerViewAdapter.java rename to app/src/main/java/net/ktnx/mobileledger/ui/TemplateDetailSourceSelectorRecyclerViewAdapter.java index 91a3c4d7..060bf138 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/PatternDetailSourceSelectorRecyclerViewAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/TemplateDetailSourceSelectorRecyclerViewAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2021 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 @@ -23,29 +23,29 @@ import android.view.ViewGroup; import androidx.recyclerview.widget.ListAdapter; import androidx.recyclerview.widget.RecyclerView; -import net.ktnx.mobileledger.databinding.FragmentPatternDetailSourceSelectorBinding; -import net.ktnx.mobileledger.model.PatternDetailSource; +import net.ktnx.mobileledger.databinding.FragmentTemplateDetailSourceSelectorBinding; +import net.ktnx.mobileledger.model.TemplateDetailSource; import org.jetbrains.annotations.NotNull; /** - * {@link RecyclerView.Adapter} that can display a {@link PatternDetailSource} and makes a call + * {@link RecyclerView.Adapter} that can display a {@link TemplateDetailSource} and makes a call * to the * specified {@link OnSourceSelectedListener}. */ -public class PatternDetailSourceSelectorRecyclerViewAdapter extends - ListAdapter { +public class TemplateDetailSourceSelectorRecyclerViewAdapter extends + ListAdapter { private OnSourceSelectedListener sourceSelectedListener; - public PatternDetailSourceSelectorRecyclerViewAdapter() { - super(PatternDetailSource.DIFF_CALLBACK); + public TemplateDetailSourceSelectorRecyclerViewAdapter() { + super(TemplateDetailSource.DIFF_CALLBACK); } @NotNull @Override public ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) { - FragmentPatternDetailSourceSelectorBinding b = - FragmentPatternDetailSourceSelectorBinding.inflate( + FragmentTemplateDetailSourceSelectorBinding b = + FragmentTemplateDetailSourceSelectorBinding.inflate( LayoutInflater.from(parent.getContext()), parent, false); return new ViewHolder(b); } @@ -60,7 +60,7 @@ public class PatternDetailSourceSelectorRecyclerViewAdapter extends public void resetSourceSelectedListener() { sourceSelectedListener = null; } - public void notifySourceSelected(PatternDetailSource item) { + public void notifySourceSelected(TemplateDetailSource item) { if (null != sourceSelectedListener) sourceSelectedListener.onSourceSelected(false, item.getGroupNumber()); } @@ -69,10 +69,10 @@ public class PatternDetailSourceSelectorRecyclerViewAdapter extends sourceSelectedListener.onSourceSelected(true, (short) -1); } public class ViewHolder extends RecyclerView.ViewHolder { - private final FragmentPatternDetailSourceSelectorBinding b; - private PatternDetailSource mItem; + private final FragmentTemplateDetailSourceSelectorBinding b; + private TemplateDetailSource mItem; - ViewHolder(FragmentPatternDetailSourceSelectorBinding binding) { + ViewHolder(FragmentTemplateDetailSourceSelectorBinding binding) { super(binding.getRoot()); b = binding; @@ -86,7 +86,7 @@ public class PatternDetailSourceSelectorRecyclerViewAdapter extends return super.toString() + " " + b.groupNumber.getText() + ": '" + b.matchedText.getText() + "'"; } - void bindTo(PatternDetailSource item) { + void bindTo(TemplateDetailSource item) { mItem = item; b.groupNumber.setText(String.valueOf(item.getGroupNumber())); b.matchedText.setText(item.getMatchedText()); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 3ed89291..291ad7c4 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -55,8 +55,8 @@ import net.ktnx.mobileledger.model.MobileLedgerProfile; import net.ktnx.mobileledger.ui.MainModel; import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment; import net.ktnx.mobileledger.ui.new_transaction.NewTransactionActivity; -import net.ktnx.mobileledger.ui.patterns.PatternsActivity; import net.ktnx.mobileledger.ui.profiles.ProfilesRecyclerViewAdapter; +import net.ktnx.mobileledger.ui.templates.TemplatesActivity; import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment; import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.Logger; @@ -302,7 +302,7 @@ public class MainActivity extends ProfileThemedActivity { b.navPatterns.setOnClickListener(this::onPatternsClick); } private void onPatternsClick(View view) { - Intent intent = new Intent(this, PatternsActivity.class); + Intent intent = new Intent(this, TemplatesActivity.class); startActivity(intent); } private void scheduleDataRetrievalIfStale(long lastUpdate) { 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 6be1bd37..e708c5fe 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 @@ -49,15 +49,15 @@ import com.google.android.material.snackbar.Snackbar; import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.db.DB; -import net.ktnx.mobileledger.db.PatternAccount; -import net.ktnx.mobileledger.db.PatternHeader; +import net.ktnx.mobileledger.db.TemplateAccount; +import net.ktnx.mobileledger.db.TemplateHeader; import net.ktnx.mobileledger.json.API; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.model.LedgerTransaction; import net.ktnx.mobileledger.model.LedgerTransactionAccount; import net.ktnx.mobileledger.model.MobileLedgerProfile; import net.ktnx.mobileledger.ui.QRScanCapableFragment; -import net.ktnx.mobileledger.ui.patterns.PatternsActivity; +import net.ktnx.mobileledger.ui.templates.TemplatesActivity; import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.Misc; import net.ktnx.mobileledger.utils.SimpleDate; @@ -90,9 +90,9 @@ public class NewTransactionFragment extends QRScanCapableFragment { setHasOptionsMenu(true); } private void startNewPatternActivity(String scanned) { - Intent intent = new Intent(requireContext(), PatternsActivity.class); + Intent intent = new Intent(requireContext(), TemplatesActivity.class); Bundle args = new Bundle(); - args.putString(PatternsActivity.ARG_ADD_PATTERN, scanned); + args.putString(TemplatesActivity.ARG_ADD_TEMPLATE, scanned); requireContext().startActivity(intent, args); } private void alertNoPatternMatch(String scanned) { @@ -110,13 +110,13 @@ public class NewTransactionFragment extends QRScanCapableFragment { if (Misc.emptyIsNull(text) == null) return; - LiveData> allPatterns = DB.get() - .getPatternDAO() - .getPatterns(); + LiveData> allPatterns = DB.get() + .getPatternDAO() + .getPatterns(); allPatterns.observe(getViewLifecycleOwner(), patternHeaders -> { - ArrayList matchingPatterns = new ArrayList<>(); + ArrayList matchingPatterns = new ArrayList<>(); - for (PatternHeader ph : patternHeaders) { + for (TemplateHeader ph : patternHeaders) { String patternSource = ph.getRegularExpression(); if (Misc.emptyIsNull(patternSource) == null) continue; @@ -147,7 +147,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { choosePattern(matchingPatterns, text); }); } - private void choosePattern(ArrayList matchingPatterns, String matchedText) { + private void choosePattern(ArrayList matchingPatterns, String matchedText) { final String patternNameColumn = "name"; AbstractCursor cursor = new AbstractCursor() { @Override @@ -207,7 +207,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { .create() .show(); } - private void applyPattern(PatternHeader patternHeader, String text) { + private void applyPattern(TemplateHeader patternHeader, String text) { Pattern pattern = Pattern.compile(patternHeader.getRegularExpression()); Matcher m = pattern.matcher(text); @@ -262,7 +262,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { .observe(getViewLifecycleOwner(), entry -> { int rowIndex = 0; final boolean accountsInInitialState = viewModel.accountsInInitialState(); - for (PatternAccount acc : entry.accounts) { + for (TemplateAccount acc : entry.accounts) { rowIndex++; String accountName = extractStringFromMatches(m, acc.getAccountNameMatchGroup(), diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java similarity index 65% rename from app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsAdapter.java rename to app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java index 4fd35a52..4f70f846 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java @@ -15,7 +15,7 @@ * along with MoLe. If not, see . */ -package net.ktnx.mobileledger.ui.patterns; +package net.ktnx.mobileledger.ui.templates; import android.text.Editable; import android.text.TextWatcher; @@ -30,13 +30,13 @@ import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; import net.ktnx.mobileledger.R; -import net.ktnx.mobileledger.databinding.PatternDetailsAccountBinding; -import net.ktnx.mobileledger.databinding.PatternDetailsHeaderBinding; -import net.ktnx.mobileledger.db.PatternBase; +import net.ktnx.mobileledger.databinding.TemplateDetailsAccountBinding; +import net.ktnx.mobileledger.databinding.TemplateDetailsHeaderBinding; +import net.ktnx.mobileledger.db.TemplateBase; import net.ktnx.mobileledger.model.Data; -import net.ktnx.mobileledger.model.PatternDetailsItem; -import net.ktnx.mobileledger.ui.PatternDetailSourceSelectorFragment; +import net.ktnx.mobileledger.model.TemplateDetailsItem; import net.ktnx.mobileledger.ui.QRScanCapableFragment; +import net.ktnx.mobileledger.ui.TemplateDetailSourceSelectorFragment; import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.Misc; @@ -49,20 +49,20 @@ import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; -class PatternDetailsAdapter extends RecyclerView.Adapter { - private static final String D_PATTERN_UI = "pattern-ui"; - private final AsyncListDiffer differ; - public PatternDetailsAdapter() { +class TemplateDetailsAdapter extends RecyclerView.Adapter { + private static final String D_TEMPLATE_UI = "template-ui"; + private final AsyncListDiffer differ; + public TemplateDetailsAdapter() { super(); setHasStableIds(true); - differ = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback() { + differ = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback() { @Override - public boolean areItemsTheSame(@NonNull PatternDetailsItem oldItem, - @NonNull PatternDetailsItem newItem) { + public boolean areItemsTheSame(@NonNull TemplateDetailsItem oldItem, + @NonNull TemplateDetailsItem newItem) { if (oldItem.getType() != newItem.getType()) return false; if (oldItem.getType() - .equals(PatternDetailsItem.Type.HEADER)) + .equals(TemplateDetailsItem.Type.HEADER)) return true; // only one header item, ever // the rest is comparing two account row items return oldItem.asAccountRowItem() @@ -70,19 +70,19 @@ class PatternDetailsAdapter extends RecyclerView.Adapter items) { - ArrayList list = new ArrayList<>(); - for (PatternBase p : items) { - PatternDetailsItem item = PatternDetailsItem.fromRoomObject(p); + public void setTemplateItems(List items) { + ArrayList list = new ArrayList<>(); + for (TemplateBase p : items) { + TemplateDetailsItem item = TemplateDetailsItem.fromRoomObject(p); list.add(item); } setItems(list); } - public void setItems(List items) { + public void setItems(List items) { differ.submitList(items); } public String getMatchGroupText(int groupNumber) { - PatternDetailsItem.Header header = getHeader(); + TemplateDetailsItem.Header header = getHeader(); Pattern p = header.getCompiledPattern(); if (p == null) return null; @@ -157,7 +157,7 @@ class PatternDetailsAdapter extends RecyclerView.Adapter { if (literal) { @@ -318,107 +318,109 @@ class PatternDetailsAdapter extends RecyclerView.Adapter selectHeaderDetailSource(v, HeaderDetail.DATE_YEAR)); - b.patternDetailsYearSource.setOnClickListener( + b.templateDetailsYearSource.setOnClickListener( v -> selectHeaderDetailSource(v, HeaderDetail.DATE_YEAR)); if (header.hasLiteralDateMonth()) { - b.patternDetailsMonthSource.setText(R.string.pattern_details_source_literal); + b.templateDetailsMonthSource.setText(R.string.template_details_source_literal); final Integer dateMonth = header.getDateMonth(); - b.patternDetailsDateMonth.setText( + b.templateDetailsDateMonth.setText( (dateMonth == null) ? null : String.valueOf(dateMonth)); - b.patternDetailsDateMonthLayout.setVisibility(View.VISIBLE); + b.templateDetailsDateMonthLayout.setVisibility(View.VISIBLE); } else { - b.patternDetailsDateMonthLayout.setVisibility(View.GONE); - b.patternDetailsMonthSource.setText( + b.templateDetailsDateMonthLayout.setVisibility(View.GONE); + b.templateDetailsMonthSource.setText( String.format(Locale.US, "Group %d (%s)", header.getDateMonthMatchGroup(), getMatchGroupText(header.getDateMonthMatchGroup()))); } - b.patternDetailsMonthSourceLabel.setOnClickListener( + b.templateDetailsMonthSourceLabel.setOnClickListener( v -> selectHeaderDetailSource(v, HeaderDetail.DATE_MONTH)); - b.patternDetailsMonthSource.setOnClickListener( + b.templateDetailsMonthSource.setOnClickListener( v -> selectHeaderDetailSource(v, HeaderDetail.DATE_MONTH)); if (header.hasLiteralDateDay()) { - b.patternDetailsDaySource.setText(R.string.pattern_details_source_literal); + b.templateDetailsDaySource.setText(R.string.template_details_source_literal); final Integer dateDay = header.getDateDay(); - b.patternDetailsDateDay.setText((dateDay == null) ? null : String.valueOf(dateDay)); - b.patternDetailsDateDayLayout.setVisibility(View.VISIBLE); + b.templateDetailsDateDay.setText( + (dateDay == null) ? null : String.valueOf(dateDay)); + b.templateDetailsDateDayLayout.setVisibility(View.VISIBLE); } else { - b.patternDetailsDateDayLayout.setVisibility(View.GONE); - b.patternDetailsDaySource.setText( + b.templateDetailsDateDayLayout.setVisibility(View.GONE); + b.templateDetailsDaySource.setText( String.format(Locale.US, "Group %d (%s)", header.getDateDayMatchGroup(), getMatchGroupText(header.getDateDayMatchGroup()))); } - b.patternDetailsDaySourceLabel.setOnClickListener( + b.templateDetailsDaySourceLabel.setOnClickListener( v -> selectHeaderDetailSource(v, HeaderDetail.DATE_DAY)); - b.patternDetailsDaySource.setOnClickListener( + b.templateDetailsDaySource.setOnClickListener( v -> selectHeaderDetailSource(v, HeaderDetail.DATE_DAY)); if (header.hasLiteralTransactionDescription()) { - b.patternTransactionDescriptionSource.setText( - R.string.pattern_details_source_literal); + b.templateTransactionDescriptionSource.setText( + R.string.template_details_source_literal); b.transactionDescription.setText(header.getTransactionDescription()); b.transactionDescriptionLayout.setVisibility(View.VISIBLE); } else { b.transactionDescriptionLayout.setVisibility(View.GONE); - b.patternTransactionDescriptionSource.setText( + b.templateTransactionDescriptionSource.setText( String.format(Locale.US, "Group %d (%s)", header.getTransactionDescriptionMatchGroup(), getMatchGroupText(header.getTransactionDescriptionMatchGroup()))); } - b.patternTransactionDescriptionSourceLabel.setOnClickListener( + b.templateTransactionDescriptionSourceLabel.setOnClickListener( v -> selectHeaderDetailSource(v, HeaderDetail.DESCRIPTION)); - b.patternTransactionDescriptionSource.setOnClickListener( + b.templateTransactionDescriptionSource.setOnClickListener( v -> selectHeaderDetailSource(v, HeaderDetail.DESCRIPTION)); if (header.hasLiteralTransactionComment()) { - b.patternTransactionCommentSource.setText(R.string.pattern_details_source_literal); + b.templateTransactionCommentSource.setText( + R.string.template_details_source_literal); b.transactionComment.setText(header.getTransactionComment()); b.transactionCommentLayout.setVisibility(View.VISIBLE); } else { b.transactionCommentLayout.setVisibility(View.GONE); - b.patternTransactionCommentSource.setText(String.format(Locale.US, "Group %d (%s)", + b.templateTransactionCommentSource.setText(String.format(Locale.US, "Group %d (%s)", header.getTransactionCommentMatchGroup(), getMatchGroupText(header.getTransactionCommentMatchGroup()))); } - b.patternTransactionCommentSourceLabel.setOnClickListener( + b.templateTransactionCommentSourceLabel.setOnClickListener( v -> selectHeaderDetailSource(v, HeaderDetail.COMMENT)); - b.patternTransactionCommentSource.setOnClickListener( + b.templateTransactionCommentSource.setOnClickListener( v -> selectHeaderDetailSource(v, HeaderDetail.COMMENT)); - b.patternDetailsHeadScanQrButton.setOnClickListener(this::scanTestQR); + b.templateDetailsHeadScanQrButton.setOnClickListener(this::scanTestQR); } private void scanTestQR(View view) { @@ -427,8 +429,8 @@ class PatternDetailsAdapter extends RecyclerView.Adapter { + b.templateDetailsAccountAmount.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) return; - PatternDetailsItem.AccountRow accRow = getItem(); + TemplateDetailsItem.AccountRow accRow = getItem(); if (!accRow.hasLiteralAmount()) return; Float amt = accRow.getAmount(); if (amt == null) return; - b.patternDetailsAccountAmount.setText(Data.formatNumber(amt)); + b.templateDetailsAccountAmount.setText(Data.formatNumber(amt)); }); b.negateAmountSwitch.setOnCheckedChangeListener( (buttonView, isChecked) -> getItem().setNegateAmount(isChecked)); } @Override - void bind(PatternDetailsItem item) { - PatternDetailsItem.AccountRow accRow = item.asAccountRowItem(); + void bind(TemplateDetailsItem item) { + TemplateDetailsItem.AccountRow accRow = item.asAccountRowItem(); if (accRow.hasLiteralAccountName()) { - b.patternDetailsAccountNameLayout.setVisibility(View.VISIBLE); - b.patternDetailsAccountName.setText(accRow.getAccountName()); - b.patternDetailsAccountNameSource.setText(R.string.pattern_details_source_literal); + b.templateDetailsAccountNameLayout.setVisibility(View.VISIBLE); + b.templateDetailsAccountName.setText(accRow.getAccountName()); + b.templateDetailsAccountNameSource.setText( + R.string.template_details_source_literal); } else { - b.patternDetailsAccountNameLayout.setVisibility(View.GONE); - b.patternDetailsAccountNameSource.setText( + b.templateDetailsAccountNameLayout.setVisibility(View.GONE); + b.templateDetailsAccountNameSource.setText( String.format(Locale.US, "Group %d (%s)", accRow.getAccountNameMatchGroup(), getMatchGroupText(accRow.getAccountNameMatchGroup()))); } if (accRow.hasLiteralAccountComment()) { - b.patternDetailsAccountCommentLayout.setVisibility(View.VISIBLE); - b.patternDetailsAccountComment.setText(accRow.getAccountComment()); - b.patternDetailsAccountCommentSource.setText( - R.string.pattern_details_source_literal); + b.templateDetailsAccountCommentLayout.setVisibility(View.VISIBLE); + b.templateDetailsAccountComment.setText(accRow.getAccountComment()); + b.templateDetailsAccountCommentSource.setText( + R.string.template_details_source_literal); } else { - b.patternDetailsAccountCommentLayout.setVisibility(View.GONE); - b.patternDetailsAccountCommentSource.setText( + b.templateDetailsAccountCommentLayout.setVisibility(View.GONE); + b.templateDetailsAccountCommentSource.setText( String.format(Locale.US, "Group %d (%s)", accRow.getAccountCommentMatchGroup(), getMatchGroupText(accRow.getAccountCommentMatchGroup()))); } if (accRow.hasLiteralAmount()) { - b.patternDetailsAccountAmountSource.setText( - R.string.pattern_details_source_literal); - b.patternDetailsAccountAmount.setVisibility(View.VISIBLE); + b.templateDetailsAccountAmountSource.setText( + R.string.template_details_source_literal); + b.templateDetailsAccountAmount.setVisibility(View.VISIBLE); Float amt = accRow.getAmount(); - b.patternDetailsAccountAmount.setText((amt == null) ? null : String.format( + b.templateDetailsAccountAmount.setText((amt == null) ? null : String.format( Data.locale.getValue(), "%,4.2f", (accRow.getAmount()))); b.negateAmountSwitch.setVisibility(View.GONE); } else { - b.patternDetailsAccountAmountSource.setText( + b.templateDetailsAccountAmountSource.setText( String.format(Locale.US, "Group %d (%s)", accRow.getAmountMatchGroup(), getMatchGroupText(accRow.getAmountMatchGroup()))); - b.patternDetailsAccountAmountLayout.setVisibility(View.GONE); + b.templateDetailsAccountAmountLayout.setVisibility(View.GONE); b.negateAmountSwitch.setVisibility(View.VISIBLE); b.negateAmountSwitch.setChecked(accRow.isNegateAmount()); } - b.patternAccountNameSourceLabel.setOnClickListener( + b.templateAccountNameSourceLabel.setOnClickListener( v -> selectAccountRowDetailSource(v, AccDetail.ACCOUNT)); - b.patternDetailsAccountNameSource.setOnClickListener( + b.templateDetailsAccountNameSource.setOnClickListener( v -> selectAccountRowDetailSource(v, AccDetail.ACCOUNT)); - b.patternAccountCommentSourceLabel.setOnClickListener( + b.templateAccountCommentSourceLabel.setOnClickListener( v -> selectAccountRowDetailSource(v, AccDetail.COMMENT)); - b.patternDetailsAccountCommentSource.setOnClickListener( + b.templateDetailsAccountCommentSource.setOnClickListener( v -> selectAccountRowDetailSource(v, AccDetail.COMMENT)); - b.patternAccountAmountSourceLabel.setOnClickListener( + b.templateAccountAmountSourceLabel.setOnClickListener( v -> selectAccountRowDetailSource(v, AccDetail.AMOUNT)); - b.patternDetailsAccountAmountSource.setOnClickListener( + b.templateDetailsAccountAmountSource.setOnClickListener( v -> selectAccountRowDetailSource(v, AccDetail.AMOUNT)); } - private @NotNull PatternDetailsItem.AccountRow getItem() { + private @NotNull TemplateDetailsItem.AccountRow getItem() { return differ.getCurrentList() .get(getAdapterPosition()) .asAccountRowItem(); } private void selectAccountRowDetailSource(View v, AccDetail detail) { - PatternDetailsItem.AccountRow accRow = getItem(); - final PatternDetailsItem.Header header = getHeader(); - Logger.debug(D_PATTERN_UI, "header is " + header); - PatternDetailSourceSelectorFragment sel = - PatternDetailSourceSelectorFragment.newInstance(1, header.getPattern(), + TemplateDetailsItem.AccountRow accRow = getItem(); + final TemplateDetailsItem.Header header = getHeader(); + Logger.debug(D_TEMPLATE_UI, "header is " + header); + TemplateDetailSourceSelectorFragment sel = + TemplateDetailSourceSelectorFragment.newInstance(1, header.getPattern(), header.getTestText()); sel.setOnSourceSelectedListener((literal, group) -> { if (literal) { @@ -618,7 +621,7 @@ class PatternDetailsAdapter extends RecyclerView.Adapter. */ -package net.ktnx.mobileledger.ui.patterns; +package net.ktnx.mobileledger.ui.templates; import android.content.Context; import android.os.Bundle; @@ -34,25 +34,25 @@ import androidx.recyclerview.widget.LinearLayoutManager; import com.google.android.material.snackbar.Snackbar; import net.ktnx.mobileledger.R; -import net.ktnx.mobileledger.databinding.PatternDetailsFragmentBinding; +import net.ktnx.mobileledger.databinding.TemplateDetailsFragmentBinding; import net.ktnx.mobileledger.ui.QRScanCapableFragment; import net.ktnx.mobileledger.utils.Logger; -public class PatternDetailsFragment extends QRScanCapableFragment { - static final String ARG_PATTERN_ID = "pattern-id"; +public class TemplateDetailsFragment extends QRScanCapableFragment { + static final String ARG_TEMPLATE_ID = "pattern-id"; private static final String ARG_COLUMN_COUNT = "column-count"; - PatternDetailsFragmentBinding b; - private PatternDetailsViewModel mViewModel; + TemplateDetailsFragmentBinding b; + private TemplateDetailsViewModel mViewModel; private int mColumnCount = 1; private Long mPatternId; - public PatternDetailsFragment() { + public TemplateDetailsFragment() { } - public static PatternDetailsFragment newInstance(int columnCount, int patternId) { - final PatternDetailsFragment fragment = new PatternDetailsFragment(); + public static TemplateDetailsFragment newInstance(int columnCount, int patternId) { + final TemplateDetailsFragment fragment = new TemplateDetailsFragment(); Bundle args = new Bundle(); args.putInt(ARG_COLUMN_COUNT, columnCount); if (patternId > 0) - args.putInt(ARG_PATTERN_ID, patternId); + args.putInt(ARG_TEMPLATE_ID, patternId); fragment.setArguments(args); return fragment; } @@ -63,7 +63,7 @@ public class PatternDetailsFragment extends QRScanCapableFragment { final Bundle args = getArguments(); if (args != null) { mColumnCount = args.getInt(ARG_COLUMN_COUNT, 1); - mPatternId = args.getLong(ARG_PATTERN_ID, -1); + mPatternId = args.getLong(ARG_TEMPLATE_ID, -1); if (mPatternId == -1) mPatternId = null; } @@ -71,14 +71,14 @@ public class PatternDetailsFragment extends QRScanCapableFragment { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - NavController controller = ((PatternsActivity) requireActivity()).getNavController(); + NavController controller = ((TemplatesActivity) requireActivity()).getNavController(); final ViewModelStoreOwner viewModelStoreOwner = - controller.getViewModelStoreOwner(R.id.pattern_list_navigation); - mViewModel = new ViewModelProvider(viewModelStoreOwner).get(PatternDetailsViewModel.class); + controller.getViewModelStoreOwner(R.id.template_list_navigation); + mViewModel = new ViewModelProvider(viewModelStoreOwner).get(TemplateDetailsViewModel.class); mViewModel.setDefaultPatternName(getString(R.string.unnamed_pattern)); Logger.debug("flow", "PatternDetailsFragment.onCreateView(): model=" + mViewModel); - b = PatternDetailsFragmentBinding.inflate(inflater); + b = TemplateDetailsFragmentBinding.inflate(inflater); Context context = b.patternDetailsRecyclerView.getContext(); if (mColumnCount <= 1) { b.patternDetailsRecyclerView.setLayoutManager(new LinearLayoutManager(context)); @@ -89,7 +89,7 @@ public class PatternDetailsFragment extends QRScanCapableFragment { } - PatternDetailsAdapter adapter = new PatternDetailsAdapter(); + TemplateDetailsAdapter adapter = new TemplateDetailsAdapter(); b.patternDetailsRecyclerView.setAdapter(adapter); mViewModel.getItems(mPatternId) .observe(getViewLifecycleOwner(), adapter::setItems); @@ -103,7 +103,7 @@ public class PatternDetailsFragment extends QRScanCapableFragment { mViewModel.setTestText(text); } public void onSavePattern() { - mViewModel.onSavePattern(); + mViewModel.onSaveTemplate(); final Snackbar snackbar = Snackbar.make(b.getRoot(), "One Save pattern action coming up soon in a fragment near you", Snackbar.LENGTH_INDEFINITE); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsViewModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java similarity index 72% rename from app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsViewModel.java rename to app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java index 982bb47c..088b1b77 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsViewModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java @@ -15,7 +15,7 @@ * along with MoLe. If not, see . */ -package net.ktnx.mobileledger.ui.patterns; +package net.ktnx.mobileledger.ui.templates; import android.os.AsyncTask; @@ -27,10 +27,10 @@ import androidx.lifecycle.ViewModel; import net.ktnx.mobileledger.dao.PatternAccountDAO; import net.ktnx.mobileledger.dao.PatternHeaderDAO; import net.ktnx.mobileledger.db.DB; -import net.ktnx.mobileledger.db.PatternAccount; -import net.ktnx.mobileledger.db.PatternHeader; import net.ktnx.mobileledger.db.PatternWithAccounts; -import net.ktnx.mobileledger.model.PatternDetailsItem; +import net.ktnx.mobileledger.db.TemplateAccount; +import net.ktnx.mobileledger.db.TemplateHeader; +import net.ktnx.mobileledger.model.TemplateDetailsItem; import net.ktnx.mobileledger.utils.Logger; import java.util.ArrayList; @@ -39,8 +39,8 @@ import java.util.List; import java.util.Locale; import java.util.Objects; -public class PatternDetailsViewModel extends ViewModel { - private final MutableLiveData> items = +public class TemplateDetailsViewModel extends ViewModel { + private final MutableLiveData> items = new MutableLiveData<>(Collections.emptyList()); private Long mPatternId; private String mDefaultPatternName; @@ -52,14 +52,14 @@ public class PatternDetailsViewModel extends ViewModel { } public void resetItems() { - ArrayList newList = new ArrayList<>(); - final PatternDetailsItem.Header header = PatternDetailsItem.createHeader(); + ArrayList newList = new ArrayList<>(); + final TemplateDetailsItem.Header header = TemplateDetailsItem.createHeader(); header.setName(mDefaultPatternName); header.setId(0); newList.add(header); while (newList.size() < 3) { - final PatternDetailsItem.AccountRow aRow = PatternDetailsItem.createAccountRow(); + final TemplateDetailsItem.AccountRow aRow = TemplateDetailsItem.createAccountRow(); aRow.setId(newList.size() + 1); newList.add(aRow); } @@ -67,24 +67,24 @@ public class PatternDetailsViewModel extends ViewModel { items.setValue(newList); } private void checkItemConsistency() { - ArrayList newList = new ArrayList<>(items.getValue()); + ArrayList newList = new ArrayList<>(items.getValue()); boolean changes = false; if (newList.size() < 1) { - final PatternDetailsItem.Header header = PatternDetailsItem.createHeader(); + final TemplateDetailsItem.Header header = TemplateDetailsItem.createHeader(); header.setName(mDefaultPatternName); newList.add(header); changes = true; } while (newList.size() < 3) { - newList.add(PatternDetailsItem.createAccountRow()); + newList.add(TemplateDetailsItem.createAccountRow()); changes = true; } if (changes) items.setValue(newList); } - public LiveData> getItems(Long patternId) { + public LiveData> getItems(Long patternId) { if (patternId != null && patternId <= 0) throw new IllegalArgumentException("Pattern ID " + patternId + " is invalid"); @@ -101,15 +101,15 @@ public class PatternDetailsViewModel extends ViewModel { Observer observer = new Observer() { @Override public void onChanged(PatternWithAccounts src) { - ArrayList l = new ArrayList<>(); + ArrayList l = new ArrayList<>(); - PatternDetailsItem header = PatternDetailsItem.fromRoomObject(src.header); + TemplateDetailsItem header = TemplateDetailsItem.fromRoomObject(src.header); l.add(header); - for (PatternAccount acc : src.accounts) { - l.add(PatternDetailsItem.fromRoomObject(acc)); + for (TemplateAccount acc : src.accounts) { + l.add(TemplateDetailsItem.fromRoomObject(acc)); } - for (PatternDetailsItem i : l) { + for (TemplateDetailsItem i : l) { Logger.debug("patterns-db", "Loaded pattern item " + i); } items.postValue(l); @@ -122,26 +122,26 @@ public class PatternDetailsViewModel extends ViewModel { return items; } public void setTestText(String text) { - List list = new ArrayList<>(items.getValue()); - PatternDetailsItem.Header header = new PatternDetailsItem.Header(list.get(0) - .asHeaderItem()); + List list = new ArrayList<>(items.getValue()); + TemplateDetailsItem.Header header = new TemplateDetailsItem.Header(list.get(0) + .asHeaderItem()); header.setTestText(text); list.set(0, header); items.setValue(list); } - public void onSavePattern() { + public void onSaveTemplate() { Logger.debug("flow", "PatternDetailsViewModel.onSavePattern(); model=" + this); - final List list = Objects.requireNonNull(items.getValue()); + final List list = Objects.requireNonNull(items.getValue()); AsyncTask.execute(() -> { boolean newPattern = mPatternId == null || mPatternId <= 0; - PatternDetailsItem.Header modelHeader = list.get(0) - .asHeaderItem(); + TemplateDetailsItem.Header modelHeader = list.get(0) + .asHeaderItem(); PatternHeaderDAO headerDAO = DB.get() .getPatternDAO(); - PatternHeader dbHeader = modelHeader.toDBO(); + TemplateHeader dbHeader = modelHeader.toDBO(); if (newPattern) { dbHeader.setId(null); dbHeader.setId(mPatternId = headerDAO.insert(dbHeader)); @@ -157,9 +157,9 @@ public class PatternDetailsViewModel extends ViewModel { PatternAccountDAO paDAO = DB.get() .getPatternAccountDAO(); for (int i = 1; i < list.size(); i++) { - final PatternDetailsItem.AccountRow accRowItem = list.get(i) - .asAccountRowItem(); - PatternAccount dbAccount = accRowItem.toDBO(dbHeader.getId()); + final TemplateDetailsItem.AccountRow accRowItem = list.get(i) + .asAccountRowItem(); + TemplateAccount dbAccount = accRowItem.toDBO(dbHeader.getId()); dbAccount.setPatternId(mPatternId); dbAccount.setPosition(i); if (newPattern) { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateListFragment.java similarity index 74% rename from app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternListFragment.java rename to app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateListFragment.java index 3f8dbb13..cc5c7988 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateListFragment.java @@ -15,7 +15,7 @@ * along with MoLe. If not, see . */ -package net.ktnx.mobileledger.ui.patterns; +package net.ktnx.mobileledger.ui.templates; import android.content.Context; import android.os.Bundle; @@ -33,9 +33,9 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import net.ktnx.mobileledger.dao.PatternHeaderDAO; -import net.ktnx.mobileledger.databinding.FragmentPatternListBinding; +import net.ktnx.mobileledger.databinding.FragmentTemplateListBinding; import net.ktnx.mobileledger.db.DB; -import net.ktnx.mobileledger.db.PatternHeader; +import net.ktnx.mobileledger.db.TemplateHeader; import net.ktnx.mobileledger.utils.Logger; import org.jetbrains.annotations.NotNull; @@ -44,25 +44,25 @@ import java.util.List; /** * A simple {@link Fragment} subclass. - * Use the {@link PatternListFragment#newInstance} factory method to + * Use the {@link TemplateListFragment#newInstance} factory method to * create an instance of this fragment. */ -public class PatternListFragment extends Fragment { - private FragmentPatternListBinding b; - private OnPatternListFragmentInteractionListener mListener; +public class TemplateListFragment extends Fragment { + private FragmentTemplateListBinding b; + private OnTemplateListFragmentInteractionListener mListener; - public PatternListFragment() { + public TemplateListFragment() { // Required empty public constructor } /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * - * @return A new instance of fragment PatternListFragment. + * @return A new instance of fragment TemplateListFragment. */ // TODO: Rename and change types and number of parameters - public static PatternListFragment newInstance() { - PatternListFragment fragment = new PatternListFragment(); + public static TemplateListFragment newInstance() { + TemplateListFragment fragment = new TemplateListFragment(); Bundle args = new Bundle(); fragment.setArguments(args); return fragment; @@ -80,25 +80,25 @@ public class PatternListFragment extends Fragment { public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Logger.debug("flow", "PatternListFragment.onCreateView()"); - b = FragmentPatternListBinding.inflate(inflater); + b = FragmentTemplateListBinding.inflate(inflater); - PatternsRecyclerViewAdapter modelAdapter = new PatternsRecyclerViewAdapter(); + TemplatesRecyclerViewAdapter modelAdapter = new TemplatesRecyclerViewAdapter(); - b.patternList.setAdapter(modelAdapter); + b.templateList.setAdapter(modelAdapter); PatternHeaderDAO pDao = DB.get() .getPatternDAO(); - LiveData> patterns = pDao.getPatterns(); - patterns.observe(getViewLifecycleOwner(), modelAdapter::setPatterns); + LiveData> templates = pDao.getPatterns(); + templates.observe(getViewLifecycleOwner(), modelAdapter::setTemplates); LinearLayoutManager llm = new LinearLayoutManager(getContext()); llm.setOrientation(RecyclerView.VERTICAL); - b.patternList.setLayoutManager(llm); + b.templateList.setLayoutManager(llm); return b.getRoot(); } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - if (context instanceof OnPatternListFragmentInteractionListener) { - mListener = (OnPatternListFragmentInteractionListener) context; + if (context instanceof OnTemplateListFragmentInteractionListener) { + mListener = (OnTemplateListFragmentInteractionListener) context; } else { throw new RuntimeException( @@ -127,9 +127,9 @@ public class PatternListFragment extends Fragment { * "http://developer.android.com/training/basics/fragments/communicating.html" * >Communicating with Other Fragments for more information. */ - public interface OnPatternListFragmentInteractionListener { - void onSavePattern(); + public interface OnTemplateListFragmentInteractionListener { + void onSaveTemplate(); - void onEditPattern(Long id); + void onEditTemplate(Long id); } } \ No newline at end of file diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternViewHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateViewHolder.java similarity index 63% rename from app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternViewHolder.java rename to app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateViewHolder.java index 8dc8e32b..e9b9032d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternViewHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateViewHolder.java @@ -15,24 +15,24 @@ * along with MoLe. If not, see . */ -package net.ktnx.mobileledger.ui.patterns; +package net.ktnx.mobileledger.ui.templates; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; -import net.ktnx.mobileledger.databinding.PatternLayoutBinding; -import net.ktnx.mobileledger.db.PatternHeader; +import net.ktnx.mobileledger.databinding.TemplateListTemplateItemBinding; +import net.ktnx.mobileledger.db.TemplateHeader; -class PatternViewHolder extends RecyclerView.ViewHolder { - final PatternLayoutBinding b; - public PatternViewHolder(@NonNull PatternLayoutBinding binding) { +class TemplateViewHolder extends RecyclerView.ViewHolder { + final TemplateListTemplateItemBinding b; + public TemplateViewHolder(@NonNull TemplateListTemplateItemBinding binding) { super(binding.getRoot()); b = binding; } - public void bindToItem(PatternHeader item) { - b.patternName.setText(item.getName()); + public void bindToItem(TemplateHeader item) { + b.templateName.setText(item.getName()); b.editButton.setOnClickListener(v -> { - ((PatternsActivity) v.getContext()).onEditPattern(item.getId()); + ((TemplatesActivity) v.getContext()).onEditTemplate(item.getId()); }); } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplatesActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplatesActivity.java index 0f1d20f4..7bcece63 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplatesActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplatesActivity.java @@ -15,7 +15,7 @@ * along with MoLe. If not, see . */ -package net.ktnx.mobileledger.ui.patterns; +package net.ktnx.mobileledger.ui.templates; import android.os.Bundle; import android.view.Menu; @@ -25,31 +25,32 @@ import androidx.appcompat.app.ActionBar; import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelStoreOwner; import androidx.navigation.NavController; +import androidx.navigation.NavDestination; import androidx.navigation.fragment.NavHostFragment; import net.ktnx.mobileledger.R; -import net.ktnx.mobileledger.databinding.ActivityPatternsBinding; +import net.ktnx.mobileledger.databinding.ActivityTemplatesBinding; import net.ktnx.mobileledger.ui.activity.CrashReportingActivity; import net.ktnx.mobileledger.utils.Logger; import java.util.Objects; -public class PatternsActivity extends CrashReportingActivity - implements PatternListFragment.OnPatternListFragmentInteractionListener { - public static final String ARG_ADD_PATTERN = "add-pattern"; - private ActivityPatternsBinding b; +public class TemplatesActivity extends CrashReportingActivity + implements TemplateListFragment.OnTemplateListFragmentInteractionListener { + public static final String ARG_ADD_TEMPLATE = "add-template"; + private ActivityTemplatesBinding b; private NavController navController; @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); - getMenuInflater().inflate(R.menu.pattern_list_menu, menu); + getMenuInflater().inflate(R.menu.template_list_menu, menu); return true; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - b = ActivityPatternsBinding.inflate(getLayoutInflater()); + b = ActivityTemplatesBinding.inflate(getLayoutInflater()); setContentView(b.getRoot()); setSupportActionBar(b.toolbar); // Show the Up button in the action bar. @@ -63,28 +64,28 @@ public class PatternsActivity extends CrashReportingActivity navController = navHostFragment.getNavController(); navController.addOnDestinationChangedListener((controller, destination, arguments) -> { - if (destination.getId() == R.id.patternListFragment) { + if (destination.getId() == R.id.templateListFragment) { b.fabAdd.show(); b.fabSave.hide(); - b.toolbarLayout.setTitle(getString(R.string.title_activity_patterns)); + b.toolbarLayout.setTitle(getString(R.string.title_activity_templates)); } - if (destination.getId() == R.id.patternDetailsFragment) { + if (destination.getId() == R.id.templateDetailsFragment) { b.fabAdd.hide(); b.fabSave.show(); } }); - b.toolbarLayout.setTitle(getString(R.string.title_activity_patterns)); + b.toolbarLayout.setTitle(getString(R.string.title_activity_templates)); - b.fabAdd.setOnClickListener(v -> onEditPattern(null)); - b.fabSave.setOnClickListener(v -> onSavePattern()); + b.fabAdd.setOnClickListener(v -> onEditTemplate(null)); + b.fabSave.setOnClickListener(v -> onSaveTemplate()); } @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { final NavDestination currentDestination = navController.getCurrentDestination(); if (currentDestination != null && - currentDestination.getId() == R.id.patternDetailsFragment) + currentDestination.getId() == R.id.templateDetailsFragment) navController.popBackStack(); else finish(); @@ -95,27 +96,27 @@ public class PatternsActivity extends CrashReportingActivity } @Override - public void onEditPattern(Long id) { + public void onEditTemplate(Long id) { if (id == null) { - navController.navigate(R.id.action_patternListFragment_to_patternDetailsFragment); - b.toolbarLayout.setTitle(getString(R.string.title_new_pattern)); + navController.navigate(R.id.action_templateListFragment_to_templateDetailsFragment); + b.toolbarLayout.setTitle(getString(R.string.title_new_template)); } else { Bundle bundle = new Bundle(); - bundle.putLong(PatternDetailsFragment.ARG_PATTERN_ID, id); - navController.navigate(R.id.action_patternListFragment_to_patternDetailsFragment, + bundle.putLong(TemplateDetailsFragment.ARG_TEMPLATE_ID, id); + navController.navigate(R.id.action_templateListFragment_to_templateDetailsFragment, bundle); - b.toolbarLayout.setTitle(getString(R.string.title_edit_pattern)); + b.toolbarLayout.setTitle(getString(R.string.title_edit_template)); } } @Override - public void onSavePattern() { + public void onSaveTemplate() { final ViewModelStoreOwner viewModelStoreOwner = - navController.getViewModelStoreOwner(R.id.pattern_list_navigation); - PatternDetailsViewModel model = - new ViewModelProvider(viewModelStoreOwner).get(PatternDetailsViewModel.class); - Logger.debug("flow", "PatternsActivity.onSavePattern(): model=" + model); - model.onSavePattern(); + navController.getViewModelStoreOwner(R.id.template_list_navigation); + TemplateDetailsViewModel model = + new ViewModelProvider(viewModelStoreOwner).get(TemplateDetailsViewModel.class); + Logger.debug("flow", "TemplatesActivity.onSavePattern(): model=" + model); + model.onSaveTemplate(); navController.navigateUp(); } public NavController getNavController() { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternsRecyclerViewAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplatesRecyclerViewAdapter.java similarity index 58% rename from app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternsRecyclerViewAdapter.java rename to app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplatesRecyclerViewAdapter.java index 642a5ca6..6c1632ea 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternsRecyclerViewAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplatesRecyclerViewAdapter.java @@ -15,7 +15,7 @@ * along with MoLe. If not, see . */ -package net.ktnx.mobileledger.ui.patterns; +package net.ktnx.mobileledger.ui.templates; import android.view.LayoutInflater; import android.view.ViewGroup; @@ -25,41 +25,41 @@ import androidx.recyclerview.widget.AsyncListDiffer; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; -import net.ktnx.mobileledger.databinding.PatternLayoutBinding; -import net.ktnx.mobileledger.db.PatternHeader; +import net.ktnx.mobileledger.databinding.TemplateListTemplateItemBinding; +import net.ktnx.mobileledger.db.TemplateHeader; import org.jetbrains.annotations.NotNull; import java.util.List; -public class PatternsRecyclerViewAdapter extends RecyclerView.Adapter { - private final AsyncListDiffer listDiffer; - public PatternsRecyclerViewAdapter() { - listDiffer = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback() { +public class TemplatesRecyclerViewAdapter extends RecyclerView.Adapter { + private final AsyncListDiffer listDiffer; + public TemplatesRecyclerViewAdapter() { + listDiffer = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback() { @Override - public boolean areItemsTheSame(@NotNull PatternHeader oldItem, - @NotNull PatternHeader newItem) { + public boolean areItemsTheSame(@NotNull TemplateHeader oldItem, + @NotNull TemplateHeader newItem) { return oldItem.getId() .equals(newItem.getId()); } @Override - public boolean areContentsTheSame(@NotNull PatternHeader oldItem, - @NotNull PatternHeader newItem) { + public boolean areContentsTheSame(@NotNull TemplateHeader oldItem, + @NotNull TemplateHeader newItem) { return oldItem.equals(newItem); } }); } @NonNull @Override - public PatternViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - PatternLayoutBinding b = - PatternLayoutBinding.inflate(LayoutInflater.from(parent.getContext()), parent, - false); + public TemplateViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + TemplateListTemplateItemBinding b = + TemplateListTemplateItemBinding.inflate(LayoutInflater.from(parent.getContext()), + parent, false); - return new PatternViewHolder(b); + return new TemplateViewHolder(b); } @Override - public void onBindViewHolder(@NonNull PatternViewHolder holder, int position) { + public void onBindViewHolder(@NonNull TemplateViewHolder holder, int position) { holder.bindToItem(listDiffer.getCurrentList() .get(position)); } @@ -68,7 +68,7 @@ public class PatternsRecyclerViewAdapter extends RecyclerView.Adapter newList) { + public void setTemplates(List newList) { listDiffer.submitList(newList); } } diff --git a/app/src/main/res/layout/activity_patterns.xml b/app/src/main/res/layout/activity_templates.xml similarity index 96% rename from app/src/main/res/layout/activity_patterns.xml rename to app/src/main/res/layout/activity_templates.xml index 47ce9f1d..97416f9f 100644 --- a/app/src/main/res/layout/activity_patterns.xml +++ b/app/src/main/res/layout/activity_templates.xml @@ -20,7 +20,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".ui.patterns.PatternsActivity" + tools:context=".ui.templates.TemplatesActivity" > diff --git a/app/src/main/res/layout/fragment_item_list.xml b/app/src/main/res/layout/fragment_item_list.xml index b2eda57d..9b6014d1 100644 --- a/app/src/main/res/layout/fragment_item_list.xml +++ b/app/src/main/res/layout/fragment_item_list.xml @@ -26,6 +26,6 @@ android:layout_marginLeft="16dp" android:layout_marginRight="16dp" app:layoutManager="LinearLayoutManager" - tools:context=".ui.patterns.TestItemFragment" - tools:listitem="@layout/pattern_details_header" + tools:context=".ui.templates.TestItemFragment" + tools:listitem="@layout/template_details_header" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_pattern_detail_source_selector.xml b/app/src/main/res/layout/fragment_template_detail_source_selector.xml similarity index 98% rename from app/src/main/res/layout/fragment_pattern_detail_source_selector.xml rename to app/src/main/res/layout/fragment_template_detail_source_selector.xml index b36f101c..d3af166e 100644 --- a/app/src/main/res/layout/fragment_pattern_detail_source_selector.xml +++ b/app/src/main/res/layout/fragment_template_detail_source_selector.xml @@ -1,5 +1,5 @@