diff --git a/app/src/main/java/de/domjos/unitrackermobile/activities/MainActivity.java b/app/src/main/java/de/domjos/unitrackermobile/activities/MainActivity.java index be5e0ede..fa869332 100644 --- a/app/src/main/java/de/domjos/unitrackermobile/activities/MainActivity.java +++ b/app/src/main/java/de/domjos/unitrackermobile/activities/MainActivity.java @@ -18,6 +18,7 @@ package de.domjos.unitrackermobile.activities; +import android.app.Activity; import android.content.Intent; import android.graphics.BitmapFactory; import android.view.Menu; @@ -318,6 +319,33 @@ protected void initControls() { this.lvMainIssues = this.findViewById(R.id.lvMainIssues); this.lvMainIssues.setContextMenu(R.menu.context_main); + this.lvMainIssues.addButtonClick(R.drawable.ic_style_black_24dp, new SwipeRefreshDeleteList.ButtonClickListener() { + @Override + public void onClick(List objectList) { + try { + Activity act = MainActivity.this; + boolean show = settings.showNotifications(); + Object pid = settings.getCurrentProjectId(); + + String tags = Helper.showTagDialog(act, bugService, show, pid); + + for(ListObject listObject : objectList) { + IssueTask issueTask = new IssueTask(act, bugService, pid, false, true, show, R.drawable.ic_bug_report_black_24dp); + List issues = issueTask.execute(listObject.getDescriptionObject().getId()).get(); + + if(issues!=null) { + if(!issues.isEmpty()) { + issues.get(0).setTags(tags); + issueTask = new IssueTask(act, bugService, pid, false, false, show, R.drawable.ic_bug_report_black_24dp); + issueTask.execute(issues.get(0)).get(); + } + } + } + } catch (Exception ex) { + MessageHelper.printException(ex, MainActivity.this); + } + } + }); this.spMainFilters = this.findViewById(R.id.spMainFilters); this.filterAdapter = new ArrayAdapter<>(this.getApplicationContext(), R.layout.spinner_item); diff --git a/app/src/main/java/de/domjos/unitrackermobile/custom/swiperefreshlist/SwipeRefreshDeleteList.java b/app/src/main/java/de/domjos/unitrackermobile/custom/swiperefreshlist/SwipeRefreshDeleteList.java index 4b1b9bbb..245496b1 100644 --- a/app/src/main/java/de/domjos/unitrackermobile/custom/swiperefreshlist/SwipeRefreshDeleteList.java +++ b/app/src/main/java/de/domjos/unitrackermobile/custom/swiperefreshlist/SwipeRefreshDeleteList.java @@ -34,6 +34,11 @@ import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; import com.google.android.material.snackbar.Snackbar; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + import de.domjos.unitrackerlibrary.model.ListObject; import de.domjos.unitrackerlibrary.tasks.IssueTask; import de.domjos.unitrackermobile.R; @@ -52,6 +57,7 @@ public class SwipeRefreshDeleteList extends LinearLayout { private Snackbar snackbar; private SwipeRefreshLayout swipeRefreshLayout; private LinearLayout linearLayout; + private Map menuItems; public SwipeRefreshDeleteList(@NonNull Context context) { super(context); @@ -72,6 +78,7 @@ public RecyclerAdapter getAdapter() { } private void initDefault() { + this.menuItems = new LinkedHashMap<>(); this.setOrientation(VERTICAL); this.swipeRefreshLayout = new SwipeRefreshLayout(this.context); @@ -112,23 +119,6 @@ private void initDefault() { }); this.linearLayout.addView(cmdDelete); - ImageButton cmdTags = new ImageButton(this.context); - cmdTags.setImageDrawable(VectorDrawableCompat.create(context.getResources(), R.drawable.ic_style_black_24dp, null)); - cmdTags.setBackground(null); - cmdTags.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); - cmdTags.setOnClickListener(event -> { - Settings settings = MainActivity.GLOBALS.getSettings(context); - String tags = Helper.showTagDialog(((Activity)context), Helper.getCurrentBugService(context), settings.showNotifications(), settings.getCurrentProjectId()); - - for(int i = 0; i<=this.adapter.getItemCount()-1; i++) { - ListObject obj = this.adapter.getItem(i); - if(obj.isSelected()) { - - } - } - }); - this.linearLayout.addView(cmdTags); - this.addView(this.linearLayout); this.snackbar = Snackbar.make(((Activity)context).findViewById(android.R.id.content), R.string.sys_item_deleted, Snackbar.LENGTH_SHORT); @@ -203,6 +193,26 @@ public void click(ClickListener clickListener) { this.clickListener = clickListener; } + public void addButtonClick(int drawableId, ButtonClickListener buttonClickListener) { + ImageButton cmdTags = new ImageButton(this.context); + cmdTags.setImageDrawable(VectorDrawableCompat.create(context.getResources(), drawableId, null)); + cmdTags.setBackground(null); + cmdTags.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); + cmdTags.setOnClickListener(event -> { + List listObjects = new LinkedList<>(); + for(int i = 0; i<=this.adapter.getItemCount()-1; i++) { + ListObject obj = this.adapter.getItem(i); + if(obj.isSelected()) { + listObjects.add(obj); + } + } + if(buttonClickListener!=null) { + buttonClickListener.onClick(listObjects); + } + }); + this.linearLayout.addView(cmdTags); + } + public void setContextMenu(int menuId) { this.adapter.setContextMenu(menuId); } @@ -218,4 +228,8 @@ public abstract static class DeleteListener { public abstract static class ClickListener { public abstract void onClick(ListObject listObject); } + + public abstract static class ButtonClickListener { + public abstract void onClick(List objectList); + } }