diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2014-01-11 11:24:51 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2014-01-11 11:24:51 +0100 |
| commit | 040d6e2ceb02e33c2a2f512f0fc655c7845d75f5 (patch) | |
| tree | 8e7d98f893dda26dd0ab9ca0d46d42d8594c2f1e /main/src/cgeo/geocaching/CacheMenuHandler.java | |
| parent | 879f0b09542707f6d64506d65e2680f08a5c4fc2 (diff) | |
| download | cgeo-040d6e2ceb02e33c2a2f512f0fc655c7845d75f5.zip cgeo-040d6e2ceb02e33c2a2f512f0fc655c7845d75f5.tar.gz cgeo-040d6e2ceb02e33c2a2f512f0fc655c7845d75f5.tar.bz2 | |
refactoring: move calendar addon code into a single class
Diffstat (limited to 'main/src/cgeo/geocaching/CacheMenuHandler.java')
| -rw-r--r-- | main/src/cgeo/geocaching/CacheMenuHandler.java | 50 |
1 files changed, 2 insertions, 48 deletions
diff --git a/main/src/cgeo/geocaching/CacheMenuHandler.java b/main/src/cgeo/geocaching/CacheMenuHandler.java index 84a08f5..5f67c57 100644 --- a/main/src/cgeo/geocaching/CacheMenuHandler.java +++ b/main/src/cgeo/geocaching/CacheMenuHandler.java @@ -1,24 +1,13 @@ package cgeo.geocaching; -import cgeo.calendar.ICalendar; +import cgeo.calendar.CalendarAddon; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; -import cgeo.geocaching.geopoint.GeopointFormatter; -import cgeo.geocaching.network.Parameters; import cgeo.geocaching.ui.AbstractUIFactory; -import cgeo.geocaching.ui.dialog.Dialogs; -import cgeo.geocaching.utils.ProcessUtils; - -import org.apache.commons.lang3.StringUtils; import android.app.Activity; -import android.content.DialogInterface; -import android.content.Intent; -import android.net.Uri; import android.view.Menu; import android.view.MenuItem; -import java.util.Date; - /** * Shared menu handling for all activities having menu items related to a cache. * @@ -58,7 +47,7 @@ public class CacheMenuHandler extends AbstractUIFactory { cache.shareCache(activity, res); return true; case R.id.menu_calendar: - addToCalendarWithIntent(activity, cache); + CalendarAddon.addToCalendarWithIntent(activity, cache); return true; default: return false; @@ -80,39 +69,4 @@ public class CacheMenuHandler extends AbstractUIFactory { activity.getMenuInflater().inflate(R.menu.cache_options, menu); onPrepareOptionsMenu(menu, cache); } - - private static void addToCalendarWithIntent(final Activity activity, final Geocache cache) { - final boolean calendarAddOnAvailable = ProcessUtils.isIntentAvailable(ICalendar.INTENT, Uri.parse(ICalendar.URI_SCHEME + "://" + ICalendar.URI_HOST)); - - if (calendarAddOnAvailable) { - final Date hiddenDate = cache.getHiddenDate(); - final Parameters params = new Parameters( - ICalendar.PARAM_NAME, cache.getName(), - ICalendar.PARAM_NOTE, StringUtils.defaultString(cache.getPersonalNote()), - ICalendar.PARAM_HIDDEN_DATE, hiddenDate != null ? String.valueOf(hiddenDate.getTime()) : StringUtils.EMPTY, - ICalendar.PARAM_URL, StringUtils.defaultString(cache.getUrl()), - ICalendar.PARAM_COORDS, cache.getCoords() == null ? "" : cache.getCoords().format(GeopointFormatter.Format.LAT_LON_DECMINUTE_RAW), - ICalendar.PARAM_LOCATION, StringUtils.defaultString(cache.getLocation()), - ICalendar.PARAM_SHORT_DESC, StringUtils.defaultString(cache.getShortDescription()), - ICalendar.PARAM_START_TIME_MINUTES, StringUtils.defaultString(cache.guessEventTimeMinutes()) - ); - - activity.startActivity(new Intent(ICalendar.INTENT, - Uri.parse(ICalendar.URI_SCHEME + "://" + ICalendar.URI_HOST + "?" + params.toString()))); - } else { - // Inform user the calendar add-on is not installed and let them get it from Google Play - Dialogs.confirmYesNo(activity, R.string.addon_missing_title, new StringBuilder(res.getString(R.string.helper_calendar_missing)) - .append(' ') - .append(res.getString(R.string.addon_download_prompt)) - .toString(), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - final Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(ICalendar.CALENDAR_ADDON_URI)); - activity.startActivity(intent); - } - }); - } - } - } |
