コード例 #1
0
ファイル: GCVote.java プロジェクト: devykm/cgeo
  public static void loadRatings(final @NonNull ArrayList<Geocache> caches) {
    if (!Settings.isRatingWanted()) {
      return;
    }

    final ArrayList<String> geocodes = getVotableGeocodes(caches);
    if (geocodes.isEmpty()) {
      return;
    }

    try {
      final Map<String, GCVoteRating> ratings = GCVote.getRating(null, geocodes);

      // save found cache coordinates
      for (Geocache cache : caches) {
        if (ratings.containsKey(cache.getGeocode())) {
          GCVoteRating rating = ratings.get(cache.getGeocode());

          cache.setRating(rating.getRating());
          cache.setVotes(rating.getVotes());
          cache.setMyVote(rating.getMyVote());
        }
      }
    } catch (Exception e) {
      Log.e("GCvote.loadRatings", e);
    }
  }
コード例 #2
0
ファイル: GCVoteRatingBarUtil.java プロジェクト: sababys/cgeo
  public static void initializeRatingBar(
      @NonNull final Geocache cache,
      final View parentView,
      @Nullable final OnRatingChangeListener changeListener) {
    if (GCVote.isVotingPossible(cache)) {
      final RatingBar ratingBar = ButterKnife.findById(parentView, R.id.gcvoteRating);
      final TextView label = ButterKnife.findById(parentView, R.id.gcvoteLabel);
      ratingBar.setVisibility(View.VISIBLE);
      label.setVisibility(View.VISIBLE);
      ratingBar.setOnRatingBarChangeListener(
          new OnRatingBarChangeListener() {

            @Override
            public void onRatingChanged(
                final RatingBar ratingBar, final float stars, final boolean fromUser) {
              // 0.5 is not a valid rating, therefore we must limit
              final float rating = GCVote.isValidRating(stars) ? stars : 0;
              if (rating < stars) {
                ratingBar.setRating(rating);
              }
              label.setText(GCVote.getDescription(rating));
              if (changeListener != null) {
                changeListener.onRatingChanged(rating);
              }
            }
          });
      ratingBar.setRating(cache.getMyVote());
    }
  }
コード例 #3
0
ファイル: SearchResult.java プロジェクト: hakan42/cgeo
  /**
   * @param excludeDisabled
   * @param excludeMine
   * @param cacheType
   * @return
   */
  public SearchResult filterSearchResults(
      final boolean excludeDisabled, final boolean excludeMine, final CacheType cacheType) {

    SearchResult result = new SearchResult(this);
    result.geocodes.clear();
    final ArrayList<Geocache> includedCaches = new ArrayList<Geocache>();
    final Set<Geocache> caches = DataStore.loadCaches(geocodes, LoadFlags.LOAD_CACHE_OR_DB);
    int excluded = 0;
    for (Geocache cache : caches) {
      // Is there any reason to exclude the cache from the list?
      final boolean excludeCache =
          (excludeDisabled && cache.isDisabled())
              || (excludeMine && (cache.isOwner() || cache.isFound()))
              || (!cacheType.contains(cache));
      if (excludeCache) {
        excluded++;
      } else {
        includedCaches.add(cache);
      }
    }
    result.addAndPutInCache(includedCaches);
    // decrease maximum number of caches by filtered ones
    result.setTotalCountGC(result.getTotalCountGC() - excluded);
    GCVote.loadRatings(includedCaches);
    return result;
  }
コード例 #4
0
ファイル: LogCacheActivity.java プロジェクト: pstorch/cgeo
  private void initializeRatingBar() {
    if (GCVote.isVotingPossible(cache)) {
      GCVoteRatingBarUtil.initializeRatingBar(
          cache,
          getWindow().getDecorView().getRootView(),
          new OnRatingChangeListener() {

            @Override
            public void onRatingChanged(final float stars) {
              rating = stars;
            }
          });
    }
  }
