예제 #1
0
  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());
    }
  }
예제 #2
0
  private void initializeRatingBar() {
    if (GCVote.isVotingPossible(cache)) {
      GCVoteRatingBarUtil.initializeRatingBar(
          cache,
          getWindow().getDecorView().getRootView(),
          new OnRatingChangeListener() {

            @Override
            public void onRatingChanged(final float stars) {
              rating = stars;
            }
          });
    }
  }
예제 #3
0
    @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;
    }