Skip to content
Browse files

Some fixes for parcel updates.

* Set full Parcel ID when known, to avoid multiple hits in updates (and prepare
  for possibly handling multiple parcel hits in the future).
* When there is only one new event, show the event in the notification, instead
  of just "1 new event".
  • Loading branch information...
1 parent a24dd31 commit b19e83290658a095b20d0e748c6eae94c83dcf20 @firetech committed Jan 11, 2011
View
1 res/values/strings.xml
@@ -86,7 +86,6 @@
<string name="notification_ticker_one">Ny händelse för kolli %s</string>
<string name="notification_ticker">Nya händelser för kolli %s</string>
- <string name="notification_message_one">%d ny händelse</string>
<string name="notification_message">%d nya händelser</string>
<string name="notify_on_title">Aviseringar</string>
View
7 src/nu/firetech/android/pactrack/backend/Parcel.java
@@ -28,6 +28,7 @@
class Parcel {
private int mErrorCode;
+ private String mParcel;
private String mCustomer;
private String mSent;
private double mWeight;
@@ -44,6 +45,8 @@
@SuppressWarnings("unchecked")
Parcel(HashMap<String, Object> data) {
+ mParcel = (String)data.get("parcel");
+
mCustomer = (String)data.get("customername");
mPostal = new StringBuilder((String)data.get("receiverzipcode"))
.append(' ')
@@ -87,6 +90,10 @@ public int getError() {
return mErrorCode;
}
+ public String getParcel() {
+ return mParcel;
+ }
+
public String getCustomer() {
return mCustomer;
}
View
3 src/nu/firetech/android/pactrack/backend/ParcelDbAdapter.java
@@ -304,6 +304,9 @@ public boolean updateParcelData(long rowId, Parcel parcelData) {
String now = String.format("%tF %tT", c, c);
if (parcelData.getError() == Error.NONE) {
+ if (parcelData.getParcel() != null) {
+ args.put(KEY_PARCEL, parcelData.getParcel());
+ }
args.put(KEY_CUSTOMER, parcelData.getCustomer());
args.put(KEY_SENT, parcelData.getSent());
args.put(KEY_WEIGHT, parcelData.getWeight());
View
12 src/nu/firetech/android/pactrack/backend/ParcelUpdater.java
@@ -196,13 +196,17 @@ private void updateParcel(Bundle parcel, ParcelDbAdapter dbAdapter, Notification
Parcel parcelData = ParcelXMLParser.fetch(parcelId);
mDbAdapter.updateParcelData(rowId, parcelData);
+ if (parcelData.getParcel() != null) {
+ parcelId = parcelData.getParcel();
+ }
Context realCtx = (Context)mCtx;
SharedPreferences liveViewPref = PreferenceManager.getDefaultSharedPreferences(realCtx);
boolean liveViewEnabled = liveViewPref.getBoolean(realCtx.getString(R.string.key_liveview_announce), false);
int newEvents = 0;
+ ParcelEvent lastEvent = null;
for (ParcelEvent eventData : parcelData.getEvents()) { //loop through events
if (mDbAdapter.addEvent(rowId, eventData)) { //if event was new
newEvents++;
@@ -213,6 +217,7 @@ private void updateParcel(Bundle parcel, ParcelDbAdapter dbAdapter, Notification
.putExtra(ParcelDbAdapter.KEY_ROWID, rowId);
realCtx.startService(i);
}
+ lastEvent = eventData;
}
}
@@ -226,8 +231,11 @@ private void updateParcel(Bundle parcel, ParcelDbAdapter dbAdapter, Notification
Intent i = new Intent(realCtx, ParcelView.class).putExtra(ParcelDbAdapter.KEY_ROWID, rowId);
PendingIntent pi = PendingIntent.getActivity(realCtx, rowId.hashCode(), i, 0);
- stringId = (newEvents > 1 ? R.string.notification_message : R.string.notification_message_one);
- n.setLatestEventInfo(realCtx.getApplicationContext(), realCtx.getString(R.string.parcel_title, parcelId), realCtx.getString(stringId, newEvents), pi);
+ String eventInfo = realCtx.getString(R.string.notification_message, newEvents);
+ if (newEvents == 1) {
+ eventInfo = lastEvent.toString();
+ }
+ n.setLatestEventInfo(realCtx.getApplicationContext(), realCtx.getString(R.string.parcel_title, parcelId), eventInfo, pi);
n.sound = prefs.getNotificationSound();
if (prefs.getNotificationLight()) {
View
7 src/nu/firetech/android/pactrack/backend/ParcelXMLParser.java
@@ -96,7 +96,12 @@ private ParcelXMLParser() {
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
mElementPath.push(localName);
- if (localName.equals("event")) {
+ if (localName.equals("parcel")) {
+ String parcel = atts.getValue("id");
+ if (parcel != null) {
+ mData.put("parcel", parcel);
+ }
+ } else if (localName.equals("event")) {
mInEvent = true;
} else if (localName.equals("errorevent")) {
mEventData.put("errorevent", "true");

0 comments on commit b19e832

Please sign in to comment.
Something went wrong with that request. Please try again.