1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 03:11:30 +00:00

Cancel restart notification on shutdown, minor refactoring.

This commit is contained in:
Felix Ableitner 2014-05-30 20:07:31 +02:00
parent 231f6d4fca
commit d3a5b09568
2 changed files with 9 additions and 6 deletions

View file

@ -31,7 +31,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
*/ */
public static final String TYPE_GUI = "GUI"; public static final String TYPE_GUI = "GUI";
private static final int NOTIFICATION_ID = 2; private static final int NOTIFICATION_RESTART = 2;
private Context mContext; private Context mContext;
@ -43,10 +43,14 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
private JSONObject mConfig; private JSONObject mConfig;
private NotificationManager mNotificationManager;
public RestApi(Context context, String url, String apiKey) { public RestApi(Context context, String url, String apiKey) {
mContext = context; mContext = context;
mUrl = url; mUrl = url;
mApiKey = apiKey; mApiKey = apiKey;
mNotificationManager = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
} }
/** /**
@ -89,6 +93,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
* Stops syncthing. You should probably use SyncthingService.stopService() instead. * Stops syncthing. You should probably use SyncthingService.stopService() instead.
*/ */
public void shutdown() { public void shutdown() {
mNotificationManager.cancel(NOTIFICATION_RESTART);
new PostTask().execute(mUrl, PostTask.URI_SHUTDOWN, mApiKey, ""); new PostTask().execute(mUrl, PostTask.URI_SHUTDOWN, mApiKey, "");
} }
@ -168,9 +173,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
.setContentIntent(pi) .setContentIntent(pi)
.build(); .build();
n.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; n.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
NotificationManager mNotificationManager = mNotificationManager.notify(NOTIFICATION_RESTART, n);
(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, n);
} }
} }

View file

@ -56,7 +56,7 @@ public class SyncthingService extends Service {
private static final String TAG = "SyncthingService"; private static final String TAG = "SyncthingService";
private static final int NOTIFICATION_ID = 1; private static final int NOTIFICATION_RUNNING = 1;
/** /**
* Intent action to perform a syncthing restart. * Intent action to perform a syncthing restart.
@ -303,7 +303,7 @@ public class SyncthingService extends Service {
.setContentIntent(pi) .setContentIntent(pi)
.build(); .build();
n.flags |= Notification.FLAG_ONGOING_EVENT; n.flags |= Notification.FLAG_ONGOING_EVENT;
startForeground(NOTIFICATION_ID, n); startForeground(NOTIFICATION_RUNNING, n);
new StartupTask().execute(); new StartupTask().execute();
} }