Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #433 from flexibeast/notifications

When synchronisation fails, show complete error message in a dialog.
commit 72e7c0e655afb7af535b02151d979bcaf9bd6977 2 parents a336474 + 8d42ea0
@matburt authored
View
5 MobileOrg/src/main/AndroidManifest.xml
@@ -61,9 +61,12 @@
android:label="MobileOrg" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
-
+
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
+ <intent-filter>
+ <action android:name="com.matburt.mobileorg.SYNC_FAILED" />
+ </intent-filter>
</activity>
<activity
android:name=".Gui.ViewActivity"
View
28 MobileOrg/src/main/java/com/matburt/mobileorg/Gui/Outline/OutlineActivity.java
@@ -33,6 +33,8 @@
private final static String OUTLINE_CHECKED_POS = "selection";
private final static String OUTLINE_SCROLL_POS = "scrollPosition";
+ public final static String SYNC_FAILED = "com.matburt.mobileorg.SYNC_FAILED";
+
private Long node_id;
private OutlineListView listView;
@@ -83,9 +85,8 @@ protected void onRestoreInstanceState(Bundle savedInstanceState) {
int scrollPos = savedInstanceState.getInt(OUTLINE_SCROLL_POS, 0);
listView.setSelection(scrollPos);
- }
-
+ }
private void setupList() {
listView = (OutlineListView) findViewById(R.id.outline_list);
@@ -107,6 +108,15 @@ protected void onResume() {
refreshTitle();
}
+ @Override
+ protected void onNewIntent(Intent intent) {
+ if (intent.getAction().equals(SYNC_FAILED)) {
+ Bundle extrasBundle = intent.getExtras();
+ String errorMsg = extrasBundle.getString("ERROR_MESSAGE");
+ showSyncFailPopup(errorMsg);
+ }
+ }
+
@Override
protected void onDestroy() {
unregisterReceiver(this.syncReceiver);
@@ -224,7 +234,19 @@ public void onClick(DialogInterface dialog, int id) {
});
builder.create().show();
}
-
+
+ private void showSyncFailPopup(String errorMsg) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setMessage(errorMsg);
+ builder.setCancelable(false);
+ builder.setPositiveButton(R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.dismiss();
+ }
+ });
+ builder.create().show();
+ }
private class SynchServiceReceiver extends BroadcastReceiver {
@Override
View
15 MobileOrg/src/main/java/com/matburt/mobileorg/Gui/SynchronizerNotification.java
@@ -22,24 +22,25 @@ public SynchronizerNotification(Context context) {
super(context);
this.context = context;
}
-
+
@Override
public void errorNotification(String errorMsg) {
- this.notificationManager = (NotificationManager) context
- .getSystemService(Context.NOTIFICATION_SERVICE);
+ this.notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notifyIntent = new Intent(context, OutlineActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
- | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ notifyIntent.putExtra("ERROR_MESSAGE", errorMsg);
+ notifyIntent.setAction("com.matburt.mobileorg.SYNC_FAILED");
- PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
- notifyIntent, 0);
+ PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notifyIntent, 0);
Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(contentIntent);
builder.setSmallIcon(R.drawable.icon);
builder.setContentTitle(context.getString(R.string.sync_failed));
builder.setContentText(errorMsg);
- notification = builder.getNotification();
+ notification = builder.getNotification();
+ notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notifyRef, notification);
}
Please sign in to comment.
Something went wrong with that request. Please try again.