diff options
Diffstat (limited to 'main/src/cgeo/geocaching/cgeotrackable.java')
| -rw-r--r-- | main/src/cgeo/geocaching/cgeotrackable.java | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java index 1d5b5db..2a0a017 100644 --- a/main/src/cgeo/geocaching/cgeotrackable.java +++ b/main/src/cgeo/geocaching/cgeotrackable.java @@ -1,10 +1,12 @@ package cgeo.geocaching; import cgeo.geocaching.activity.AbstractActivity; +import cgeo.geocaching.connector.gc.GCParser; import cgeo.geocaching.geopoint.HumanDistance; import cgeo.geocaching.network.HtmlImage; +import cgeo.geocaching.ui.Formatter; +import cgeo.geocaching.utils.Log; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import android.app.ProgressDialog; @@ -16,7 +18,6 @@ import android.os.Handler; import android.os.Message; import android.text.Html; import android.text.method.LinkMovementMethod; -import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.Menu; @@ -48,13 +49,6 @@ public class cgeotrackable extends AbstractActivity { @Override public void handleMessage(Message msg) { - if (trackable != null && StringUtils.isNotBlank(trackable.getError())) { - showToast(res.getString(R.string.err_tb_details_download) + " " + trackable.getError() + "."); - - finish(); - return; - } - if (trackable == null) { if (waitDialog != null) { waitDialog.dismiss(); @@ -94,7 +88,7 @@ public class cgeotrackable extends AbstractActivity { addDetail(R.string.trackable_name, StringUtils.isNotBlank(trackable.getName()) ? Html.fromHtml(trackable.getName()).toString() : res.getString(R.string.trackable_unknown)); // trackable type - String tbType = null; + String tbType; if (StringUtils.isNotBlank(trackable.getType())) { tbType = Html.fromHtml(trackable.getType()).toString(); } else { @@ -117,7 +111,7 @@ public class cgeotrackable extends AbstractActivity { trackable.getSpottedType() == cgTrackable.SPOTTED_UNKNOWN || trackable.getSpottedType() == cgTrackable.SPOTTED_OWNER ) { - String text = null; + String text; if (trackable.getSpottedType() == cgTrackable.SPOTTED_CACHE) { text = res.getString(R.string.trackable_spotted_in_cache) + " " + Html.fromHtml(trackable.getSpottedName()).toString(); @@ -155,7 +149,7 @@ public class cgeotrackable extends AbstractActivity { // trackable released if (trackable.getReleased() != null) { - addDetail(R.string.trackable_released, cgBase.formatDate(trackable.getReleased().getTime())); + addDetail(R.string.trackable_released, Formatter.formatDate(trackable.getReleased().getTime())); } // trackable distance @@ -213,7 +207,7 @@ public class cgeotrackable extends AbstractActivity { @Override public void run() { - BitmapDrawable image = null; + BitmapDrawable image; try { HtmlImage imgGetter = new HtmlImage(cgeotrackable.this, geocode, true, 0, false); @@ -221,7 +215,7 @@ public class cgeotrackable extends AbstractActivity { Message message = handler.obtainMessage(0, image); handler.sendMessage(message); } catch (Exception e) { - Log.e(Settings.tag, "cgeospoilers.onCreate.onClick.run: " + e.toString()); + Log.e("cgeospoilers.onCreate.onClick.run: " + e.toString()); } } }.start(); @@ -229,7 +223,7 @@ public class cgeotrackable extends AbstractActivity { imgView.addView(trackableImage); } } catch (Exception e) { - Log.e(Settings.tag, "cgeotrackable.loadTrackableHandler: " + e.toString() + Arrays.toString(e.getStackTrace())); + Log.e("cgeotrackable.loadTrackableHandler: " + e.toString() + Arrays.toString(e.getStackTrace())); } displayLogs(); @@ -356,21 +350,20 @@ public class cgeotrackable extends AbstractActivity { } @Override - public boolean onContextItemSelected(MenuItem item) { - final int id = item.getItemId(); - - if (id == 1) { - cgeocaches.startActivityOwner(this, contextMenuUser); - return true; - } else if (id == 2) { - cgeocaches.startActivityUserName(this, contextMenuUser); - return true; - } else if (id == 3) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/profile/?u=" + URLEncoder.encode(contextMenuUser)))); - - return true; + public boolean onContextItemSelected(final MenuItem item) { + switch (item.getItemId()) { + case 1: + cgeocaches.startActivityOwner(this, contextMenuUser); + return true; + case 2: + cgeocaches.startActivityUserName(this, contextMenuUser); + return true; + case 3: + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/profile/?u=" + URLEncoder.encode(contextMenuUser)))); + return true; + default: + return false; } - return false; } @Override @@ -418,7 +411,6 @@ public class cgeotrackable extends AbstractActivity { stop(); finish(); - return; } } @@ -428,7 +420,7 @@ public class cgeotrackable extends AbstractActivity { trackable = cgeoapplication.getInstance().getTrackableByGeocode(geocode); if ((trackable == null || trackable.isLoggable()) && !StringUtils.startsWithIgnoreCase(geocode, "GK")) { - trackable = cgBase.searchTrackable(geocode, guid, id); + trackable = GCParser.searchTrackable(geocode, guid, id); } handler.sendMessage(Message.obtain()); } @@ -442,11 +434,11 @@ public class cgeotrackable extends AbstractActivity { RelativeLayout rowView; if (trackable != null && trackable.getLogs() != null) { - for (cgLog log : trackable.getLogs()) { + for (LogEntry log : trackable.getLogs()) { 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)); + ((TextView) rowView.findViewById(R.id.added)).setText(Formatter.formatShortDate(log.date)); } ((TextView) rowView.findViewById(R.id.type)).setText(log.type.getL10n()); @@ -460,24 +452,21 @@ public class cgeotrackable extends AbstractActivity { final String cacheName = log.cacheName; ((TextView) rowView.findViewById(R.id.location)).setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { - Intent cacheIntent = new Intent(cgeotrackable.this, CacheDetailActivity.class); - cacheIntent.putExtra("guid", cacheGuid); - cacheIntent.putExtra("name", Html.fromHtml(cacheName).toString()); - startActivity(cacheIntent); + CacheDetailActivity.startActivityGuid(cgeotrackable.this, cacheGuid, Html.fromHtml(cacheName).toString()); } }); } TextView logView = (TextView) rowView.findViewById(R.id.log); logView.setMovementMethod(LinkMovementMethod.getInstance()); - logView.setText(Html.fromHtml(log.log, new HtmlImage(cgeotrackable.this, null, false, StoredList.TEMPORARY_LIST_ID, false), null), TextView.BufferType.SPANNABLE); + logView.setText(Html.fromHtml(log.log, new HtmlImage(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)) { + if (log.hasLogImages()) { - final ArrayList<cgImage> logImages = new ArrayList<cgImage>(log.logImages); + final ArrayList<cgImage> logImages = new ArrayList<cgImage>(log.getLogImages()); final View.OnClickListener listener = new View.OnClickListener() { @Override @@ -487,8 +476,8 @@ public class cgeotrackable extends AbstractActivity { }; 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(); + for (cgImage image : log.getLogImages()) { + String img_title = image.getTitle(); if (!StringUtils.isBlank(img_title)) { titles.add(img_title); } @@ -525,7 +514,7 @@ public class cgeotrackable extends AbstractActivity { registerForContextMenu(view); openContextMenu(view); } catch (Exception e) { - Log.e(Settings.tag, "cgeotrackable.userActions.onClick ", e); + Log.e("cgeotrackable.userActions.onClick ", e); } } } @@ -565,7 +554,7 @@ public class cgeotrackable extends AbstractActivity { return; } - BitmapDrawable image = null; + BitmapDrawable image; try { HtmlImage imgGetter = new HtmlImage(cgeotrackable.this, trackable.getGeocode(), false, 0, false); @@ -573,7 +562,7 @@ public class cgeotrackable extends AbstractActivity { Message message = handler.obtainMessage(0, image); handler.sendMessage(message); } catch (Exception e) { - Log.e(Settings.tag, "cgeotrackable.tbIconThread.run: " + e.toString()); + Log.e("cgeotrackable.tbIconThread.run: " + e.toString()); } } } |
