DateTime in custom pass

This commit is contained in:
ligi 2015-03-06 15:44:50 +01:00
parent ff0d33e158
commit d2cf9e5970
2 changed files with 19 additions and 0 deletions

View file

@ -2,6 +2,9 @@ package org.ligi.passandroid.model;
import com.google.common.base.Optional;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.json.JSONException;
import org.json.JSONObject;
@ -32,6 +35,14 @@ public class PassWriter {
object.put("fgColor", "#" +String.format("%08X", pass.getForegroundColor()));
object.put("bgColor", "#" +String.format("%08X", pass.getBackGroundColor()));
final Optional<DateTime> relevantDate = pass.getRelevantDate();
if (relevantDate.isPresent()) {
final JSONObject timeObject = new JSONObject();
DateTimeFormatter df = DateTimeFormat.forPattern("dd MM yyyy HH:mm:ss.SSS Z");
timeObject.put("dateTime", relevantDate.get().toString());
object.put("when", timeObject);
}
return object.toString(2);
} catch (JSONException e) {

View file

@ -1,8 +1,10 @@
package org.ligi.passandroid.reader;
import android.graphics.Color;
import com.google.common.base.Optional;
import com.google.zxing.BarcodeFormat;
import java.io.File;
import org.joda.time.DateTime;
import org.json.JSONObject;
import org.ligi.axt.AXT;
import org.ligi.passandroid.helper.SafeJSONReader;
@ -48,6 +50,12 @@ public class PassReader {
}
if (pass_json.has("when")) {
final JSONObject when = pass_json.getJSONObject("when");
final String dateTime = when.getString("dateTime");
pass.setRelevantDate(Optional.of(DateTime.parse(dateTime)));
}
} catch (Exception e) {
Log.i("PassParse Exception " + e);
}