aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/export/FieldnoteExport.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/export/FieldnoteExport.java')
-rw-r--r--main/src/cgeo/geocaching/export/FieldnoteExport.java55
1 files changed, 25 insertions, 30 deletions
diff --git a/main/src/cgeo/geocaching/export/FieldnoteExport.java b/main/src/cgeo/geocaching/export/FieldnoteExport.java
index 11214db..65dc291 100644
--- a/main/src/cgeo/geocaching/export/FieldnoteExport.java
+++ b/main/src/cgeo/geocaching/export/FieldnoteExport.java
@@ -3,7 +3,7 @@ package cgeo.geocaching.export;
import cgeo.geocaching.LogEntry;
import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.cgData;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.activity.Progress;
import cgeo.geocaching.connector.gc.Login;
@@ -12,7 +12,9 @@ import cgeo.geocaching.network.Network;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.utils.Log;
+import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang3.StringUtils;
+import org.mapsforge.core.IOUtils;
import android.app.Activity;
import android.app.AlertDialog;
@@ -31,6 +33,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
+import java.util.TimeZone;
/**
* Exports offline-logs in the Groundspeak Field Note format.<br>
@@ -42,6 +45,9 @@ import java.util.Locale;
class FieldnoteExport extends AbstractExport {
private static final File exportLocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/field-notes");
private static final SimpleDateFormat fieldNoteDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
+ static {
+ fieldNoteDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ }
protected FieldnoteExport() {
super(getString(R.string.export_fieldnotes));
@@ -135,13 +141,11 @@ class FieldnoteExport extends AbstractExport {
@Override
protected Boolean doInBackground(Void... params) {
final StringBuilder fieldNoteBuffer = new StringBuilder();
- final cgeoapplication app = cgeoapplication.getInstance();
-
try {
int i = 0;
for (cgCache cache : caches) {
if (cache.isLogOffline()) {
- appendFieldNote(fieldNoteBuffer, cache, app.loadLogOffline(cache.getGeocode()));
+ appendFieldNote(fieldNoteBuffer, cache, cgData.loadLogOffline(cache.getGeocode()));
publishProgress(++i);
}
}
@@ -152,40 +156,30 @@ class FieldnoteExport extends AbstractExport {
fieldNoteBuffer.append('\n');
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- exportLocation.mkdirs();
+ if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+ return false;
+ }
- SimpleDateFormat fileNameDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
- exportFile = new File(exportLocation.toString() + '/' + fileNameDateFormat.format(new Date()) + ".txt");
+ exportLocation.mkdirs();
- OutputStream os;
- Writer fw = null;
- try {
- os = new FileOutputStream(exportFile);
- fw = new OutputStreamWriter(os, "UTF-16");
- fw.write(fieldNoteBuffer.toString());
- } catch (IOException e) {
- Log.e("FieldnoteExport.ExportTask export", e);
- return false;
- } finally {
- if (fw != null) {
- try {
- fw.close();
- } catch (IOException e) {
- Log.e("FieldnoteExport.ExportTask export", e);
- return false;
- }
- }
- }
- } else {
+ SimpleDateFormat fileNameDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
+ exportFile = new File(exportLocation.toString() + '/' + fileNameDateFormat.format(new Date()) + ".txt");
+
+ Writer fw = null;
+ try {
+ OutputStream os = new FileOutputStream(exportFile);
+ fw = new OutputStreamWriter(os, CharEncoding.UTF_16);
+ fw.write(fieldNoteBuffer.toString());
+ } catch (IOException e) {
+ Log.e("FieldnoteExport.ExportTask export", e);
return false;
+ } finally {
+ IOUtils.closeQuietly(fw);
}
if (upload) {
publishProgress(STATUS_UPLOAD);
- final String uri = "http://www.geocaching.com/my/uploadfieldnotes.aspx";
-
if (!Login.isActualLoginStatus()) {
// no need to upload (possibly large file) if we're not logged in
final StatusCode loginState = Login.login();
@@ -194,6 +188,7 @@ class FieldnoteExport extends AbstractExport {
}
}
+ final String uri = "http://www.geocaching.com/my/uploadfieldnotes.aspx";
String page = Network.getResponseData(Network.getRequest(uri));
if (!Login.getLoginStatus(page)) {