@Override public final void endElement(final String uri, final String localName, final String qName) throws SAXException { try { if (localName.equalsIgnoreCase("geolutin_id")) { trackable.setGeocode(content); } if (localName.equalsIgnoreCase("nom")) { trackable.setName(content); } if (localName.equalsIgnoreCase("description")) { trackable.setDetails(content); isMultiline = false; } if (localName.equalsIgnoreCase("esprit_nom")) { if (isInApparition) { logEntryBuilder.setAuthor(content); } else { trackable.setOwner(content); } } if (StringUtils.isNotBlank(content) && localName.equalsIgnoreCase("date_naissance")) { final Date date = DATE_FORMAT.parse(content); trackable.setReleased(date); } if (StringUtils.isNotBlank(content) && localName.equalsIgnoreCase("distance_parcourue")) { trackable.setDistance(Float.parseFloat(content)); } if (localName.equalsIgnoreCase("date_apparition_disparition")) { logEntryBuilder.setDate(DATE_FORMAT.parse(content).getTime()); } if (localName.equalsIgnoreCase("commentaires")) { logEntryBuilder.setLog(content); } if (localName.equalsIgnoreCase("type")) { logEntryBuilder.setLogType(getLogType(content)); } if (localName.equalsIgnoreCase("geolutin")) { trackable.setLogs(logsEntries); // manage spotted field if (!logsEntries.isEmpty()) { // retrieve the first logEntry final LogEntry lastLog = logsEntries.get(0); if (lastLog.getType() == LogType.PLACED_IT) { // it's in a cache trackable.setSpottedType(Trackable.SPOTTED_CACHE); trackable.setSpottedName(lastLog.cacheName); } else if (lastLog.getType() == LogType.RETRIEVED_IT) { trackable.setSpottedName(lastLog.author); // it's in someone hands trackable.setSpottedType(Trackable.SPOTTED_USER); trackable.setSpottedName(lastLog.author); } else { Log.e("GeolutinsHandler.endElement unknown logtype:" + lastLog.getType()); } } } if (localName.equalsIgnoreCase("apparition_disparition")) { isInApparition = false; logsEntries.add(logEntryBuilder.build()); } } catch (final ParseException | NumberFormatException e) { Log.e("Parsing GeoLutins", e); } }
@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; }