Ejemplo n.º 1
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(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;
    }
  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;
  }
Ejemplo n.º 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;
    }