void onSaveTemplate();
void onEditTemplate(Long id);
+
+ void onDuplicateTemplate(long id);
}
}
\ No newline at end of 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;
}
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;
});
}
}
}
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) {
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
<?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>
<?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>Edit</item>
+ <item>Duplicate</item>
+ <item>Delete</item>
+ </string-array>
</resources>
\ No newline at end of file