diff options
-rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 20 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 27 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgImage.java | 27 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeodetail.java | 14 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeoimages.java | 38 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java | 7 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/test/mock/GC2JVEH.java | 17 |
7 files changed, 83 insertions, 67 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 9d30ff5..a615ae7 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -1231,15 +1231,17 @@ public class cgBase { final Matcher matcherSpoilersInside = GCConstants.PATTERN_SPOILERSINSIDE.matcher(spoilers); while (matcherSpoilersInside.find()) { - final cgImage spoiler = new cgImage(); - spoiler.url = matcherSpoilersInside.group(1); + String url = matcherSpoilersInside.group(1); + String title = null; if (matcherSpoilersInside.group(2) != null) { - spoiler.title = matcherSpoilersInside.group(2); + title = matcherSpoilersInside.group(2); } + String description = null; if (matcherSpoilersInside.group(3) != null) { - spoiler.description = matcherSpoilersInside.group(3); + description = matcherSpoilersInside.group(3); } + final cgImage spoiler = new cgImage(url, title, description); if (cache.getSpoilers() == null) { cache.setSpoilers(new ArrayList<cgImage>()); @@ -1551,9 +1553,9 @@ public class cgBase { final JSONArray images = entry.getJSONArray("Images"); for (int i = 0; i < images.length(); i++) { final JSONObject image = images.getJSONObject(i); - final cgImage logImage = new cgImage(); - logImage.url = "http://img.geocaching.com/cache/log/" + image.getString("FileName"); - logImage.title = image.getString("Name"); + String url = "http://img.geocaching.com/cache/log/" + image.getString("FileName"); + String title = image.getString("Name"); + final cgImage logImage = new cgImage(url, title); if (logDone.logImages == null) { logDone.logImages = new ArrayList<cgImage>(); } @@ -2935,7 +2937,7 @@ public class cgBase { // store spoilers if (CollectionUtils.isNotEmpty(cache.getSpoilers())) { for (cgImage oneSpoiler : cache.getSpoilers()) { - imgGetter.getDrawable(oneSpoiler.url); + imgGetter.getDrawable(oneSpoiler.getUrl()); } } @@ -2948,7 +2950,7 @@ public class cgBase { for (cgLog log : cache.getLogs()) { if (CollectionUtils.isNotEmpty(log.logImages)) { for (cgImage oneLogImg : log.logImages) { - imgGetter.getDrawable(oneLogImg.url); + imgGetter.getDrawable(oneLogImg.getUrl()); } } } diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 2ebb554..6cfeab9 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -1554,9 +1554,9 @@ public class cgData { values.clear(); values.put("geocode", geocode); values.put("updated", timeStamp); - values.put("url", oneSpoiler.url); - values.put("title", oneSpoiler.title); - values.put("description", oneSpoiler.description); + values.put("url", oneSpoiler.getUrl()); + values.put("title", oneSpoiler.getTitle()); + values.put("description", oneSpoiler.getDescription()); databaseRW.insert(dbTableSpoilers, null, values); } @@ -1608,8 +1608,8 @@ public class cgData { for (cgImage img : log.logImages) { values.clear(); values.put("log_id", log_id); - values.put("title", img.title); - values.put("url", img.url); + values.put("title", img.getTitle()); + values.put("url", img.getUrl()); databaseRW.insert(dbTableLogImages, null, values); } } @@ -2263,10 +2263,7 @@ public class cgData { int indexDescription = cursor.getColumnIndex("description"); do { - cgImage spoiler = new cgImage(); - spoiler.url = cursor.getString(indexUrl); - spoiler.title = cursor.getString(indexTitle); - spoiler.description = cursor.getString(indexDescription); + cgImage spoiler = new cgImage(cursor.getString(indexUrl), cursor.getString(indexTitle), cursor.getString(indexDescription)); spoilers.add(spoiler); } while (cursor.moveToNext()); @@ -2382,18 +2379,12 @@ public class cgData { logs.add(log); } if (!cursor.isNull(indexLogImagesId)) { - final cgImage log_img = new cgImage(); - log_img.title = cursor.getString(indexTitle); - if (log_img.title == null) { - log_img.title = ""; - } - log_img.url = cursor.getString(indexUrl); - if (log_img.url == null) { - log_img.url = ""; - } + String title = cursor.getString(indexTitle); + String url = cursor.getString(indexUrl); if (log.logImages == null) { log.logImages = new ArrayList<cgImage>(); } + final cgImage log_img = new cgImage(url, title); log.logImages.add(log_img); } } diff --git a/main/src/cgeo/geocaching/cgImage.java b/main/src/cgeo/geocaching/cgImage.java index 3dba437..4becefd 100644 --- a/main/src/cgeo/geocaching/cgImage.java +++ b/main/src/cgeo/geocaching/cgImage.java @@ -4,11 +4,18 @@ import android.os.Parcel; import android.os.Parcelable; public class cgImage implements Parcelable { - public String url = ""; - public String title = ""; - public String description = ""; + private final String url; + private final String title; + private final String description; + + public cgImage(final String url, final String title, final String description) { + this.url = url; + this.title = title; + this.description = description; + } - public cgImage() { + public cgImage(final String url, final String title) { + this(url, title, null); } public cgImage(final Parcel in) { @@ -39,4 +46,16 @@ public class cgImage implements Parcelable { return new cgImage[size]; } }; + + public String getUrl() { + return url; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } } diff --git a/main/src/cgeo/geocaching/cgeodetail.java b/main/src/cgeo/geocaching/cgeodetail.java index 84c208b..9cb38f9 100644 --- a/main/src/cgeo/geocaching/cgeodetail.java +++ b/main/src/cgeo/geocaching/cgeodetail.java @@ -1306,17 +1306,13 @@ public class cgeodetail extends AbstractActivity { final View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { - Intent logImgIntent = new Intent(cgeodetail.this, cgeoimages.class); - logImgIntent.putExtra("geocode", geocode.toUpperCase()); - logImgIntent.putExtra("type", cgeoimages.LOG_IMAGES); - logImgIntent.putParcelableArrayListExtra("images", logImages); - startActivity(logImgIntent); + cgeoimages.startActivityLogImages(cgeodetail.this, geocode, 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).title; + String img_title = log.logImages.get(i_img_cnt).getTitle(); if (!StringUtils.isBlank(img_title)) { titles.add(img_title); } @@ -1647,11 +1643,7 @@ public class cgeodetail extends AbstractActivity { showToast(res.getString(R.string.err_detail_no_spoiler)); } - Intent spoilersIntent = new Intent(this, cgeoimages.class); - spoilersIntent.putExtra("geocode", geocode.toUpperCase()); - spoilersIntent.putExtra("type", cgeoimages.SPOILER_IMAGES); - spoilersIntent.putParcelableArrayListExtra("images", cache.getSpoilers()); - startActivity(spoilersIntent); + cgeoimages.startActivitySpoilerImages(cgeodetail.this, geocode, cache.getSpoilers()); } public class codeHint implements View.OnClickListener { diff --git a/main/src/cgeo/geocaching/cgeoimages.java b/main/src/cgeo/geocaching/cgeoimages.java index 48b7985..89badae 100644 --- a/main/src/cgeo/geocaching/cgeoimages.java +++ b/main/src/cgeo/geocaching/cgeoimages.java @@ -8,6 +8,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import android.app.ProgressDialog; +import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; @@ -35,8 +36,8 @@ import java.util.List; public class cgeoimages extends AbstractActivity { private static final int UNKNOWN_TYPE = 0; - public static final int LOG_IMAGES = 1; - public static final int SPOILER_IMAGES = 2; + private static final int LOG_IMAGES = 1; + private static final int SPOILER_IMAGES = 2; private String geocode = null; private LayoutInflater inflater = null; @@ -45,7 +46,7 @@ public class cgeoimages extends AbstractActivity { private int count = 0; private int countDone = 0; - static private Collection<Bitmap> bitmaps = Collections.synchronizedCollection(new ArrayList<Bitmap>()); + static private final Collection<Bitmap> bitmaps = Collections.synchronizedCollection(new ArrayList<Bitmap>()); private void loadImages(final List<cgImage> images, final int progressMessage, final boolean offline) { @@ -61,11 +62,11 @@ public class cgeoimages extends AbstractActivity { for (final cgImage img : images) { rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null); - ((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.title)); + ((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.getTitle())); - if (StringUtils.isNotBlank(img.description)) { + if (StringUtils.isNotBlank(img.getDescription())) { final TextView descView = (TextView) rowView.findViewById(R.id.description); - descView.setText(Html.fromHtml(img.description), TextView.BufferType.SPANNABLE); + descView.setText(Html.fromHtml(img.getDescription()), TextView.BufferType.SPANNABLE); descView.setVisibility(View.VISIBLE); } @@ -89,7 +90,7 @@ public class cgeoimages extends AbstractActivity { @Override protected BitmapDrawable doInBackground(Void... params) { final HtmlImage imgGetter = new HtmlImage(cgeoimages.this, geocode, true, offline ? 1 : 0, false); - return imgGetter.getDrawable(img.url); + return imgGetter.getDrawable(img.getUrl()); } @Override @@ -115,13 +116,14 @@ public class cgeoimages extends AbstractActivity { return; } - Intent intent = new Intent(); + final Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/jpg"); startActivity(intent); - if (file.exists()) + if (file.exists()) { file.deleteOnExit(); + } } }); image_view.setImageDrawable(image); @@ -146,7 +148,7 @@ public class cgeoimages extends AbstractActivity { super.onCreate(savedInstanceState); // get parameters - Bundle extras = getIntent().getExtras(); + final Bundle extras = getIntent().getExtras(); // try to get data from extras int img_type = UNKNOWN_TYPE; @@ -200,10 +202,20 @@ public class cgeoimages extends AbstractActivity { super.onDestroy(); } - @Override - public void onResume() { - super.onResume(); + public static void startActivityLogImages(final Context fromActivity, final String geocode, ArrayList<cgImage> logImages) { + startActivity(fromActivity, geocode, logImages, cgeoimages.LOG_IMAGES); + } + + private static void startActivity(final Context fromActivity, final String geocode, ArrayList<cgImage> logImages, int imageType) { + final Intent logImgIntent = new Intent(fromActivity, cgeoimages.class); + logImgIntent.putExtra("geocode", geocode.toUpperCase()); + logImgIntent.putExtra("type", imageType); + logImgIntent.putParcelableArrayListExtra("images", logImages); + fromActivity.startActivity(logImgIntent); + } + public static void startActivitySpoilerImages(final Context fromActivity, String geocode, ArrayList<cgImage> spoilers) { + startActivity(fromActivity, geocode, spoilers, cgeoimages.SPOILER_IMAGES); } } diff --git a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java index a0af45c..c1d4586 100644 --- a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java @@ -111,13 +111,12 @@ final public class OkapiClient { final JSONArray images = response.getJSONArray(CACHE_IMAGES); if (images != null) { JSONObject imageResponse; - cgImage image; for (int i = 0; i < images.length(); i++) { imageResponse = images.getJSONObject(i); if (imageResponse.getBoolean(CACHE_IMAGE_IS_SPOILER)) { - image = new cgImage(); - image.title = imageResponse.getString(CACHE_IMAGE_CAPTION); - image.url = absoluteUrl(imageResponse.getString(CACHE_IMAGE_URL), cache.getGeocode()); + final String title = imageResponse.getString(CACHE_IMAGE_CAPTION); + final String url = absoluteUrl(imageResponse.getString(CACHE_IMAGE_URL), cache.getGeocode()); + final cgImage image = new cgImage(url, title); if (cache.getSpoilers() == null) { cache.setSpoilers(new ArrayList<cgImage>()); } diff --git a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java index 1c7ac5b..5ff95b3 100644 --- a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java +++ b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java @@ -97,7 +97,7 @@ public class GC2JVEH extends MockedCache { @Override public List<String> getAttributes() { - String[] attributes = new String[] { + final String[] attributes = new String[] { "winter_yes", "flashlight_yes", "stealth_yes", @@ -111,7 +111,7 @@ public class GC2JVEH extends MockedCache { @Override public Map<Integer, Integer> getLogCounts() { - Map<Integer, Integer> logCounts = new HashMap<Integer, Integer>(); + final Map<Integer, Integer> logCounts = new HashMap<Integer, Integer>(); logCounts.put(cgBase.LOG_FOUND_IT, 59); logCounts.put(cgBase.LOG_NOTE, 7); logCounts.put(cgBase.LOG_TEMP_DISABLE_LISTING, 1); @@ -122,7 +122,7 @@ public class GC2JVEH extends MockedCache { @Override public Integer getFavoritePoints() { - return new Integer(21); + return 21; } @Override @@ -132,17 +132,18 @@ public class GC2JVEH extends MockedCache { @Override public List<cgTrackable> getInventory() { - ArrayList<cgTrackable> inventory = new ArrayList<cgTrackable>(); + final ArrayList<cgTrackable> inventory = new ArrayList<cgTrackable>(); inventory.add(new cgTrackable()); return inventory; } @Override public List<cgImage> getSpoilers() { - ArrayList<cgImage> spoilers = new ArrayList<cgImage>(); - spoilers.add(new cgImage()); - spoilers.add(new cgImage()); - spoilers.add(new cgImage()); + final ArrayList<cgImage> spoilers = new ArrayList<cgImage>(); + final cgImage mockedImage = new cgImage(null, null, null); + spoilers.add(mockedImage); + spoilers.add(mockedImage); + spoilers.add(mockedImage); return spoilers; } } |