From d2494279b07b4675d0303cce90e615934c422850 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 2 Jun 2013 19:47:36 +0200 Subject: refactoring: extract some common code out of log viewers --- main/src/cgeo/geocaching/CacheDetailActivity.java | 55 +++-------------------- main/src/cgeo/geocaching/LogViewHolder.java | 46 +++++++++++++++++++ main/src/cgeo/geocaching/TrackableActivity.java | 23 ++-------- 3 files changed, 56 insertions(+), 68 deletions(-) create mode 100644 main/src/cgeo/geocaching/LogViewHolder.java diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index bdc1921..58765bc 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -2156,7 +2156,6 @@ public class CacheDetailActivity extends AbstractViewPagerActivity - * This must be called by the UI thread. - * - * @return the cursor position - */ - public int getPosition() { - return position; - } - - /** - * Set the position of the cursor pointed to by this holder.
- * This must be called by the UI thread. - * - * @param position - * the cursor position - */ - public void setPosition(final int position) { - this.position = position; - } - - } } private class WaypointsViewCreator extends AbstractCachingPageViewCreator { diff --git a/main/src/cgeo/geocaching/LogViewHolder.java b/main/src/cgeo/geocaching/LogViewHolder.java new file mode 100644 index 0000000..1fb3f55 --- /dev/null +++ b/main/src/cgeo/geocaching/LogViewHolder.java @@ -0,0 +1,46 @@ +package cgeo.geocaching; + +import butterknife.InjectView; +import butterknife.Views; + +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +public class LogViewHolder { + @InjectView(R.id.added) protected TextView date ; + @InjectView(R.id.type) protected TextView type; + @InjectView(R.id.author) protected TextView author; + @InjectView(R.id.count_or_location) protected TextView countOrLocation; + @InjectView(R.id.log) protected TextView text; + @InjectView(R.id.log_images) protected TextView images; + @InjectView(R.id.log_mark) protected ImageView marker; + + private int position; + + public LogViewHolder(View rowView) { + Views.inject(this, rowView); + rowView.setTag(this); + } + + /** + * Read the position of the cursor pointed to by this holder.
+ * This must be called by the UI thread. + * + * @return the cursor position + */ + public int getPosition() { + return position; + } + + /** + * Set the position of the cursor pointed to by this holder.
+ * This must be called by the UI thread. + * + * @param position + * the cursor position + */ + public void setPosition(final int position) { + this.position = position; + } +} \ No newline at end of file diff --git a/main/src/cgeo/geocaching/TrackableActivity.java b/main/src/cgeo/geocaching/TrackableActivity.java index 1295181..383b327 100644 --- a/main/src/cgeo/geocaching/TrackableActivity.java +++ b/main/src/cgeo/geocaching/TrackableActivity.java @@ -387,21 +387,6 @@ public class TrackableActivity extends AbstractViewPagerActivity { - protected class LogViewHolder { - @InjectView(R.id.added) protected TextView added ; - @InjectView(R.id.type) protected TextView type; - @InjectView(R.id.author) protected TextView author; - @InjectView(R.id.count_or_location) protected TextView location; - @InjectView(R.id.log) protected TextView text; - @InjectView(R.id.log_images) protected TextView images; - @InjectView(R.id.log_mark) protected ImageView marker; - - public LogViewHolder(View rowView) { - Views.inject(this, rowView); - rowView.setTag(this); - } - } - @Override public ListView getDispatchedView() { view = (ListView) getLayoutInflater().inflate(R.layout.trackable_logs_view, null); @@ -430,19 +415,19 @@ public class TrackableActivity extends AbstractViewPagerActivity 0) { - holder.added.setText(Formatter.formatShortDateVerbally(log.date)); + holder.date.setText(Formatter.formatShortDateVerbally(log.date)); } holder.type.setText(log.type.getL10n()); holder.author.setText(Html.fromHtml(log.author), TextView.BufferType.SPANNABLE); if (StringUtils.isBlank(log.cacheName)) { - holder.location.setVisibility(View.GONE); + holder.countOrLocation.setVisibility(View.GONE); } else { - holder.location.setText(Html.fromHtml(log.cacheName)); + holder.countOrLocation.setText(Html.fromHtml(log.cacheName)); final String cacheGuid = log.cacheGuid; final String cacheName = log.cacheName; - holder.location.setOnClickListener(new View.OnClickListener() { + holder.countOrLocation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { CacheDetailActivity.startActivityGuid(TrackableActivity.this, cacheGuid, Html.fromHtml(cacheName).toString()); -- cgit v1.1