aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
-rw-r--r--main/src/cgeo/geocaching/ui/AbstractViewHolder.java19
-rw-r--r--main/src/cgeo/geocaching/ui/AddressListAdapter.java19
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java6
-rw-r--r--main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java28
-rw-r--r--main/src/cgeo/geocaching/ui/GPXListAdapter.java28
5 files changed, 57 insertions, 43 deletions
diff --git a/main/src/cgeo/geocaching/ui/AbstractViewHolder.java b/main/src/cgeo/geocaching/ui/AbstractViewHolder.java
new file mode 100644
index 0000000..cc5cd4d
--- /dev/null
+++ b/main/src/cgeo/geocaching/ui/AbstractViewHolder.java
@@ -0,0 +1,19 @@
+package cgeo.geocaching.ui;
+
+import butterknife.Views;
+
+import android.view.View;
+
+/**
+ * Abstract super class for all view holders. It is responsible for the invocation of the view injection code and for
+ * the tagging of views.
+ *
+ */
+public abstract class AbstractViewHolder {
+
+ protected AbstractViewHolder(View view) {
+ Views.inject(this, view);
+ view.setTag(this);
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/ui/AddressListAdapter.java b/main/src/cgeo/geocaching/ui/AddressListAdapter.java
index eb8b516..6689bb6 100644
--- a/main/src/cgeo/geocaching/ui/AddressListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/AddressListAdapter.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui;
+import butterknife.InjectView;
+
import cgeo.geocaching.R;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.cgeocaches;
@@ -24,9 +26,13 @@ public class AddressListAdapter extends ArrayAdapter<Address> {
final private LayoutInflater inflater;
final private Geopoint location;
- private static final class ViewHolder {
- TextView label;
- TextView distance;
+ protected static final class ViewHolder extends AbstractViewHolder {
+ @InjectView(R.id.label) protected TextView label;
+ @InjectView(R.id.distance) protected TextView distance;
+
+ public ViewHolder(View view) {
+ super(view);
+ }
}
public AddressListAdapter(final Context context) {
@@ -45,12 +51,7 @@ public class AddressListAdapter extends ArrayAdapter<Address> {
final ViewHolder holder;
if (view == null) {
view = inflater.inflate(R.layout.addresses_item, null);
-
- holder = new ViewHolder();
- holder.label = (TextView) view.findViewById(R.id.label);
- holder.distance = (TextView) view.findViewById(R.id.distance);
-
- view.setTag(holder);
+ holder = new ViewHolder(view);
} else {
holder = (ViewHolder) view.getTag();
}
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index c27c387..122f835 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -1,7 +1,6 @@
package cgeo.geocaching.ui;
import butterknife.InjectView;
-import butterknife.Views;
import cgeo.geocaching.CacheDetailActivity;
import cgeo.geocaching.Geocache;
@@ -94,7 +93,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
* view holder for the cache list adapter
*
*/
- protected static class ViewHolder {
+ protected static class ViewHolder extends AbstractViewHolder {
@InjectView(R.id.checkbox) protected CheckBox checkbox;
@InjectView(R.id.log_status_mark) protected ImageView logStatusMark;
@InjectView(R.id.text) protected TextView text;
@@ -106,8 +105,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
@InjectView(R.id.dirimg) protected ImageView dirImg;
public ViewHolder(View view) {
- Views.inject(this, view);
- view.setTag(this);
+ super(view);
}
}
diff --git a/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java b/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java
index ea32178..c325f50 100644
--- a/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui;
+import butterknife.InjectView;
+
import cgeo.geocaching.R;
import cgeo.geocaching.files.IFileSelectionView;
import cgeo.geocaching.utils.Log;
@@ -17,21 +19,18 @@ import java.util.List;
public class FileSelectionListAdapter extends ArrayAdapter<File> {
- private IFileSelectionView parentView;
- private LayoutInflater inflater;
+ private final IFileSelectionView parentView;
+ private final LayoutInflater inflater;
public FileSelectionListAdapter(IFileSelectionView parentIn, List<File> listIn) {
super(parentIn.getContext(), 0, listIn);
parentView = parentIn;
+ inflater = ((Activity) getContext()).getLayoutInflater();
}
@Override
public View getView(final int position, final View rowView, final ViewGroup parent) {
- if (inflater == null) {
- inflater = ((Activity) getContext()).getLayoutInflater();
- }
-
if (position > getCount()) {
Log.w("FileSelectionListAdapter.getView: Attempt to access missing item #" + position);
return null;
@@ -44,12 +43,7 @@ public class FileSelectionListAdapter extends ArrayAdapter<File> {
ViewHolder holder;
if (v == null) {
v = inflater.inflate(R.layout.mapfile_item, null);
-
- holder = new ViewHolder();
- holder.filepath = (TextView) v.findViewById(R.id.mapfilepath);
- holder.filename = (TextView) v.findViewById(R.id.mapfilename);
-
- v.setTag(holder);
+ holder = new ViewHolder(v);
} else {
holder = (ViewHolder) v.getTag();
}
@@ -85,8 +79,12 @@ public class FileSelectionListAdapter extends ArrayAdapter<File> {
}
}
- private static final class ViewHolder {
- TextView filepath;
- TextView filename;
+ protected static final class ViewHolder extends AbstractViewHolder {
+ @InjectView(R.id.mapfilepath) protected TextView filepath;
+ @InjectView(R.id.mapfilename) protected TextView filename;
+
+ public ViewHolder(View view) {
+ super(view);
+ }
}
}
diff --git a/main/src/cgeo/geocaching/ui/GPXListAdapter.java b/main/src/cgeo/geocaching/ui/GPXListAdapter.java
index d2bfe16..7f3c33f 100644
--- a/main/src/cgeo/geocaching/ui/GPXListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/GPXListAdapter.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui;
+import butterknife.InjectView;
+
import cgeo.geocaching.GpxFileListActivity;
import cgeo.geocaching.R;
import cgeo.geocaching.files.GPXImporter;
@@ -18,26 +20,27 @@ import java.io.File;
import java.util.List;
public class GPXListAdapter extends ArrayAdapter<File> {
- private GpxFileListActivity activity = null;
- private LayoutInflater inflater = null;
+ private final GpxFileListActivity activity;
+ private final LayoutInflater inflater;
+
+ protected static class ViewHolder extends AbstractViewHolder {
+ @InjectView(R.id.filepath) protected TextView filepath;
+ @InjectView(R.id.filename) protected TextView filename;
- private static class ViewHolder {
- TextView filepath;
- TextView filename;
+ public ViewHolder(View view) {
+ super(view);
+ }
}
public GPXListAdapter(GpxFileListActivity parentIn, List<File> listIn) {
super(parentIn, 0, listIn);
activity = parentIn;
+ inflater = ((Activity) getContext()).getLayoutInflater();
}
@Override
public View getView(final int position, final View rowView, final ViewGroup parent) {
- if (inflater == null) {
- inflater = ((Activity) getContext()).getLayoutInflater();
- }
-
if (position > getCount()) {
Log.w("GPXListAdapter.getView: Attempt to access missing item #" + position);
return null;
@@ -50,12 +53,7 @@ public class GPXListAdapter extends ArrayAdapter<File> {
final ViewHolder holder;
if (view == null) {
view = inflater.inflate(R.layout.gpx_item, null);
-
- holder = new ViewHolder();
- holder.filepath = (TextView) view.findViewById(R.id.filepath);
- holder.filename = (TextView) view.findViewById(R.id.filename);
-
- view.setTag(holder);
+ holder = new ViewHolder(view);
} else {
holder = (ViewHolder) view.getTag();
}