diff options
author | campbeb <bpcampbell@gmail.com> | 2012-02-25 14:32:44 +0900 |
---|---|---|
committer | campbeb <bpcampbell@gmail.com> | 2012-02-25 14:32:44 +0900 |
commit | 659e513f2d8c713d184e2fb10bbd2db3e4d629bd (patch) | |
tree | 22fd166060df6f38db6c7150ec08882dab5424bb /main/src | |
parent | 1453862cc743c7293e4fde0573a963227682079d (diff) | |
download | cgeo-659e513f2d8c713d184e2fb10bbd2db3e4d629bd.zip cgeo-659e513f2d8c713d184e2fb10bbd2db3e4d629bd.tar.gz cgeo-659e513f2d8c713d184e2fb10bbd2db3e4d629bd.tar.bz2 |
Display images in trackable logs
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/cgeo/geocaching/GCConstants.java | 1 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 17 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeotrackable.java | 38 |
3 files changed, 53 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/GCConstants.java b/main/src/cgeo/geocaching/GCConstants.java index 49f9e29..d884380 100644 --- a/main/src/cgeo/geocaching/GCConstants.java +++ b/main/src/cgeo/geocaching/GCConstants.java @@ -92,6 +92,7 @@ public final class GCConstants { public final static Pattern PATTERN_TRACKABLE_TYPE = Pattern.compile("<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"[^\"]+\" alt=\"([^\"]+)\"[^>]*>"); public final static Pattern PATTERN_TRACKABLE_DISTANCE = Pattern.compile("<h4[^>]*\\W*Tracking History \\(([0-9.,]+(km|mi))[^\\)]*\\)"); public final static Pattern PATTERN_TRACKABLE_LOG = Pattern.compile("<tr class=\"Data.+?src=\"/images/icons/([^.]+)\\.gif[^>]+> ([^<]+)</td>.+?guid.+?>([^<]+)</a>.+?(?:guid=([^\"]+)\">(<span class=\"Strike\">)?([^<]+)</.+?)?<td colspan=\"4\">(.+?)(?:<ul.+?ul>)?\\s*</td>\\s*</tr>"); + public final static Pattern PATTERN_TRACKABLE_LOG_IMAGES = Pattern.compile(".+?<li><a href=\"([^\"]+)\".+?LogImgTitle.+?>([^<]+)</"); /** * Patterns for parsing the result of a search (next) diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index ed904b6..a5311e3 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -1501,11 +1501,26 @@ public class cgBase { logDone.cacheName = matcherLogs.group(6); } + // Apply the pattern for images in a trackable log entry against each full log (group(0)) + final Matcher matcherLogImages = GCConstants.PATTERN_TRACKABLE_LOG_IMAGES.matcher(matcherLogs.group(0)); + /* + * 1. Image URL + * 2. Image title + */ + while (matcherLogImages.find()) + { + final cgImage logImage = new cgImage(matcherLogImages.group(1), matcherLogImages.group(2)); + if (logDone.logImages == null) { + logDone.logImages = new ArrayList<cgImage>(); + } + logDone.logImages.add(logImage); + } + trackable.getLogs().add(logDone); } } catch (Exception e) { // failed to parse logs - Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache logs"); + Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache logs" + e.toString()); } // trackingcode diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java index e40e04f..db533ce 100644 --- a/main/src/cgeo/geocaching/cgeotrackable.java +++ b/main/src/cgeo/geocaching/cgeotrackable.java @@ -4,6 +4,7 @@ import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.geopoint.HumanDistance; import cgeo.geocaching.network.HtmlImage; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import android.app.ProgressDialog; @@ -28,6 +29,7 @@ import android.widget.ScrollView; import android.widget.TextView; import java.net.URLEncoder; +import java.util.ArrayList; import java.util.Arrays; public class cgeotrackable extends AbstractActivity { @@ -441,7 +443,7 @@ public class cgeotrackable extends AbstractActivity { if (trackable != null && trackable.getLogs() != null) { for (cgLog log : trackable.getLogs()) { - rowView = (RelativeLayout) inflater.inflate(R.layout.trackable_logitem, null); + rowView = (RelativeLayout) inflater.inflate(R.layout.trackable_logs_item, null); if (log.date > 0) { ((TextView) rowView.findViewById(R.id.added)).setText(cgBase.formatShortDate(log.date)); @@ -468,7 +470,39 @@ public class cgeotrackable extends AbstractActivity { TextView logView = (TextView) rowView.findViewById(R.id.log); logView.setMovementMethod(LinkMovementMethod.getInstance()); - logView.setText(Html.fromHtml(log.log, new HtmlImage(cgeotrackable.this, null, false, 0, false), null), TextView.BufferType.SPANNABLE); + logView.setText(Html.fromHtml(log.log, new HtmlImage(cgeotrackable.this, null, false, StoredList.TEMPORARY_LIST_ID, false), null), TextView.BufferType.SPANNABLE); + + // add LogImages + LinearLayout logLayout = (LinearLayout) rowView.findViewById(R.id.log_layout); + + if (CollectionUtils.isNotEmpty(log.logImages)) { + + final ArrayList<cgImage> logImages = new ArrayList<cgImage>(log.logImages); + + final View.OnClickListener listener = new View.OnClickListener() { + @Override + public void onClick(View v) { + cgeoimages.startActivityLogImages(cgeotrackable.this, trackable.getGeocode(), logImages); + } + }; + + ArrayList<String> titles = new ArrayList<String>(); + for (int i_img_cnt = 0; i_img_cnt < log.logImages.size(); i_img_cnt++) { + String img_title = log.logImages.get(i_img_cnt).getTitle(); + if (!StringUtils.isBlank(img_title)) { + titles.add(img_title); + } + } + if (titles.isEmpty()) { + titles.add(res.getString(R.string.cache_log_image_default_title)); + } + + 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(StringUtils.join(titles.toArray(new String[titles.size()]), ", ")); + log_img_title.setOnClickListener(listener); + logLayout.addView(log_imgView); + } ((TextView) rowView.findViewById(R.id.author)).setOnClickListener(new userActions()); listView.addView(rowView); |