From 6c346e0e7ba72dcfae10b2b494f964857c9a14d4 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 9 Jun 2013 17:42:00 +0200 Subject: refactoring: use activity names for layouts --- main/src/cgeo/geocaching/AddressListActivity.java | 2 +- main/src/cgeo/geocaching/CacheDetailActivity.java | 14 +- main/src/cgeo/geocaching/CompassActivity.java | 2 +- main/src/cgeo/geocaching/EditWaypointActivity.java | 2 +- main/src/cgeo/geocaching/Geocache.java | 6 +- main/src/cgeo/geocaching/ImageSelectActivity.java | 2 +- main/src/cgeo/geocaching/ImagesActivity.java | 2 +- main/src/cgeo/geocaching/LogCacheActivity.java | 706 +++++++++++++++++++++ main/src/cgeo/geocaching/LogTrackableActivity.java | 2 +- main/src/cgeo/geocaching/MainActivity.java | 2 +- .../cgeo/geocaching/NavigateAnyPointActivity.java | 6 +- main/src/cgeo/geocaching/SearchActivity.java | 2 +- main/src/cgeo/geocaching/SettingsActivity.java | 2 +- main/src/cgeo/geocaching/StaticMapsActivity.java | 4 +- main/src/cgeo/geocaching/UsefulAppsActivity.java | 6 +- main/src/cgeo/geocaching/VisitCacheActivity.java | 706 --------------------- main/src/cgeo/geocaching/cgeocaches.java | 4 +- .../geocaching/connector/gc/GCLoggingManager.java | 6 +- .../connector/oc/OkapiLoggingManager.java | 6 +- .../src/cgeo/geocaching/ui/AddressListAdapter.java | 2 +- .../cgeo/geocaching/ui/CacheDetailsCreator.java | 2 +- main/src/cgeo/geocaching/ui/CacheListAdapter.java | 2 +- .../ui/dialog/CoordinatesInputDialog.java | 2 +- 23 files changed, 745 insertions(+), 745 deletions(-) create mode 100644 main/src/cgeo/geocaching/LogCacheActivity.java delete mode 100644 main/src/cgeo/geocaching/VisitCacheActivity.java (limited to 'main/src') diff --git a/main/src/cgeo/geocaching/AddressListActivity.java b/main/src/cgeo/geocaching/AddressListActivity.java index 150bbc5..c984d28 100644 --- a/main/src/cgeo/geocaching/AddressListActivity.java +++ b/main/src/cgeo/geocaching/AddressListActivity.java @@ -20,7 +20,7 @@ public class AddressListActivity extends AbstractListActivity { @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState, R.layout.addresses); + super.onCreate(savedInstanceState, R.layout.addresslist_activity); // get parameters final String keyword = getIntent().getStringExtra(Intents.EXTRA_KEYWORD); diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 0f2fba0..32aabd8 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -202,7 +202,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity logCounts = cache.getLogCounts(); @@ -2273,7 +2273,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity possibleLogTypes = new ArrayList(); + private List trackables = null; + private Button postButton = null; + private CheckBox tweetCheck = null; + private LinearLayout tweetBox = null; + private boolean tbChanged = false; + private SparseArray actionButtons; + + private ILoggingManager loggingManager; + + // Data to be saved while reconfiguring + private double rating; + private LogType typeSelected; + private Calendar date; + private String imageCaption; + private String imageDescription; + private Uri imageUri; + + + public void onLoadFinished() { + + if (loggingManager.hasLoaderError()) { + showErrorLoadingData(); + return; + } + + trackables = loggingManager.getTrackables(); + possibleLogTypes = loggingManager.getPossibleLogTypes(); + + if (possibleLogTypes.isEmpty()) { + showErrorLoadingData(); + return; + } + + if (!possibleLogTypes.contains(typeSelected)) { + typeSelected = possibleLogTypes.get(0); + setType(typeSelected); + + showToast(res.getString(R.string.info_log_type_changed)); + } + + enablePostButton(true); + + initializeTrackablesAction(); + updateTrackablesList(); + + showProgress(false); + } + + private void showErrorLoadingData() { + showToast(res.getString(R.string.err_log_load_data)); + showProgress(false); + } + + private void initializeTrackablesAction() { + if (Settings.isTrackableAutoVisit()) { + for (TrackableLog trackable : trackables) { + trackable.action = LogTypeTrackable.VISITED; + tbChanged = true; + } + } + } + + private void updateTrackablesList() { + if (CollectionUtils.isEmpty(trackables)) { + return; + } + if (inflater == null) { + inflater = getLayoutInflater(); + } + actionButtons = new SparseArray(); + + final LinearLayout inventoryView = (LinearLayout) findViewById(R.id.inventory); + inventoryView.removeAllViews(); + + for (TrackableLog tb : trackables) { + LinearLayout inventoryItem = (LinearLayout) inflater.inflate(R.layout.logcache_trackable_item, null); + + ((TextView) inventoryItem.findViewById(R.id.trackcode)).setText(tb.trackCode); + ((TextView) inventoryItem.findViewById(R.id.name)).setText(tb.name); + final TextView actionButton = (TextView) inventoryItem.findViewById(R.id.action); + actionButton.setId(tb.id); + actionButtons.put(actionButton.getId(), tb); + actionButton.setText(res.getString(tb.action.resourceId) + " ▼"); + actionButton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + selectTrackableAction(view); + } + }); + + final String tbCode = tb.trackCode; + inventoryItem.setClickable(true); + inventoryItem.findViewById(R.id.info).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + final Intent trackablesIntent = new Intent(LogCacheActivity.this, TrackableActivity.class); + trackablesIntent.putExtra(Intents.EXTRA_GEOCODE, tbCode); + startActivity(trackablesIntent); + } + }); + + inventoryView.addView(inventoryItem); + } + + if (inventoryView.getChildCount() > 0) { + findViewById(R.id.inventory_box).setVisibility(View.VISIBLE); + } + if (inventoryView.getChildCount() > 1) { + final LinearLayout inventoryChangeAllView = (LinearLayout) findViewById(R.id.inventory_changeall); + + final Button changeButton = (Button) inventoryChangeAllView.findViewById(R.id.changebutton); + changeButton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + selectAllTrackablesAction(); + } + }); + + inventoryChangeAllView.setVisibility(View.VISIBLE); + } + } + + private void enablePostButton(boolean enabled) { + postButton.setEnabled(enabled); + if (enabled) { + postButton.setOnClickListener(new PostListener()); + } + else { + postButton.setOnTouchListener(null); + postButton.setOnClickListener(null); + } + updatePostButtonText(); + } + + private void updatePostButtonText() { + postButton.setText(getPostButtonText()); + } + + private String getPostButtonText() { + if (!postButton.isEnabled()) { + return res.getString(R.string.log_post_not_possible); + } + if (typeSelected != LogType.FOUND_IT || !Settings.isGCvoteLogin() || !cache.supportsGCVote()) { + return res.getString(R.string.log_post); + } + if (rating == 0) { + return res.getString(R.string.log_post_no_rate); + } + return res.getString(R.string.log_post_rate) + " " + ratingTextValue(rating) + "*"; + } + + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState, R.layout.logcache_activity); + + // Get parameters from intent and basic cache information from database + final Bundle extras = getIntent().getExtras(); + if (extras != null) { + cacheid = extras.getString(EXTRAS_ID); + geocode = extras.getString(EXTRAS_GEOCODE); + } + + if ((StringUtils.isBlank(cacheid)) && StringUtils.isNotBlank(geocode)) { + cacheid = cgData.getCacheidForGeocode(geocode); + } + if (StringUtils.isBlank(geocode) && StringUtils.isNotBlank(cacheid)) { + geocode = cgData.getGeocodeForGuid(cacheid); + } + + cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); + possibleLogTypes = cache.getPossibleLogTypes(); + + if (StringUtils.isNotBlank(cache.getName())) { + setTitle(res.getString(R.string.log_new_log) + ": " + cache.getName()); + } else { + setTitle(res.getString(R.string.log_new_log) + ": " + cache.getGeocode()); + } + + // Get ids for later use + postButton = (Button) findViewById(R.id.post); + tweetBox = (LinearLayout) findViewById(R.id.tweet_box); + tweetCheck = (CheckBox) findViewById(R.id.tweet); + + // initialize with default values + setDefaultValues(); + + // Restore previous state + if (savedInstanceState != null) { + rating = savedInstanceState.getDouble(SAVED_STATE_RATING); + typeSelected = LogType.getById(savedInstanceState.getInt(SAVED_STATE_TYPE)); + date.setTimeInMillis(savedInstanceState.getLong(SAVED_STATE_DATE)); + imageCaption = savedInstanceState.getString(SAVED_STATE_IMAGE_CAPTION); + imageDescription = savedInstanceState.getString(SAVED_STATE_IMAGE_DESCRIPTION); + imageUri = Uri.parse(savedInstanceState.getString(SAVED_STATE_IMAGE_URI)); + } else { + // If log had been previously saved, load it now, otherwise initialize signature as needed + final LogEntry log = cgData.loadLogOffline(geocode); + if (log != null) { + typeSelected = log.type; + date.setTime(new Date(log.date)); + text = log.log; + } else if (StringUtils.isNotBlank(Settings.getSignature()) + && Settings.isAutoInsertSignature() + && StringUtils.isBlank(currentLogText())) { + insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(cache)), false); + } + } + updatePostButtonText(); + updateImageButton(); + enablePostButton(false); + + final Button typeButton = (Button) findViewById(R.id.type); + typeButton.setText(typeSelected.getL10n()); + typeButton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + selectLogType(); + } + }); + + final Button dateButton = (Button) findViewById(R.id.date); + setDate(date); + dateButton.setOnClickListener(new DateListener()); + + final EditText logView = (EditText) findViewById(R.id.log); + if (StringUtils.isBlank(currentLogText()) && StringUtils.isNotBlank(text)) { + logView.setText(text); + } + + tweetCheck.setChecked(true); + updateTweetBox(typeSelected); + + final Button imageButton = (Button) findViewById(R.id.image_btn); + imageButton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + selectImage(); + } + }); + + final Button saveButton = (Button) findViewById(R.id.save); + saveButton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + saveLog(true); + } + }); + + final Button clearButton = (Button) findViewById(R.id.clear); + clearButton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + clearLog(); + } + }); + + loggingManager = cache.getLoggingManager(this); + + loggingManager.init(); + } + + private void setDefaultValues() { + date = Calendar.getInstance(); + rating = 0.0; + if (cache.isEventCache()) { + final Date eventDate = cache.getHiddenDate(); + boolean expired = DateUtils.daysSince(eventDate.getTime()) > 0; + + if (cache.hasOwnLog(LogType.WILL_ATTEND) || expired) { + if (cache.hasOwnLog(LogType.ATTENDED)) { + typeSelected = LogType.NOTE; + } + else { + typeSelected = LogType.ATTENDED; + } + } + else { + typeSelected = LogType.WILL_ATTEND; + } + } + else { + if (cache.isFound()) { + typeSelected = LogType.NOTE; + } else { + typeSelected = LogType.FOUND_IT; + } + } + text = null; + imageCaption = StringUtils.EMPTY; + imageDescription = StringUtils.EMPTY; + imageUri = Uri.EMPTY; + } + + private void clearLog() { + cgData.clearLogOffline(geocode); + + setDefaultValues(); + + setType(typeSelected); + setDate(date); + + final EditText logView = (EditText) findViewById(R.id.log); + logView.setText(StringUtils.EMPTY); + + updateImageButton(); + + showToast(res.getString(R.string.info_log_cleared)); + } + + @Override + public void finish() { + saveLog(false); + super.finish(); + } + + @Override + public void onStop() { + saveLog(false); + super.onStop(); + } + + @Override + public boolean onCreateOptionsMenu(final Menu menu) { + super.onCreateOptionsMenu(menu); + + final SubMenu menuStars = menu.addSubMenu(0, SUBMENU_VOTE, 0, res.getString(R.string.log_rating)).setIcon(R.drawable.ic_menu_sort_by_size); + menuStars.add(0, 10, 0, res.getString(R.string.log_no_rating)); + menuStars.add(0, 19, 0, res.getString(R.string.log_stars_5) + " (" + res.getString(R.string.log_stars_5_description) + ")"); + menuStars.add(0, 18, 0, res.getString(R.string.log_stars_45) + " (" + res.getString(R.string.log_stars_45_description) + ")"); + menuStars.add(0, 17, 0, res.getString(R.string.log_stars_4) + " (" + res.getString(R.string.log_stars_4_description) + ")"); + menuStars.add(0, 16, 0, res.getString(R.string.log_stars_35) + " (" + res.getString(R.string.log_stars_35_description) + ")"); + menuStars.add(0, 15, 0, res.getString(R.string.log_stars_3) + " (" + res.getString(R.string.log_stars_3_description) + ")"); + menuStars.add(0, 14, 0, res.getString(R.string.log_stars_25) + " (" + res.getString(R.string.log_stars_25_description) + ")"); + menuStars.add(0, 13, 0, res.getString(R.string.log_stars_2) + " (" + res.getString(R.string.log_stars_2_description) + ")"); + menuStars.add(0, 12, 0, res.getString(R.string.log_stars_15) + " (" + res.getString(R.string.log_stars_15_description) + ")"); + menuStars.add(0, 11, 0, res.getString(R.string.log_stars_1) + " (" + res.getString(R.string.log_stars_1_description) + ")"); + + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + + final boolean voteAvailable = Settings.isGCvoteLogin() && typeSelected == LogType.FOUND_IT && StringUtils.isNotBlank(cache.getGuid()) && cache.supportsGCVote(); + menu.findItem(SUBMENU_VOTE).setVisible(voteAvailable); + + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (super.onOptionsItemSelected(item)) { + return true; + } + + final int id = item.getItemId(); + if (id >= 10 && id <= 19) { + rating = (id - 9) / 2.0; + if (rating < 1) { + rating = 0; + } + updatePostButtonText(); + return true; + } + + return false; + } + + private static String ratingTextValue(final double rating) { + return String.format(Locale.getDefault(), "%.1f", rating); + } + + @Override + protected void onSaveInstanceState(final Bundle outState) { + super.onSaveInstanceState(outState); + outState.putDouble(SAVED_STATE_RATING, rating); + outState.putInt(SAVED_STATE_TYPE, typeSelected.id); + outState.putLong(SAVED_STATE_DATE, date.getTimeInMillis()); + outState.putString(SAVED_STATE_IMAGE_URI, imageUri.getPath()); + outState.putString(SAVED_STATE_IMAGE_CAPTION, imageCaption); + outState.putString(SAVED_STATE_IMAGE_DESCRIPTION, imageDescription); + } + + @Override + public void setDate(Calendar dateIn) { + date = dateIn; + + final Button dateButton = (Button) findViewById(R.id.date); + dateButton.setText(Formatter.formatShortDateVerbally(date.getTime().getTime())); + } + + public void setType(LogType type) { + final Button typeButton = (Button) findViewById(R.id.type); + + typeSelected = type; + typeButton.setText(typeSelected.getL10n()); + + if (LogType.FOUND_IT == type && !tbChanged) { + // TODO: change action + } else if (LogType.FOUND_IT != type && !tbChanged) { + // TODO: change action + } + + updateTweetBox(type); + + updatePostButtonText(); + } + + private void updateTweetBox(LogType type) { + if (type == LogType.FOUND_IT && Settings.isUseTwitter()) { + tweetBox.setVisibility(View.VISIBLE); + } else { + tweetBox.setVisibility(View.GONE); + } + } + + private class DateListener implements View.OnClickListener { + + @Override + public void onClick(View arg0) { + final Dialog dateDialog = new DateDialog(LogCacheActivity.this, LogCacheActivity.this, date); + dateDialog.setCancelable(true); + dateDialog.show(); + } + } + + private class PostListener implements View.OnClickListener { + @Override + public void onClick(View arg0) { + final String message = res.getString(StringUtils.isBlank(imageUri.getPath()) ? + R.string.log_saving : + R.string.log_saving_and_uploading); + new Poster(LogCacheActivity.this, message).execute(currentLogText()); + } + } + + private class Poster extends AsyncTaskWithProgress { + + public Poster(final Activity activity, final String progressMessage) { + super(activity, null, progressMessage, true); + } + + @Override + protected StatusCode doInBackgroundInternal(final String[] logTexts) { + final String log = logTexts[0]; + try { + final LogResult logResult = loggingManager.postLog(cache, typeSelected, date, log, trackables); + + if (logResult.getPostLogResult() == StatusCode.NO_ERROR) { + final LogEntry logNow = new LogEntry(date, typeSelected, log); + + cache.getLogs().add(0, logNow); + + if (typeSelected == LogType.FOUND_IT || typeSelected == LogType.ATTENDED) { + cache.setFound(true); + } + + cgData.saveChangedCache(cache); + cgData.clearLogOffline(geocode); + + if (typeSelected == LogType.FOUND_IT) { + if (tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE) { + Twitter.postTweetCache(geocode); + } + GCVote.setRating(cache, rating); + } + + if (StringUtils.isNotBlank(imageUri.getPath())) { + ImageResult imageResult = loggingManager.postLogImage(logResult.getLogId(), imageCaption, imageDescription, imageUri); + final String uploadedImageUrl = imageResult.getImageUri(); + if (StringUtils.isNotEmpty(uploadedImageUrl)) { + logNow.addLogImage(new Image(uploadedImageUrl, imageCaption, imageDescription)); + cgData.saveChangedCache(cache); + } + return imageResult.getPostResult(); + } + } + + return logResult.getPostLogResult(); + } catch (Exception e) { + Log.e("VisitCacheActivity.Poster.doInBackgroundInternal", e); + } + + return StatusCode.LOG_POST_ERROR; + } + + @Override + protected void onPostExecuteInternal(final StatusCode status) { + if (status == StatusCode.NO_ERROR) { + showToast(res.getString(R.string.info_log_posted)); + // No need to save the log when quitting if it has been posted. + text = currentLogText(); + finish(); + } else if (status == StatusCode.LOG_SAVED) { + showToast(res.getString(R.string.info_log_saved)); + finish(); + } else { + showToast(status.getErrorString(res)); + } + } + } + + private void saveLog(final boolean force) { + final String log = currentLogText(); + + // Do not erase the saved log if the user has removed all the characters + // without using "Clear". This may be a manipulation mistake, and erasing + // again will be easy using "Clear" while retyping the text may not be. + if (force || (StringUtils.isNotEmpty(log) && !StringUtils.equals(log, text))) { + cache.logOffline(this, log, date, typeSelected); + } + text = log; + } + + private String currentLogText() { + return ((EditText) findViewById(R.id.log)).getText().toString(); + } + + @Override + protected LogContext getLogContext() { + return new LogContext(cache); + } + + private void selectAllTrackablesAction() { + Builder alert = new AlertDialog.Builder(this); + alert.setTitle(res.getString(R.string.log_tb_changeall)); + String[] tbLogTypes = getTBLogTypes(); + alert.setItems(tbLogTypes, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int position) { + final LogTypeTrackable logType = LogTypeTrackable.values()[position]; + for (TrackableLog tb : trackables) { + tb.action = logType; + } + tbChanged = true; + updateTrackablesList(); + dialog.dismiss(); + } + }); + alert.create().show(); + } + + private String[] getTBLogTypes() { + final LogTypeTrackable[] logTypeValues = LogTypeTrackable.values(); + String[] logTypes = new String[logTypeValues.length]; + for (int i = 0; i < logTypes.length; i++) { + logTypes[i] = res.getString(logTypeValues[i].resourceId); + } + return logTypes; + } + + private void selectLogType() { + // use a local copy of the possible types, as that one might be modified in the background by the loader + final ArrayList possible = new ArrayList(possibleLogTypes); + + Builder alert = new AlertDialog.Builder(this); + String[] choices = new String[possible.size()]; + for (int i = 0; i < choices.length; i++) { + choices[i] = possible.get(i).getL10n(); + } + alert.setSingleChoiceItems(choices, possible.indexOf(typeSelected), new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int position) { + setType(possible.get(position)); + dialog.dismiss(); + } + }); + alert.create().show(); + } + + private void selectTrackableAction(View view) { + final int realViewId = view.getId(); + Builder alert = new AlertDialog.Builder(this); + final TrackableLog trackableLog = actionButtons.get(realViewId); + alert.setTitle(trackableLog.name); + String[] tbLogTypes = getTBLogTypes(); + alert.setItems(tbLogTypes, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int position) { + final LogTypeTrackable logType = LogTypeTrackable.values()[position]; + tbChanged = true; + trackableLog.action = logType; + Log.i("Trackable " + trackableLog.trackCode + " (" + trackableLog.name + ") has new action: #" + logType); + updateTrackablesList(); + dialog.dismiss(); + } + }); + alert.create().show(); + } + + private void selectImage() { + Intent selectImageIntent = new Intent(this, ImageSelectActivity.class); + selectImageIntent.putExtra(ImageSelectActivity.EXTRAS_CAPTION, imageCaption); + selectImageIntent.putExtra(ImageSelectActivity.EXTRAS_DESCRIPTION, imageDescription); + selectImageIntent.putExtra(ImageSelectActivity.EXTRAS_URI_AS_STRING, imageUri.toString()); + + startActivityForResult(selectImageIntent, SELECT_IMAGE); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == SELECT_IMAGE) { + if (resultCode == RESULT_OK) { + imageCaption = data.getStringExtra(ImageSelectActivity.EXTRAS_CAPTION); + imageDescription = data.getStringExtra(ImageSelectActivity.EXTRAS_DESCRIPTION); + imageUri = Uri.parse(data.getStringExtra(ImageSelectActivity.EXTRAS_URI_AS_STRING)); + } else if (resultCode != RESULT_CANCELED) { + // Image capture failed, advise user + showToast(getResources().getString(R.string.err_select_logimage_failed)); + } + updateImageButton(); + + } + } + + private void updateImageButton() { + final Button imageButton = (Button) findViewById(R.id.image_btn); + if (cache.supportsLogImages()) { + imageButton.setVisibility(View.VISIBLE); + imageButton.setText(StringUtils.isNotBlank(imageUri.getPath()) ? + res.getString(R.string.log_image_edit) : res.getString(R.string.log_image_attach)); + } else { + imageButton.setVisibility(View.GONE); + } + } +} diff --git a/main/src/cgeo/geocaching/LogTrackableActivity.java b/main/src/cgeo/geocaching/LogTrackableActivity.java index 7d8575b..1f6feb7 100644 --- a/main/src/cgeo/geocaching/LogTrackableActivity.java +++ b/main/src/cgeo/geocaching/LogTrackableActivity.java @@ -115,7 +115,7 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState, R.layout.touch); + super.onCreate(savedInstanceState, R.layout.logtrackable_activity); Views.inject(this); // get parameters diff --git a/main/src/cgeo/geocaching/MainActivity.java b/main/src/cgeo/geocaching/MainActivity.java index e8de1f7..9c3e89f 100644 --- a/main/src/cgeo/geocaching/MainActivity.java +++ b/main/src/cgeo/geocaching/MainActivity.java @@ -189,7 +189,7 @@ public class MainActivity extends AbstractActivity { public void onCreate(Bundle savedInstanceState) { // don't call the super implementation with the layout argument, as that would set the wrong theme super.onCreate(savedInstanceState); - setContentView(R.layout.main); + setContentView(R.layout.main_activity); Views.inject(this); if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { diff --git a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java index cc6853b..6f94944 100644 --- a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java +++ b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java @@ -119,7 +119,7 @@ public class NavigateAnyPointActivity extends AbstractActivity { @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState, R.layout.point); + super.onCreate(savedInstanceState, R.layout.navigateanypoint_activity); Views.inject(this); createHistoryView(); @@ -127,7 +127,7 @@ public class NavigateAnyPointActivity extends AbstractActivity { } private void createHistoryView() { - final View pointControls = getLayoutInflater().inflate(R.layout.point_controls, null); + final View pointControls = getLayoutInflater().inflate(R.layout.navigateanypoint_header, null); historyListView.addHeaderView(pointControls, null, false); // inject a second time to also find the dynamically expanded views above @@ -197,7 +197,7 @@ public class NavigateAnyPointActivity extends AbstractActivity { private TextView getEmptyHistoryFooter() { if (historyFooter == null) { - historyFooter = (TextView) getLayoutInflater().inflate(R.layout.caches_footer, null); + historyFooter = (TextView) getLayoutInflater().inflate(R.layout.cacheslist_footer, null); historyFooter.setText(R.string.search_history_empty); } return historyFooter; diff --git a/main/src/cgeo/geocaching/SearchActivity.java b/main/src/cgeo/geocaching/SearchActivity.java index 946724f..0c31abf 100644 --- a/main/src/cgeo/geocaching/SearchActivity.java +++ b/main/src/cgeo/geocaching/SearchActivity.java @@ -78,7 +78,7 @@ public class SearchActivity extends AbstractActivity { } setTheme(); - setContentView(R.layout.search); + setContentView(R.layout.search_activity); // set title in code, as the activity needs a hard coded title due to the intent filters setTitle(res.getString(R.string.search)); diff --git a/main/src/cgeo/geocaching/SettingsActivity.java b/main/src/cgeo/geocaching/SettingsActivity.java index aa163ad..872d5ee 100644 --- a/main/src/cgeo/geocaching/SettingsActivity.java +++ b/main/src/cgeo/geocaching/SettingsActivity.java @@ -126,7 +126,7 @@ public class SettingsActivity extends AbstractActivity { @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState, R.layout.init); + super.onCreate(savedInstanceState, R.layout.settings_activity); init(); } diff --git a/main/src/cgeo/geocaching/StaticMapsActivity.java b/main/src/cgeo/geocaching/StaticMapsActivity.java index d8bc614..5cf9e9d 100644 --- a/main/src/cgeo/geocaching/StaticMapsActivity.java +++ b/main/src/cgeo/geocaching/StaticMapsActivity.java @@ -85,7 +85,7 @@ public class StaticMapsActivity extends AbstractActivity { for (final Bitmap image : maps) { if (image != null) { - final ImageView map = (ImageView) inflater.inflate(R.layout.map_static_item, null); + final ImageView map = (ImageView) inflater.inflate(R.layout.staticmaps_activity_item, null); map.setImageBitmap(image); smapsView.addView(map); } @@ -94,7 +94,7 @@ public class StaticMapsActivity extends AbstractActivity { @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState, R.layout.map_static); + super.onCreate(savedInstanceState, R.layout.staticmaps_activity); if (geocode == null) { showToast("Sorry, c:geo forgot for what cache you want to load static maps."); diff --git a/main/src/cgeo/geocaching/UsefulAppsActivity.java b/main/src/cgeo/geocaching/UsefulAppsActivity.java index b74db83..8093bba 100644 --- a/main/src/cgeo/geocaching/UsefulAppsActivity.java +++ b/main/src/cgeo/geocaching/UsefulAppsActivity.java @@ -67,16 +67,16 @@ public class UsefulAppsActivity extends AbstractActivity { @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState, R.layout.useful_apps_activity); + super.onCreate(savedInstanceState, R.layout.usefulapps_activity); Views.inject(this); - list.setAdapter(new ArrayAdapter(this, R.layout.useful_apps_item, HELPER_APPS) { + list.setAdapter(new ArrayAdapter(this, R.layout.usefulapps_item, HELPER_APPS) { @Override public View getView(int position, View convertView, android.view.ViewGroup parent) { View rowView = convertView; if (null == rowView) { - rowView = getLayoutInflater().inflate(R.layout.useful_apps_item, null); + rowView = getLayoutInflater().inflate(R.layout.usefulapps_item, null); } ViewHolder holder = (ViewHolder) rowView.getTag(); if (null == holder) { diff --git a/main/src/cgeo/geocaching/VisitCacheActivity.java b/main/src/cgeo/geocaching/VisitCacheActivity.java deleted file mode 100644 index 89a7249..0000000 --- a/main/src/cgeo/geocaching/VisitCacheActivity.java +++ /dev/null @@ -1,706 +0,0 @@ -package cgeo.geocaching; - -import cgeo.geocaching.connector.ILoggingManager; -import cgeo.geocaching.connector.ImageResult; -import cgeo.geocaching.connector.LogResult; -import cgeo.geocaching.enumerations.LoadFlags; -import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.enumerations.LogTypeTrackable; -import cgeo.geocaching.enumerations.StatusCode; -import cgeo.geocaching.gcvote.GCVote; -import cgeo.geocaching.twitter.Twitter; -import cgeo.geocaching.ui.Formatter; -import cgeo.geocaching.ui.dialog.DateDialog; -import cgeo.geocaching.utils.AsyncTaskWithProgress; -import cgeo.geocaching.utils.DateUtils; -import cgeo.geocaching.utils.Log; -import cgeo.geocaching.utils.LogTemplateProvider; -import cgeo.geocaching.utils.LogTemplateProvider.LogContext; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.AlertDialog.Builder; -import android.app.Dialog; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.util.SparseArray; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.SubMenu; -import android.view.View; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -public class VisitCacheActivity extends AbstractLoggingActivity implements DateDialog.DateDialogParent { - static final String EXTRAS_GEOCODE = "geocode"; - static final String EXTRAS_ID = "id"; - - private static final int SUBMENU_VOTE = 3; - private static final String SAVED_STATE_RATING = "cgeo.geocaching.saved_state_rating"; - private static final String SAVED_STATE_TYPE = "cgeo.geocaching.saved_state_type"; - private static final String SAVED_STATE_DATE = "cgeo.geocaching.saved_state_date"; - private static final String SAVED_STATE_IMAGE_CAPTION = "cgeo.geocaching.saved_state_image_caption"; - private static final String SAVED_STATE_IMAGE_DESCRIPTION = "cgeo.geocaching.saved_state_image_description"; - private static final String SAVED_STATE_IMAGE_URI = "cgeo.geocaching.saved_state_image_uri"; - - private static final int SELECT_IMAGE = 101; - - private LayoutInflater inflater = null; - private Geocache cache = null; - private String cacheid = null; - private String geocode = null; - private String text = null; - private List possibleLogTypes = new ArrayList(); - private List trackables = null; - private Button postButton = null; - private CheckBox tweetCheck = null; - private LinearLayout tweetBox = null; - private boolean tbChanged = false; - private SparseArray actionButtons; - - private ILoggingManager loggingManager; - - // Data to be saved while reconfiguring - private double rating; - private LogType typeSelected; - private Calendar date; - private String imageCaption; - private String imageDescription; - private Uri imageUri; - - - public void onLoadFinished() { - - if (loggingManager.hasLoaderError()) { - showErrorLoadingData(); - return; - } - - trackables = loggingManager.getTrackables(); - possibleLogTypes = loggingManager.getPossibleLogTypes(); - - if (possibleLogTypes.isEmpty()) { - showErrorLoadingData(); - return; - } - - if (!possibleLogTypes.contains(typeSelected)) { - typeSelected = possibleLogTypes.get(0); - setType(typeSelected); - - showToast(res.getString(R.string.info_log_type_changed)); - } - - enablePostButton(true); - - initializeTrackablesAction(); - updateTrackablesList(); - - showProgress(false); - } - - private void showErrorLoadingData() { - showToast(res.getString(R.string.err_log_load_data)); - showProgress(false); - } - - private void initializeTrackablesAction() { - if (Settings.isTrackableAutoVisit()) { - for (TrackableLog trackable : trackables) { - trackable.action = LogTypeTrackable.VISITED; - tbChanged = true; - } - } - } - - private void updateTrackablesList() { - if (CollectionUtils.isEmpty(trackables)) { - return; - } - if (inflater == null) { - inflater = getLayoutInflater(); - } - actionButtons = new SparseArray(); - - final LinearLayout inventoryView = (LinearLayout) findViewById(R.id.inventory); - inventoryView.removeAllViews(); - - for (TrackableLog tb : trackables) { - LinearLayout inventoryItem = (LinearLayout) inflater.inflate(R.layout.visit_trackable, null); - - ((TextView) inventoryItem.findViewById(R.id.trackcode)).setText(tb.trackCode); - ((TextView) inventoryItem.findViewById(R.id.name)).setText(tb.name); - final TextView actionButton = (TextView) inventoryItem.findViewById(R.id.action); - actionButton.setId(tb.id); - actionButtons.put(actionButton.getId(), tb); - actionButton.setText(res.getString(tb.action.resourceId) + " ▼"); - actionButton.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View view) { - selectTrackableAction(view); - } - }); - - final String tbCode = tb.trackCode; - inventoryItem.setClickable(true); - inventoryItem.findViewById(R.id.info).setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View view) { - final Intent trackablesIntent = new Intent(VisitCacheActivity.this, TrackableActivity.class); - trackablesIntent.putExtra(Intents.EXTRA_GEOCODE, tbCode); - startActivity(trackablesIntent); - } - }); - - inventoryView.addView(inventoryItem); - } - - if (inventoryView.getChildCount() > 0) { - findViewById(R.id.inventory_box).setVisibility(View.VISIBLE); - } - if (inventoryView.getChildCount() > 1) { - final LinearLayout inventoryChangeAllView = (LinearLayout) findViewById(R.id.inventory_changeall); - - final Button changeButton = (Button) inventoryChangeAllView.findViewById(R.id.changebutton); - changeButton.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View view) { - selectAllTrackablesAction(); - } - }); - - inventoryChangeAllView.setVisibility(View.VISIBLE); - } - } - - private void enablePostButton(boolean enabled) { - postButton.setEnabled(enabled); - if (enabled) { - postButton.setOnClickListener(new PostListener()); - } - else { - postButton.setOnTouchListener(null); - postButton.setOnClickListener(null); - } - updatePostButtonText(); - } - - private void updatePostButtonText() { - postButton.setText(getPostButtonText()); - } - - private String getPostButtonText() { - if (!postButton.isEnabled()) { - return res.getString(R.string.log_post_not_possible); - } - if (typeSelected != LogType.FOUND_IT || !Settings.isGCvoteLogin() || !cache.supportsGCVote()) { - return res.getString(R.string.log_post); - } - if (rating == 0) { - return res.getString(R.string.log_post_no_rate); - } - return res.getString(R.string.log_post_rate) + " " + ratingTextValue(rating) + "*"; - } - - @Override - public void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState, R.layout.visit); - - // Get parameters from intent and basic cache information from database - final Bundle extras = getIntent().getExtras(); - if (extras != null) { - cacheid = extras.getString(EXTRAS_ID); - geocode = extras.getString(EXTRAS_GEOCODE); - } - - if ((StringUtils.isBlank(cacheid)) && StringUtils.isNotBlank(geocode)) { - cacheid = cgData.getCacheidForGeocode(geocode); - } - if (StringUtils.isBlank(geocode) && StringUtils.isNotBlank(cacheid)) { - geocode = cgData.getGeocodeForGuid(cacheid); - } - - cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); - possibleLogTypes = cache.getPossibleLogTypes(); - - if (StringUtils.isNotBlank(cache.getName())) { - setTitle(res.getString(R.string.log_new_log) + ": " + cache.getName()); - } else { - setTitle(res.getString(R.string.log_new_log) + ": " + cache.getGeocode()); - } - - // Get ids for later use - postButton = (Button) findViewById(R.id.post); - tweetBox = (LinearLayout) findViewById(R.id.tweet_box); - tweetCheck = (CheckBox) findViewById(R.id.tweet); - - // initialize with default values - setDefaultValues(); - - // Restore previous state - if (savedInstanceState != null) { - rating = savedInstanceState.getDouble(SAVED_STATE_RATING); - typeSelected = LogType.getById(savedInstanceState.getInt(SAVED_STATE_TYPE)); - date.setTimeInMillis(savedInstanceState.getLong(SAVED_STATE_DATE)); - imageCaption = savedInstanceState.getString(SAVED_STATE_IMAGE_CAPTION); - imageDescription = savedInstanceState.getString(SAVED_STATE_IMAGE_DESCRIPTION); - imageUri = Uri.parse(savedInstanceState.getString(SAVED_STATE_IMAGE_URI)); - } else { - // If log had been previously saved, load it now, otherwise initialize signature as needed - final LogEntry log = cgData.loadLogOffline(geocode); - if (log != null) { - typeSelected = log.type; - date.setTime(new Date(log.date)); - text = log.log; - } else if (StringUtils.isNotBlank(Settings.getSignature()) - && Settings.isAutoInsertSignature() - && StringUtils.isBlank(currentLogText())) { - insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(cache)), false); - } - } - updatePostButtonText(); - updateImageButton(); - enablePostButton(false); - - final Button typeButton = (Button) findViewById(R.id.type); - typeButton.setText(typeSelected.getL10n()); - typeButton.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View view) { - selectLogType(); - } - }); - - final Button dateButton = (Button) findViewById(R.id.date); - setDate(date); - dateButton.setOnClickListener(new DateListener()); - - final EditText logView = (EditText) findViewById(R.id.log); - if (StringUtils.isBlank(currentLogText()) && StringUtils.isNotBlank(text)) { - logView.setText(text); - } - - tweetCheck.setChecked(true); - updateTweetBox(typeSelected); - - final Button imageButton = (Button) findViewById(R.id.image_btn); - imageButton.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View view) { - selectImage(); - } - }); - - final Button saveButton = (Button) findViewById(R.id.save); - saveButton.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - saveLog(true); - } - }); - - final Button clearButton = (Button) findViewById(R.id.clear); - clearButton.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - clearLog(); - } - }); - - loggingManager = cache.getLoggingManager(this); - - loggingManager.init(); - } - - private void setDefaultValues() { - date = Calendar.getInstance(); - rating = 0.0; - if (cache.isEventCache()) { - final Date eventDate = cache.getHiddenDate(); - boolean expired = DateUtils.daysSince(eventDate.getTime()) > 0; - - if (cache.hasOwnLog(LogType.WILL_ATTEND) || expired) { - if (cache.hasOwnLog(LogType.ATTENDED)) { - typeSelected = LogType.NOTE; - } - else { - typeSelected = LogType.ATTENDED; - } - } - else { - typeSelected = LogType.WILL_ATTEND; - } - } - else { - if (cache.isFound()) { - typeSelected = LogType.NOTE; - } else { - typeSelected = LogType.FOUND_IT; - } - } - text = null; - imageCaption = StringUtils.EMPTY; - imageDescription = StringUtils.EMPTY; - imageUri = Uri.EMPTY; - } - - private void clearLog() { - cgData.clearLogOffline(geocode); - - setDefaultValues(); - - setType(typeSelected); - setDate(date); - - final EditText logView = (EditText) findViewById(R.id.log); - logView.setText(StringUtils.EMPTY); - - updateImageButton(); - - showToast(res.getString(R.string.info_log_cleared)); - } - - @Override - public void finish() { - saveLog(false); - super.finish(); - } - - @Override - public void onStop() { - saveLog(false); - super.onStop(); - } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - super.onCreateOptionsMenu(menu); - - final SubMenu menuStars = menu.addSubMenu(0, SUBMENU_VOTE, 0, res.getString(R.string.log_rating)).setIcon(R.drawable.ic_menu_sort_by_size); - menuStars.add(0, 10, 0, res.getString(R.string.log_no_rating)); - menuStars.add(0, 19, 0, res.getString(R.string.log_stars_5) + " (" + res.getString(R.string.log_stars_5_description) + ")"); - menuStars.add(0, 18, 0, res.getString(R.string.log_stars_45) + " (" + res.getString(R.string.log_stars_45_description) + ")"); - menuStars.add(0, 17, 0, res.getString(R.string.log_stars_4) + " (" + res.getString(R.string.log_stars_4_description) + ")"); - menuStars.add(0, 16, 0, res.getString(R.string.log_stars_35) + " (" + res.getString(R.string.log_stars_35_description) + ")"); - menuStars.add(0, 15, 0, res.getString(R.string.log_stars_3) + " (" + res.getString(R.string.log_stars_3_description) + ")"); - menuStars.add(0, 14, 0, res.getString(R.string.log_stars_25) + " (" + res.getString(R.string.log_stars_25_description) + ")"); - menuStars.add(0, 13, 0, res.getString(R.string.log_stars_2) + " (" + res.getString(R.string.log_stars_2_description) + ")"); - menuStars.add(0, 12, 0, res.getString(R.string.log_stars_15) + " (" + res.getString(R.string.log_stars_15_description) + ")"); - menuStars.add(0, 11, 0, res.getString(R.string.log_stars_1) + " (" + res.getString(R.string.log_stars_1_description) + ")"); - - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - super.onPrepareOptionsMenu(menu); - - final boolean voteAvailable = Settings.isGCvoteLogin() && typeSelected == LogType.FOUND_IT && StringUtils.isNotBlank(cache.getGuid()) && cache.supportsGCVote(); - menu.findItem(SUBMENU_VOTE).setVisible(voteAvailable); - - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (super.onOptionsItemSelected(item)) { - return true; - } - - final int id = item.getItemId(); - if (id >= 10 && id <= 19) { - rating = (id - 9) / 2.0; - if (rating < 1) { - rating = 0; - } - updatePostButtonText(); - return true; - } - - return false; - } - - private static String ratingTextValue(final double rating) { - return String.format(Locale.getDefault(), "%.1f", rating); - } - - @Override - protected void onSaveInstanceState(final Bundle outState) { - super.onSaveInstanceState(outState); - outState.putDouble(SAVED_STATE_RATING, rating); - outState.putInt(SAVED_STATE_TYPE, typeSelected.id); - outState.putLong(SAVED_STATE_DATE, date.getTimeInMillis()); - outState.putString(SAVED_STATE_IMAGE_URI, imageUri.getPath()); - outState.putString(SAVED_STATE_IMAGE_CAPTION, imageCaption); - outState.putString(SAVED_STATE_IMAGE_DESCRIPTION, imageDescription); - } - - @Override - public void setDate(Calendar dateIn) { - date = dateIn; - - final Button dateButton = (Button) findViewById(R.id.date); - dateButton.setText(Formatter.formatShortDateVerbally(date.getTime().getTime())); - } - - public void setType(LogType type) { - final Button typeButton = (Button) findViewById(R.id.type); - - typeSelected = type; - typeButton.setText(typeSelected.getL10n()); - - if (LogType.FOUND_IT == type && !tbChanged) { - // TODO: change action - } else if (LogType.FOUND_IT != type && !tbChanged) { - // TODO: change action - } - - updateTweetBox(type); - - updatePostButtonText(); - } - - private void updateTweetBox(LogType type) { - if (type == LogType.FOUND_IT && Settings.isUseTwitter()) { - tweetBox.setVisibility(View.VISIBLE); - } else { - tweetBox.setVisibility(View.GONE); - } - } - - private class DateListener implements View.OnClickListener { - - @Override - public void onClick(View arg0) { - final Dialog dateDialog = new DateDialog(VisitCacheActivity.this, VisitCacheActivity.this, date); - dateDialog.setCancelable(true); - dateDialog.show(); - } - } - - private class PostListener implements View.OnClickListener { - @Override - public void onClick(View arg0) { - final String message = res.getString(StringUtils.isBlank(imageUri.getPath()) ? - R.string.log_saving : - R.string.log_saving_and_uploading); - new Poster(VisitCacheActivity.this, message).execute(currentLogText()); - } - } - - private class Poster extends AsyncTaskWithProgress { - - public Poster(final Activity activity, final String progressMessage) { - super(activity, null, progressMessage, true); - } - - @Override - protected StatusCode doInBackgroundInternal(final String[] logTexts) { - final String log = logTexts[0]; - try { - final LogResult logResult = loggingManager.postLog(cache, typeSelected, date, log, trackables); - - if (logResult.getPostLogResult() == StatusCode.NO_ERROR) { - final LogEntry logNow = new LogEntry(date, typeSelected, log); - - cache.getLogs().add(0, logNow); - - if (typeSelected == LogType.FOUND_IT || typeSelected == LogType.ATTENDED) { - cache.setFound(true); - } - - cgData.saveChangedCache(cache); - cgData.clearLogOffline(geocode); - - if (typeSelected == LogType.FOUND_IT) { - if (tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE) { - Twitter.postTweetCache(geocode); - } - GCVote.setRating(cache, rating); - } - - if (StringUtils.isNotBlank(imageUri.getPath())) { - ImageResult imageResult = loggingManager.postLogImage(logResult.getLogId(), imageCaption, imageDescription, imageUri); - final String uploadedImageUrl = imageResult.getImageUri(); - if (StringUtils.isNotEmpty(uploadedImageUrl)) { - logNow.addLogImage(new Image(uploadedImageUrl, imageCaption, imageDescription)); - cgData.saveChangedCache(cache); - } - return imageResult.getPostResult(); - } - } - - return logResult.getPostLogResult(); - } catch (Exception e) { - Log.e("VisitCacheActivity.Poster.doInBackgroundInternal", e); - } - - return StatusCode.LOG_POST_ERROR; - } - - @Override - protected void onPostExecuteInternal(final StatusCode status) { - if (status == StatusCode.NO_ERROR) { - showToast(res.getString(R.string.info_log_posted)); - // No need to save the log when quitting if it has been posted. - text = currentLogText(); - finish(); - } else if (status == StatusCode.LOG_SAVED) { - showToast(res.getString(R.string.info_log_saved)); - finish(); - } else { - showToast(status.getErrorString(res)); - } - } - } - - private void saveLog(final boolean force) { - final String log = currentLogText(); - - // Do not erase the saved log if the user has removed all the characters - // without using "Clear". This may be a manipulation mistake, and erasing - // again will be easy using "Clear" while retyping the text may not be. - if (force || (StringUtils.isNotEmpty(log) && !StringUtils.equals(log, text))) { - cache.logOffline(this, log, date, typeSelected); - } - text = log; - } - - private String currentLogText() { - return ((EditText) findViewById(R.id.log)).getText().toString(); - } - - @Override - protected LogContext getLogContext() { - return new LogContext(cache); - } - - private void selectAllTrackablesAction() { - Builder alert = new AlertDialog.Builder(this); - alert.setTitle(res.getString(R.string.log_tb_changeall)); - String[] tbLogTypes = getTBLogTypes(); - alert.setItems(tbLogTypes, new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int position) { - final LogTypeTrackable logType = LogTypeTrackable.values()[position]; - for (TrackableLog tb : trackables) { - tb.action = logType; - } - tbChanged = true; - updateTrackablesList(); - dialog.dismiss(); - } - }); - alert.create().show(); - } - - private String[] getTBLogTypes() { - final LogTypeTrackable[] logTypeValues = LogTypeTrackable.values(); - String[] logTypes = new String[logTypeValues.length]; - for (int i = 0; i < logTypes.length; i++) { - logTypes[i] = res.getString(logTypeValues[i].resourceId); - } - return logTypes; - } - - private void selectLogType() { - // use a local copy of the possible types, as that one might be modified in the background by the loader - final ArrayList possible = new ArrayList(possibleLogTypes); - - Builder alert = new AlertDialog.Builder(this); - String[] choices = new String[possible.size()]; - for (int i = 0; i < choices.length; i++) { - choices[i] = possible.get(i).getL10n(); - } - alert.setSingleChoiceItems(choices, possible.indexOf(typeSelected), new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int position) { - setType(possible.get(position)); - dialog.dismiss(); - } - }); - alert.create().show(); - } - - private void selectTrackableAction(View view) { - final int realViewId = view.getId(); - Builder alert = new AlertDialog.Builder(this); - final TrackableLog trackableLog = actionButtons.get(realViewId); - alert.setTitle(trackableLog.name); - String[] tbLogTypes = getTBLogTypes(); - alert.setItems(tbLogTypes, new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int position) { - final LogTypeTrackable logType = LogTypeTrackable.values()[position]; - tbChanged = true; - trackableLog.action = logType; - Log.i("Trackable " + trackableLog.trackCode + " (" + trackableLog.name + ") has new action: #" + logType); - updateTrackablesList(); - dialog.dismiss(); - } - }); - alert.create().show(); - } - - private void selectImage() { - Intent selectImageIntent = new Intent(this, ImageSelectActivity.class); - selectImageIntent.putExtra(ImageSelectActivity.EXTRAS_CAPTION, imageCaption); - selectImageIntent.putExtra(ImageSelectActivity.EXTRAS_DESCRIPTION, imageDescription); - selectImageIntent.putExtra(ImageSelectActivity.EXTRAS_URI_AS_STRING, imageUri.toString()); - - startActivityForResult(selectImageIntent, SELECT_IMAGE); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == SELECT_IMAGE) { - if (resultCode == RESULT_OK) { - imageCaption = data.getStringExtra(ImageSelectActivity.EXTRAS_CAPTION); - imageDescription = data.getStringExtra(ImageSelectActivity.EXTRAS_DESCRIPTION); - imageUri = Uri.parse(data.getStringExtra(ImageSelectActivity.EXTRAS_URI_AS_STRING)); - } else if (resultCode != RESULT_CANCELED) { - // Image capture failed, advise user - showToast(getResources().getString(R.string.err_select_logimage_failed)); - } - updateImageButton(); - - } - } - - private void updateImageButton() { - final Button imageButton = (Button) findViewById(R.id.image_btn); - if (cache.supportsLogImages()) { - imageButton.setVisibility(View.VISIBLE); - imageButton.setText(StringUtils.isNotBlank(imageUri.getPath()) ? - res.getString(R.string.log_image_edit) : res.getString(R.string.log_image_attach)); - } else { - imageButton.setVisibility(View.GONE); - } - } -} diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index 6dad510..40dddd4 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -408,7 +408,7 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity super.onCreate(savedInstanceState); setTheme(); - setContentView(R.layout.caches); + setContentView(R.layout.cacheslist_activity); // get parameters Bundle extras = getIntent().getExtras(); @@ -1000,7 +1000,7 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity if (inflater == null) { inflater = getLayoutInflater(); } - listFooter = inflater.inflate(R.layout.caches_footer, null); + listFooter = inflater.inflate(R.layout.cacheslist_footer, null); listFooter.setClickable(true); listFooter.setOnClickListener(new MoreCachesListener()); diff --git a/main/src/cgeo/geocaching/connector/gc/GCLoggingManager.java b/main/src/cgeo/geocaching/connector/gc/GCLoggingManager.java index 0fbd718..4f2f8c4 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCLoggingManager.java +++ b/main/src/cgeo/geocaching/connector/gc/GCLoggingManager.java @@ -4,7 +4,7 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.Settings; import cgeo.geocaching.TrackableLog; -import cgeo.geocaching.VisitCacheActivity; +import cgeo.geocaching.LogCacheActivity; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.connector.ILoggingManager; import cgeo.geocaching.connector.ImageResult; @@ -30,7 +30,7 @@ import java.util.List; public class GCLoggingManager implements ILoggingManager, LoaderManager.LoaderCallbacks { - private final VisitCacheActivity activity; + private final LogCacheActivity activity; private final Geocache cache; private String[] viewstates; @@ -39,7 +39,7 @@ public class GCLoggingManager implements ILoggingManager, LoaderManager.LoaderCa private boolean hasLoaderError = true; public GCLoggingManager(Activity activity, Geocache cache) { - this.activity = (VisitCacheActivity) activity; + this.activity = (LogCacheActivity) activity; this.cache = cache; } diff --git a/main/src/cgeo/geocaching/connector/oc/OkapiLoggingManager.java b/main/src/cgeo/geocaching/connector/oc/OkapiLoggingManager.java index c5d6990..8a94218 100644 --- a/main/src/cgeo/geocaching/connector/oc/OkapiLoggingManager.java +++ b/main/src/cgeo/geocaching/connector/oc/OkapiLoggingManager.java @@ -2,7 +2,7 @@ package cgeo.geocaching.connector.oc; import cgeo.geocaching.Geocache; import cgeo.geocaching.TrackableLog; -import cgeo.geocaching.VisitCacheActivity; +import cgeo.geocaching.LogCacheActivity; import cgeo.geocaching.connector.ILoggingManager; import cgeo.geocaching.connector.ImageResult; import cgeo.geocaching.connector.LogResult; @@ -21,7 +21,7 @@ public class OkapiLoggingManager implements ILoggingManager { private final OCApiConnector connector; private final Geocache cache; - private VisitCacheActivity activity; + private LogCacheActivity activity; private final static List standardLogTypes = Arrays.asList(LogType.FOUND_IT, LogType.DIDNT_FIND_IT, LogType.NOTE, LogType.NEEDS_MAINTENANCE); private final static List eventLogTypes = Arrays.asList(LogType.WILL_ATTEND, LogType.ATTENDED, LogType.NOTE); @@ -29,7 +29,7 @@ public class OkapiLoggingManager implements ILoggingManager { public OkapiLoggingManager(Activity activity, OCApiConnector connector, Geocache cache) { this.connector = connector; this.cache = cache; - this.activity = (VisitCacheActivity) activity; + this.activity = (LogCacheActivity) activity; } @Override diff --git a/main/src/cgeo/geocaching/ui/AddressListAdapter.java b/main/src/cgeo/geocaching/ui/AddressListAdapter.java index 6689bb6..736c036 100644 --- a/main/src/cgeo/geocaching/ui/AddressListAdapter.java +++ b/main/src/cgeo/geocaching/ui/AddressListAdapter.java @@ -50,7 +50,7 @@ public class AddressListAdapter extends ArrayAdapter
{ // holder pattern implementation final ViewHolder holder; if (view == null) { - view = inflater.inflate(R.layout.addresses_item, null); + view = inflater.inflate(R.layout.addresslist_item, null); holder = new ViewHolder(view); } else { holder = (ViewHolder) view.getTag(); diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java index 80f01e2..9059a6b 100644 --- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java +++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java @@ -68,7 +68,7 @@ public final class CacheDetailsCreator { final LayoutInflater inflater = LayoutInflater.from(activity); for (int i = 0; i < 5; i++) { - ImageView star = (ImageView) inflater.inflate(R.layout.star, null); + ImageView star = (ImageView) inflater.inflate(R.layout.star_image, null); if (value - i >= 0.75) { star.setImageResource(R.drawable.star_on); } else if (value - i >= 0.25) { diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index 122f835..d95363e 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -354,7 +354,7 @@ public class CacheListAdapter extends ArrayAdapter { final ViewHolder holder; if (v == null) { - v = inflater.inflate(R.layout.caches_item, null); + v = inflater.inflate(R.layout.cacheslist_item, null); holder = new ViewHolder(v); } else { diff --git a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java index becd422..4ab9af0 100644 --- a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java +++ b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java @@ -72,7 +72,7 @@ public class CoordinatesInputDialog extends Dialog { // nothing } - setContentView(R.layout.coords); + setContentView(R.layout.coordinatesinput_dialog); final Spinner spinner = (Spinner) findViewById(R.id.spinnerCoordinateFormats); final ArrayAdapter adapter = -- cgit v1.1