From e201a7db89932636c9c8d4f08dbb800e1707f9f2 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 17 Nov 2017 15:17:08 +0200 Subject: [PATCH] Refactor clicking in row --- .../osmand/plus/osmedit/OsmEditsAdapter.java | 21 +++++-------------- .../osmand/plus/osmedit/OsmEditsFragment.java | 7 ++++++- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java index 4cf5339958..9a74eb64e4 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java @@ -78,7 +78,9 @@ public class OsmEditsAdapter extends ArrayAdapter { holder.selectCheckBox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - selectItem(holder.selectCheckBox, child); + if (listener != null) { + listener.onItemSelect(child, holder.selectCheckBox.isChecked()); + } } }); } else { @@ -100,9 +102,7 @@ public class OsmEditsAdapter extends ArrayAdapter { @Override public void onClick(View v) { if (selectionMode) { - CheckBox checkBox = holder.selectCheckBox; - checkBox.setChecked(!checkBox.isChecked()); - selectItem(checkBox, child); + holder.selectCheckBox.performClick(); } else { if (listener != null) { listener.onItemShowMap(child); @@ -114,17 +114,6 @@ public class OsmEditsAdapter extends ArrayAdapter { return view; } - private void selectItem(CheckBox checkBox, OsmPoint note) { - if (checkBox.isChecked()) { - selectedOsmEdits.add(note); - } else { - selectedOsmEdits.remove(note); - } - if (listener != null) { - listener.onItemSelect(note); - } - } - private class OsmEditViewHolder { View mainView; ImageView icon; @@ -143,7 +132,7 @@ public class OsmEditsAdapter extends ArrayAdapter { public interface OsmEditsAdapterListener { - void onItemSelect(OsmPoint point); + void onItemSelect(OsmPoint point, boolean checked); void onItemShowMap(OsmPoint point); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 2012e83927..9016018e1e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -361,7 +361,12 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo listAdapter.setSelectedOsmEdits(osmEditsSelected); listAdapter.setAdapterListener(new OsmEditsAdapter.OsmEditsAdapterListener() { @Override - public void onItemSelect(OsmPoint point) { + public void onItemSelect(OsmPoint point, boolean checked) { + if (checked) { + osmEditsSelected.add(point); + } else { + osmEditsSelected.remove(point); + } updateSelectionMode(actionMode); }