Esempio n. 1
0
 public static List<TrackableConnector> getGenericTrackablesConnectors() {
   final List<TrackableConnector> trackableConnectors = new ArrayList<>();
   for (final TrackableConnector connector : TRACKABLE_CONNECTORS) {
     if (connector.isGenericLoggable() && connector.isActive()) {
       trackableConnectors.add(connector);
     }
   }
   return trackableConnectors;
 }
Esempio n. 2
0
 @NonNull
 public static TrackableConnector getTrackableConnector(final String geocode) {
   for (final TrackableConnector connector : TRACKABLE_CONNECTORS) {
     if (connector.canHandleTrackable(geocode)) {
       return connector;
     }
   }
   return UNKNOWN_TRACKABLE_CONNECTOR; // avoid null checks by returning a non implementing
                                       // connector
 }
Esempio n. 3
0
 /**
  * Get trackable's geocode from an URL.
  *
  * @return the geocode, {@code null} if the URL cannot be decoded
  */
 @Nullable
 public static String getTrackableFromURL(final String url) {
   if (url == null) {
     return null;
   }
   for (final TrackableConnector connector : TRACKABLE_CONNECTORS) {
     final String geocode = connector.getTrackableCodeFromUrl(url);
     if (StringUtils.isNotBlank(geocode)) {
       return geocode;
     }
   }
   return null;
 }
Esempio n. 4
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;
    }