diff options
Diffstat (limited to 'main/src/cgeo/geocaching/CacheDetailActivity.java')
| -rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 62f946a..a9b6bf7 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -1425,6 +1425,26 @@ public class CacheDetailActivity extends AbstractActivity { buttonWatchlistRemove.setOnClickListener(new RemoveFromWatchlistClickListener()); updateWatchlistBox(); + // favorite points + Button buttonFavPointAdd = (Button) view.findViewById(R.id.add_to_favpoint); + Button buttonFavPointRemove = (Button) view.findViewById(R.id.remove_from_favpoint); + buttonFavPointAdd.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + GCConnector.addToFavorites(cache); + updateFavPointBox(); + } + }); + buttonFavPointRemove.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + GCConnector.removeFromFavorites(cache); + updateFavPointBox(); + } + }); + + updateFavPointBox(); + // data license IConnector connector = ConnectorFactory.getConnector(cache); if (connector != null) { @@ -1689,6 +1709,41 @@ public class CacheDetailActivity extends AbstractActivity { } /** + * shows/hides buttons, sets text in watchlist box + */ + private void updateFavPointBox() { + boolean userIsOwner = StringUtils.equals(cache.getOwnerReal(), Settings.getUsername()); + + LinearLayout layout = (LinearLayout) view.findViewById(R.id.favpoint_box); + boolean supportsFavoritePoints = cache.supportsFavoritePoints(); + layout.setVisibility(supportsFavoritePoints ? View.VISIBLE : View.GONE); + if (!supportsFavoritePoints || userIsOwner || !Settings.isPremiumMember()) { + return; + } + Button buttonAdd = (Button) view.findViewById(R.id.add_to_favpoint); + Button buttonRemove = (Button) view.findViewById(R.id.remove_from_favpoint); + TextView text = (TextView) view.findViewById(R.id.favpoint_text); + + if (cache.isFavorite()) { + buttonAdd.setVisibility(View.GONE); + buttonRemove.setVisibility(View.VISIBLE); + text.setText(R.string.cache_favpoint_on); + } else { + buttonAdd.setVisibility(View.VISIBLE); + buttonRemove.setVisibility(View.GONE); + text.setText(R.string.cache_favpoint_not_on); + } + + // Add/remove to Favorites is only possible if the cache has been found + if (!cache.isFound()) { + buttonAdd.setEnabled(false); + buttonAdd.setVisibility(View.GONE); + buttonRemove.setEnabled(false); + buttonRemove.setVisibility(View.GONE); + } + } + + /** * Handler, called when watchlist add or remove is done */ private class WatchlistHandler extends Handler { |
