]> git.ktnx.net Git - mobile-ledger.git/commitdiff
manipulation of templates via pop-up menu, add template duplication
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 13 Feb 2021 21:08:16 +0000 (23:08 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 18 Feb 2021 07:19:43 +0000 (07:19 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateListFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateViewHolder.java
app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplatesActivity.java
app/src/main/res/layout/template_list_template_item.xml
app/src/main/res/values-bg/arrays.xml
app/src/main/res/values/arrays.xml

index c7020e95be762b2c20965c8d542f83f67d11e9f5..52e41f2f7e1a340b5502f2185b150c7b3deefbd9 100644 (file)
@@ -131,5 +131,7 @@ public class TemplateListFragment extends Fragment {
         void onSaveTemplate();
 
         void onEditTemplate(Long id);
+
+        void onDuplicateTemplate(long id);
     }
 }
\ No newline at end of file
index e9b9032d2a24dcde22ea6c6affca7568a2fdb140..c8c197f44d1983926af295e8893ac543125ed240 100644 (file)
 package net.ktnx.mobileledger.ui.templates;
 
 import androidx.annotation.NonNull;
+import androidx.appcompat.app.AlertDialog;
 import androidx.recyclerview.widget.RecyclerView;
 
+import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.databinding.TemplateListTemplateItemBinding;
 import net.ktnx.mobileledger.db.TemplateHeader;
 
@@ -31,8 +33,30 @@ class TemplateViewHolder extends RecyclerView.ViewHolder {
     }
     public void bindToItem(TemplateHeader item) {
         b.templateName.setText(item.getName());
-        b.editButton.setOnClickListener(v -> {
-            ((TemplatesActivity) v.getContext()).onEditTemplate(item.getId());
+        b.templateName.setOnClickListener(
+                v -> ((TemplatesActivity) v.getContext()).onEditTemplate(item.getId()));
+        b.templateName.setOnLongClickListener((v) -> {
+            TemplatesActivity activity = (TemplatesActivity) v.getContext();
+            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+            final String templateName = item.getName();
+            builder.setTitle(templateName);
+            builder.setItems(R.array.templates_ctx_menu, (dialog, which) -> {
+                if (which == 0) { // edit
+                    activity.onEditTemplate(item.getId());
+                }
+                else if (which == 1) { // duplicate
+                    activity.onDuplicateTemplate(item.getId());
+                }
+                else if (which == 2) { // delete
+                    activity.onDeleteTemplate(item.getId());
+                }
+                else {
+                    throw new RuntimeException(String.format("Unknown menu item id (%d)", which));
+                }
+                dialog.dismiss();
+            });
+            builder.show();
+            return true;
         });
     }
 }
index e8668b0b05b86c50016f50548af119f25468767c..62a005ffb437950f0de0e330cd9c93c0c1a3a550 100644 (file)
@@ -101,7 +101,12 @@ public class TemplatesActivity extends CrashReportingActivity
         }
         return super.onOptionsItemSelected(item);
     }
-
+    @Override
+    public void onDuplicateTemplate(long id) {
+        DB.get()
+          .getTemplateDAO()
+          .duplicateTemplateWitAccounts(id, null);
+    }
     @Override
     public void onEditTemplate(Long id) {
         if (id == null) {
index 46d6410ef59ddcadaa31d27ae59d14b6ae2e5420..fb5e24317e35fb5536fdfbef99a358db6935329c 100644 (file)
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_marginStart="@dimen/text_margin"
-        android:layout_marginEnd="@dimen/text_margin"
+        android:gravity="center_vertical"
         app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toStartOf="@id/edit_button"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent"
-        />
-    <ImageButton
-        android:id="@+id/edit_button"
-        android:layout_width="@dimen/toolbar_height"
-        android:layout_height="@dimen/toolbar_height"
-        android:backgroundTint="?colorSurface"
-        android:contentDescription="@string/edit_button_description"
-        android:src="@drawable/ic_mode_edit_black_24dp"
-        app:layout_constraintBottom_toBottomOf="parent"
+        android:minHeight="@dimen/thumb_row_height"
+        android:textAppearance="?attr/textAppearanceListItem"
         app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintTop_toTopOf="parent"
         />
 </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
index b475943c5fdd85b414c9b40946d1154a66c95af3..953056707e64e2e9c3baa3ceb17b762d417e88da 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?><!--
-  ~ 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
         <!--<item>Expand all</item>-->
         <!--<item>Collapse all</item>-->
     </string-array>
+    <string-array name="templates_ctx_menu">
+        <item>Промяна</item>
+        <item>Дублиране</item>
+        <item>Изтриване</item>
+    </string-array>
+
 </resources>
index 17b632966ff87c85744dcbed46f00a8f3d6bc949..0e8556530389eec970f997f0e5d62d6596dbe3ef 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?><!--
-  ~ 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
@@ -21,4 +21,9 @@
         <!--<item>Expand all</item>-->
         <!--<item>Collapse all</item>-->
     </string-array>
+    <string-array name="templates_ctx_menu">
+        <item>Edit</item>
+        <item>Duplicate</item>
+        <item>Delete</item>
+    </string-array>
 </resources>
\ No newline at end of file