diff options
author | Bananeweizen <Bananeweizen@gmx.de> | 2012-12-23 22:35:26 +0100 |
---|---|---|
committer | Bananeweizen <Bananeweizen@gmx.de> | 2012-12-23 22:35:26 +0100 |
commit | f9091d6a2c31f9f08ca9f67f8498ec7598ae95e9 (patch) | |
tree | c40686232fef260a59c080c3e2816fe00af19916 /main/src/cgeo | |
parent | 774a5ab29a89c6e58177427befaa1e4031c6154e (diff) | |
download | cgeo-f9091d6a2c31f9f08ca9f67f8498ec7598ae95e9.zip cgeo-f9091d6a2c31f9f08ca9f67f8498ec7598ae95e9.tar.gz cgeo-f9091d6a2c31f9f08ca9f67f8498ec7598ae95e9.tar.bz2 |
refactoring: convert trackable log view to real list
Diffstat (limited to 'main/src/cgeo')
-rw-r--r-- | main/src/cgeo/geocaching/TrackableActivity.java | 164 |
1 files changed, 100 insertions, 64 deletions
diff --git a/main/src/cgeo/geocaching/TrackableActivity.java b/main/src/cgeo/geocaching/TrackableActivity.java index 648b4af..e4bc02f 100644 --- a/main/src/cgeo/geocaching/TrackableActivity.java +++ b/main/src/cgeo/geocaching/TrackableActivity.java @@ -32,8 +32,10 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.ScrollView; import android.widget.TextView; @@ -380,89 +382,123 @@ public class TrackableActivity extends AbstractViewPagerActivity<TrackableActivi return new ImmutablePair<List<? extends Page>, Integer>(pages, 0); } - public class LogsViewCreator extends AbstractCachingPageViewCreator<ScrollView> { + public class LogsViewCreator extends AbstractCachingPageViewCreator<ListView> { + + private class LogViewHolder { + + private final TextView added; + private final TextView type; + private final TextView author; + private final TextView location; + private final TextView log; + private final ImageView marker; + private final LinearLayout logImages; + + public LogViewHolder(View rowView) { + added = ((TextView) rowView.findViewById(R.id.added)); + type = ((TextView) rowView.findViewById(R.id.type)); + author = ((TextView) rowView.findViewById(R.id.author)); + location = ((TextView) rowView.findViewById(R.id.location)); + log = (TextView) rowView.findViewById(R.id.log); + marker = (ImageView) rowView.findViewById(R.id.log_mark); + logImages = (LinearLayout) rowView.findViewById(R.id.log_layout); + } + } @Override - public ScrollView getDispatchedView() { - view = (ScrollView) getLayoutInflater().inflate(R.layout.trackable_logs_view, null); - - LinearLayout listView = (LinearLayout) view.findViewById(R.id.log_list); - listView.removeAllViews(); + public ListView getDispatchedView() { + view = (ListView) getLayoutInflater().inflate(R.layout.trackable_logs_view, null); if (trackable != null && trackable.getLogs() != null) { - for (LogEntry log : trackable.getLogs()) { - RelativeLayout rowView = (RelativeLayout) inflater.inflate(R.layout.trackable_logs_item, null); + view.setAdapter(new ArrayAdapter<LogEntry>(TrackableActivity.this, R.layout.trackable_logs_item, trackable.getLogs()) { + @Override + public View getView(int position, View convertView, android.view.ViewGroup parent) { + View rowView = convertView; + if (null == rowView) { + rowView = getLayoutInflater().inflate(R.layout.trackable_logs_item, null); + } + LogViewHolder holder = (LogViewHolder) rowView.getTag(); + if (null == holder) { + holder = new LogViewHolder(rowView); + rowView.setTag(holder); + } - if (log.date > 0) { - ((TextView) rowView.findViewById(R.id.added)).setText(Formatter.formatShortDate(log.date)); + final LogEntry log = getItem(position); + fillViewHolder(holder, log); + return rowView; } + }); + } + return view; + } - ((TextView) rowView.findViewById(R.id.type)).setText(log.type.getL10n()); - ((TextView) rowView.findViewById(R.id.author)).setText(Html.fromHtml(log.author), TextView.BufferType.SPANNABLE); - - if (StringUtils.isBlank(log.cacheName)) { - rowView.findViewById(R.id.location).setVisibility(View.GONE); - } else { - ((TextView) rowView.findViewById(R.id.location)).setText(Html.fromHtml(log.cacheName)); - final String cacheGuid = log.cacheGuid; - final String cacheName = log.cacheName; - rowView.findViewById(R.id.location).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View arg0) { - CacheDetailActivity.startActivityGuid(TrackableActivity.this, cacheGuid, Html.fromHtml(cacheName).toString()); - } - }); - } + protected void fillViewHolder(LogViewHolder holder, LogEntry log) { + if (log.date > 0) { + holder.added.setText(Formatter.formatShortDate(log.date)); + } - TextView logView = (TextView) rowView.findViewById(R.id.log); - logView.setMovementMethod(LinkMovementMethod.getInstance()); + holder.type.setText(log.type.getL10n()); + holder.author.setText(Html.fromHtml(log.author), TextView.BufferType.SPANNABLE); - String logText = log.log; - if (BaseUtils.containsHtml(logText)) { - logText = log.getDisplayText(); - logView.setText(Html.fromHtml(logText, new HtmlImage(null, false, StoredList.TEMPORARY_LIST_ID, false), null), TextView.BufferType.SPANNABLE); - } - else { - logView.setText(logText); + if (StringUtils.isBlank(log.cacheName)) { + holder.location.setVisibility(View.GONE); + } else { + holder.location.setText(Html.fromHtml(log.cacheName)); + final String cacheGuid = log.cacheGuid; + final String cacheName = log.cacheName; + holder.location.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View arg0) { + CacheDetailActivity.startActivityGuid(TrackableActivity.this, cacheGuid, Html.fromHtml(cacheName).toString()); } + }); + } - ImageView statusMarker = (ImageView) rowView.findViewById(R.id.log_mark); - // colored marker - int marker = log.type.markerId; - if (marker != 0) { - statusMarker.setVisibility(View.VISIBLE); - statusMarker.setImageResource(marker); - } - else { - statusMarker.setVisibility(View.GONE); - } + TextView logView = holder.log; + logView.setMovementMethod(LinkMovementMethod.getInstance()); - // add LogImages - LinearLayout logLayout = (LinearLayout) rowView.findViewById(R.id.log_layout); + String logText = log.log; + if (BaseUtils.containsHtml(logText)) { + logText = log.getDisplayText(); + logView.setText(Html.fromHtml(logText, new HtmlImage(null, false, StoredList.TEMPORARY_LIST_ID, false), null), TextView.BufferType.SPANNABLE); + } + else { + logView.setText(logText); + } - if (log.hasLogImages()) { + ImageView statusMarker = holder.marker; + // colored marker + int marker = log.type.markerId; + if (marker != 0) { + statusMarker.setVisibility(View.VISIBLE); + statusMarker.setImageResource(marker); + } + else { + statusMarker.setVisibility(View.GONE); + } + + // add LogImages + LinearLayout logLayout = holder.logImages; - final ArrayList<cgImage> logImages = new ArrayList<cgImage>(log.getLogImages()); + if (log.hasLogImages()) { - final View.OnClickListener listener = new View.OnClickListener() { - @Override - public void onClick(View v) { - ImagesActivity.startActivityLogImages(TrackableActivity.this, trackable.getGeocode(), logImages); - } - }; + final ArrayList<cgImage> logImages = new ArrayList<cgImage>(log.getLogImages()); - LinearLayout log_imgView = (LinearLayout) getLayoutInflater().inflate(R.layout.trackable_logs_img, null); - TextView log_img_title = (TextView) log_imgView.findViewById(R.id.title); - log_img_title.setText(log.getImageTitles()); - log_img_title.setOnClickListener(listener); - logLayout.addView(log_imgView); + final View.OnClickListener listener = new View.OnClickListener() { + @Override + public void onClick(View v) { + ImagesActivity.startActivityLogImages(TrackableActivity.this, trackable.getGeocode(), logImages); } + }; - rowView.findViewById(R.id.author).setOnClickListener(new UserActionsListener()); - listView.addView(rowView); - } + LinearLayout log_imgView = (LinearLayout) getLayoutInflater().inflate(R.layout.trackable_logs_img, null); + TextView log_img_title = (TextView) log_imgView.findViewById(R.id.title); + log_img_title.setText(log.getImageTitles()); + log_img_title.setOnClickListener(listener); + logLayout.addView(log_imgView); } - return view; + + holder.author.setOnClickListener(new UserActionsListener()); } } |