コード例 #5
0
ファイル: LogCacheActivity.java プロジェクト: kozakakos/cgeo
    @Override
    protected StatusCode doInBackgroundInternal(final String[] logTexts) {
      final String log = logTexts[0];
      final String logPwd = logTexts.length > 1 ? logTexts[1] : null;
      try {
        final LogResult logResult =
            loggingManager.postLog(cache, typeSelected, date, log, logPwd, 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);
          cache.clearOfflineLog();

          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;
    }
コード例 #6
0
  public StatusCode postLogFn(String log) {
    try {
      final StatusCode status =
          cgBase.postLog(
              geocode,
              cacheid,
              viewstates,
              typeSelected,
              date.get(Calendar.YEAR),
              (date.get(Calendar.MONTH) + 1),
              date.get(Calendar.DATE),
              log,
              trackables);

      if (status == StatusCode.NO_ERROR) {
        final cgLog logNow = new cgLog();
        logNow.author = Settings.getUsername();
        logNow.date = date.getTimeInMillis();
        logNow.type = typeSelected;
        logNow.log = log;

        if (cache != null) {
          cache.prependLog(logNow);
        }
        app.addLog(geocode, logNow);

        if (typeSelected == LogType.LOG_FOUND_IT) {
          app.markFound(geocode);
          if (cache != null) {
            cache.setFound(true);
          }
        }

        if (cache != null) {
          app.saveCache(cache, EnumSet.of(SaveFlag.SAVE_CACHE));
        } else {
          app.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
        }
      }

      if (status == StatusCode.NO_ERROR) {
        app.clearLogOffline(geocode);
      }

      if (status == StatusCode.NO_ERROR
          && typeSelected == LogType.LOG_FOUND_IT
          && Settings.isUseTwitter()
          && Settings.isTwitterLoginValid()
          && tweetCheck.isChecked()
          && tweetBox.getVisibility() == View.VISIBLE) {
        Twitter.postTweetCache(geocode);
      }

      if (status == StatusCode.NO_ERROR
          && typeSelected == LogType.LOG_FOUND_IT
          && Settings.isGCvoteLogin()) {
        GCVote.setRating(cache, rating);
      }

      return status;
    } catch (Exception e) {
      Log.e("cgeovisit.postLogFn: " + e.toString());
    }

    return StatusCode.LOG_POST_ERROR;
  }
コード例 #7
0
ファイル: LogCacheActivity.java プロジェクト: pstorch/cgeo
    @Override
    protected StatusCode doInBackgroundInternal(final String[] logTexts) {
      final String log = logTexts[0];
      final String logPwd = logTexts.length > 1 ? logTexts[1] : null;

      try {
        final LogResult logResult =
            loggingManager.postLog(typeSelected, date, log, logPwd, new ArrayList<>(trackables));
        ImageResult imageResult = null;

        if (logResult.getPostLogResult() == StatusCode.NO_ERROR) {
          // update geocache in DB
          if (typeSelected.isFoundLog()) {
            cache.setFound(true);
            cache.setVisitedDate(date.getTimeInMillis());
          }
          DataStore.saveChangedCache(cache);

          final LogEntry.Builder logBuilder =
              new LogEntry.Builder()
                  .setDate(date.getTimeInMillis())
                  .setLogType(typeSelected)
                  .setLog(log)
                  .setFriend(true);

          // Posting image
          if (!image.isEmpty()) {
            publishProgress(res.getString(R.string.log_posting_image));
            imageResult = loggingManager.postLogImage(logResult.getLogId(), image);
            final String uploadedImageUrl = imageResult.getImageUri();
            if (StringUtils.isNotEmpty(uploadedImageUrl)) {
              logBuilder.addLogImage(image.buildUpon().setUrl(uploadedImageUrl).build());
            }
          }

          // update logs in DB
          final List<LogEntry> newLogs = new ArrayList<>(cache.getLogs());
          final LogEntry logNow = logBuilder.build();
          newLogs.add(0, logNow);
          DataStore.saveLogs(cache.getGeocode(), newLogs);

          // update offline log in DB
          cache.clearOfflineLog();

          if (typeSelected == LogType.FOUND_IT
              && tweetCheck.isChecked()
              && tweetCheck.getVisibility() == View.VISIBLE) {
            publishProgress(res.getString(R.string.log_posting_twitter));
            Twitter.postTweetCache(geocode, logNow);
          }
          if (GCVote.isValidRating(rating) && GCVote.isVotingPossible(cache)) {
            publishProgress(res.getString(R.string.log_posting_gcvote));
            if (GCVote.setRating(cache, rating)) {
              cache.setMyVote(rating);
              DataStore.saveChangedCache(cache);
            } else {
              showToast(res.getString(R.string.err_gcvote_send_rating));
            }
          }

          // Posting Generic Trackables
          for (final TrackableConnector connector :
              ConnectorFactory.getLoggableGenericTrackablesConnectors()) {
            final TrackableLoggingManager manager =
                connector.getTrackableLoggingManager((AbstractLoggingActivity) activity);
            if (manager != null) {
              // Filter trackables logs by action and brand
              final Set<TrackableLog> trackablesMoved = new HashSet<>();
              for (final TrackableLog trackableLog : trackables) {
                if (trackableLog.action != LogTypeTrackable.DO_NOTHING
                    && trackableLog.brand == connector.getBrand()) {
                  trackablesMoved.add(trackableLog);
                }
              }

              // Posting trackables logs
              int trackableLogcounter = 1;
              for (final TrackableLog trackableLog : trackablesMoved) {
                publishProgress(
                    res.getString(
                        R.string.log_posting_generic_trackable,
                        trackableLog.brand.getLabel(),
                        trackableLogcounter,
                        trackablesMoved.size()));
                manager.postLog(cache, trackableLog, date, log);
                trackableLogcounter++;
              }
            }
          }
        }

        // Todo error handling should be better than that
        if (imageResult != null
            && imageResult.getPostResult() != StatusCode.NO_ERROR
            && imageResult.getPostResult() != StatusCode.LOG_SAVED) {
          return imageResult.getPostResult();
        }
        return logResult.getPostLogResult();
      } catch (final RuntimeException e) {
        Log.e("LogCacheActivity.Poster.doInBackgroundInternal", e);
      }

      return StatusCode.LOG_POST_ERROR;
    }