aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2014-05-13 07:28:04 +0200
committerBananeweizen <bananeweizen@gmx.de>2014-05-13 07:28:04 +0200
commitb379a72027df947ff2e936d6b3478f75de5598a1 (patch)
treea9e2c52e51fd29384ba3617dc590cb0bf18554fc /main/src
parent065d6d72b2e4459a536d9bfe82a74b48a4c4beea (diff)
downloadcgeo-b379a72027df947ff2e936d6b3478f75de5598a1.zip
cgeo-b379a72027df947ff2e936d6b3478f75de5598a1.tar.gz
cgeo-b379a72027df947ff2e936d6b3478f75de5598a1.tar.bz2
refactoring: remove listener references to cachelistadapter
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java39
1 files changed, 26 insertions, 13 deletions
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index 0d90d9f..3a451a5 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -45,6 +45,7 @@ import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -377,7 +378,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
final boolean lightSkin = Settings.isLightSkin();
- final TouchListener touchListener = new TouchListener(cache);
+ final TouchListener touchListener = new TouchListener(cache, this);
v.setOnClickListener(touchListener);
v.setOnLongClickListener(touchListener);
v.setOnTouchListener(touchListener);
@@ -536,24 +537,30 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
}
}
- private class TouchListener implements View.OnClickListener, View.OnLongClickListener, View.OnTouchListener {
+ private static class TouchListener implements View.OnClickListener, View.OnLongClickListener, View.OnTouchListener {
private final Geocache cache;
private final GestureDetector gestureDetector;
+ private final @NonNull WeakReference<CacheListAdapter> adapterRef;
- public TouchListener(final Geocache cache) {
+ public TouchListener(final Geocache cache, final @NonNull CacheListAdapter adapter) {
this.cache = cache;
- gestureDetector = new GestureDetector(getContext(), new FlingGesture(cache));
+ gestureDetector = new GestureDetector(adapter.getContext(), new FlingGesture(cache, adapter));
+ adapterRef = new WeakReference<CacheListAdapter>(adapter);
}
// Tap on item
@Override
public void onClick(final View view) {
- if (isSelectMode()) {
+ final CacheListAdapter adapter = adapterRef.get();
+ if (adapter == null) {
+ return;
+ }
+ if (adapter.isSelectMode()) {
cache.setStatusChecked(!cache.isStatusChecked());
- notifyDataSetChanged();
+ adapter.notifyDataSetChanged();
} else {
- CacheDetailActivity.startActivity(getContext(), cache.getGeocode(), cache.getName());
+ CacheDetailActivity.startActivity(adapter.getContext(), cache.getGeocode(), cache.getName());
}
}
@@ -572,12 +579,14 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
}
}
- private class FlingGesture extends GestureDetector.SimpleOnGestureListener {
+ private static class FlingGesture extends GestureDetector.SimpleOnGestureListener {
private final Geocache cache;
+ private final @NonNull WeakReference<CacheListAdapter> adapterRef;
- public FlingGesture(final Geocache cache) {
+ public FlingGesture(final Geocache cache, final @NonNull CacheListAdapter adapter) {
this.cache = cache;
+ adapterRef = new WeakReference<CacheListAdapter>(adapter);
}
@Override
@@ -586,11 +595,15 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
return false;
}
+ final CacheListAdapter adapter = adapterRef.get();
+ if (adapter == null) {
+ return false;
+ }
// left to right swipe
if ((e2.getX() - e1.getX()) > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > Math.abs(velocityY)) {
- if (!selectMode) {
- switchSelectMode();
+ if (!adapter.selectMode) {
+ adapter.switchSelectMode();
cache.setStatusChecked(true);
}
return true;
@@ -598,8 +611,8 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
// right to left swipe
if ((e1.getX() - e2.getX()) > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > Math.abs(velocityY)) {
- if (selectMode) {
- switchSelectMode();
+ if (adapter.selectMode) {
+ adapter.switchSelectMode();
}
return true;
}