mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 06:11:19 +00:00
Change restart handling to show a dialog first (ref #49).
The notification is only shown if the dialog is dismissed, in which case the dialog won't show up as long as syncthing is not restarted.
This commit is contained in:
parent
50c71c5b45
commit
61eba3da1d
5 changed files with 67 additions and 39 deletions
|
@ -163,7 +163,7 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
||||||
Toast.makeText(this, R.string.node_name_required, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.node_name_required, Toast.LENGTH_LONG).show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mSyncthingService.getApi().editNode(mNode, true);
|
mSyncthingService.getApi().editNode(mNode, true, this);
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
case R.id.share_node_id:
|
case R.id.share_node_id:
|
||||||
|
@ -216,7 +216,7 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
mSyncthingService.getApi().deleteNode(mNode);
|
mSyncthingService.getApi().deleteNode(mNode, NodeSettingsActivity.this);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -246,7 +246,7 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
||||||
*/
|
*/
|
||||||
private void nodeUpdated() {
|
private void nodeUpdated() {
|
||||||
if (getIntent().getAction().equals(ACTION_EDIT)) {
|
if (getIntent().getAction().equals(ACTION_EDIT)) {
|
||||||
mSyncthingService.getApi().editNode(mNode, false);
|
mSyncthingService.getApi().editNode(mNode, false, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ public class RepoSettingsActivity extends PreferenceActivity
|
||||||
Toast.makeText(this, R.string.repo_path_required, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.repo_path_required, Toast.LENGTH_LONG).show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mSyncthingService.getApi().editRepo(mRepo, true);
|
mSyncthingService.getApi().editRepo(mRepo, true, this);
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
|
@ -295,7 +295,7 @@ public class RepoSettingsActivity extends PreferenceActivity
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
mSyncthingService.getApi().deleteRepo(mRepo);
|
mSyncthingService.getApi().deleteRepo(mRepo, RepoSettingsActivity.this);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -317,7 +317,7 @@ public class RepoSettingsActivity extends PreferenceActivity
|
||||||
|
|
||||||
private void repoUpdated() {
|
private void repoUpdated() {
|
||||||
if (getIntent().getAction().equals(ACTION_EDIT)) {
|
if (getIntent().getAction().equals(ACTION_EDIT)) {
|
||||||
mSyncthingService.getApi().editRepo(mRepo, false);
|
mSyncthingService.getApi().editRepo(mRepo, false, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,11 +161,12 @@ public class SettingsActivity extends PreferenceActivity
|
||||||
|
|
||||||
if (mOptionsScreen.findPreference(preference.getKey()) != null) {
|
if (mOptionsScreen.findPreference(preference.getKey()) != null) {
|
||||||
mSyncthingService.getApi().setValue(RestApi.TYPE_OPTIONS, preference.getKey(), o,
|
mSyncthingService.getApi().setValue(RestApi.TYPE_OPTIONS, preference.getKey(), o,
|
||||||
preference.getKey().equals("ListenAddress"));
|
preference.getKey().equals("ListenAddress"), this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (mGuiScreen.findPreference(preference.getKey()) != null) {
|
else if (mGuiScreen.findPreference(preference.getKey()) != null) {
|
||||||
mSyncthingService.getApi().setValue(RestApi.TYPE_GUI, preference.getKey(), o, false);
|
mSyncthingService.getApi().setValue(
|
||||||
|
RestApi.TYPE_GUI, preference.getKey(), o, false, this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.nutomic.syncthingandroid.syncthing;
|
package com.nutomic.syncthingandroid.syncthing;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -131,6 +133,8 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
|
|
||||||
private final NotificationManager mNotificationManager;
|
private final NotificationManager mNotificationManager;
|
||||||
|
|
||||||
|
private boolean mRestartPostponed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the result of the last successful request to {@link GetTask#URI_CONNECTIONS},
|
* Stores the result of the last successful request to {@link GetTask#URI_CONNECTIONS},
|
||||||
* or an empty HashMap.
|
* or an empty HashMap.
|
||||||
|
@ -267,12 +271,12 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
* @param value The new value to set, either String, Boolean or Integer.
|
* @param value The new value to set, either String, Boolean or Integer.
|
||||||
* @param isArray True iff value is a space seperated String that should be converted to array.
|
* @param isArray True iff value is a space seperated String that should be converted to array.
|
||||||
*/
|
*/
|
||||||
public <T> void setValue(String name, String key, T value, boolean isArray) {
|
public <T> void setValue(String name, String key, T value, boolean isArray, Activity activity) {
|
||||||
try {
|
try {
|
||||||
mConfig.getJSONObject(name).put(key, (isArray)
|
mConfig.getJSONObject(name).put(key, (isArray)
|
||||||
? listToJson(((String) value).split(" "))
|
? listToJson(((String) value).split(" "))
|
||||||
: value);
|
: value);
|
||||||
configUpdated();
|
configUpdated(activity);
|
||||||
}
|
}
|
||||||
catch (JSONException e) {
|
catch (JSONException e) {
|
||||||
Log.w(TAG, "Failed to set value for " + key, e);
|
Log.w(TAG, "Failed to set value for " + key, e);
|
||||||
|
@ -294,21 +298,41 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
/**
|
/**
|
||||||
* Sends the updated mConfig via Rest API to syncthing and displays a "restart" notification.
|
* Sends the updated mConfig via Rest API to syncthing and displays a "restart" notification.
|
||||||
*/
|
*/
|
||||||
private void configUpdated() {
|
private void configUpdated(Activity activity) {
|
||||||
new PostTask().execute(mUrl, PostTask.URI_CONFIG, mApiKey, mConfig.toString());
|
new PostTask().execute(mUrl, PostTask.URI_CONFIG, mApiKey, mConfig.toString());
|
||||||
|
|
||||||
Intent i = new Intent(mSyncthingService, SyncthingService.class)
|
if (mRestartPostponed) {
|
||||||
.setAction(SyncthingService.ACTION_RESTART);
|
return;
|
||||||
PendingIntent pi = PendingIntent.getService(mSyncthingService, 0, i, 0);
|
}
|
||||||
|
|
||||||
Notification n = new NotificationCompat.Builder(mSyncthingService)
|
final Intent intent = new Intent(mSyncthingService, SyncthingService.class)
|
||||||
.setContentTitle(mSyncthingService.getString(R.string.restart_notif_title))
|
.setAction(SyncthingService.ACTION_RESTART);
|
||||||
.setContentText(mSyncthingService.getString(R.string.restart_notif_text))
|
|
||||||
.setSmallIcon(R.drawable.ic_launcher)
|
new AlertDialog.Builder(activity)
|
||||||
.setContentIntent(pi)
|
.setMessage(R.string.restart_title)
|
||||||
.build();
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
n.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
|
@Override
|
||||||
mNotificationManager.notify(NOTIFICATION_RESTART, n);
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
mSyncthingService.startService(intent);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.restart_later, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
PendingIntent pi = PendingIntent.getService(mSyncthingService, 0, intent, 0);
|
||||||
|
|
||||||
|
Notification n = new NotificationCompat.Builder(mSyncthingService)
|
||||||
|
.setContentTitle(mSyncthingService.getString(R.string.restart_title))
|
||||||
|
.setContentText(mSyncthingService.getString(R.string.restart_notification_text))
|
||||||
|
.setSmallIcon(R.drawable.ic_launcher)
|
||||||
|
.setContentIntent(pi)
|
||||||
|
.build();
|
||||||
|
n.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
|
||||||
|
mNotificationManager.notify(NOTIFICATION_RESTART, n);
|
||||||
|
mRestartPostponed = true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -557,7 +581,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
/**
|
/**
|
||||||
* Updates or creates the given node.
|
* Updates or creates the given node.
|
||||||
*/
|
*/
|
||||||
public void editNode(Node node, boolean create) {
|
public void editNode(Node node, boolean create, Activity activity) {
|
||||||
try {
|
try {
|
||||||
JSONArray nodes = mConfig.getJSONArray("Nodes");
|
JSONArray nodes = mConfig.getJSONArray("Nodes");
|
||||||
JSONObject n = null;
|
JSONObject n = null;
|
||||||
|
@ -577,7 +601,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
n.put("NodeID", node.NodeID);
|
n.put("NodeID", node.NodeID);
|
||||||
n.put("Name", node.Name);
|
n.put("Name", node.Name);
|
||||||
n.put("Addresses", listToJson(node.Addresses.split(" ")));
|
n.put("Addresses", listToJson(node.Addresses.split(" ")));
|
||||||
configUpdated();
|
configUpdated(activity);
|
||||||
}
|
}
|
||||||
catch (JSONException e) {
|
catch (JSONException e) {
|
||||||
Log.w(TAG, "Failed to read nodes", e);
|
Log.w(TAG, "Failed to read nodes", e);
|
||||||
|
@ -587,7 +611,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
/**
|
/**
|
||||||
* Deletes the given node from syncthing.
|
* Deletes the given node from syncthing.
|
||||||
*/
|
*/
|
||||||
public void deleteNode(Node node) {
|
public void deleteNode(Node node, Activity activity) {
|
||||||
try {
|
try {
|
||||||
JSONArray nodes = mConfig.getJSONArray("Nodes");
|
JSONArray nodes = mConfig.getJSONArray("Nodes");
|
||||||
|
|
||||||
|
@ -599,7 +623,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configUpdated();
|
configUpdated(activity);
|
||||||
}
|
}
|
||||||
catch (JSONException e) {
|
catch (JSONException e) {
|
||||||
Log.w(TAG, "Failed to edit repo", e);
|
Log.w(TAG, "Failed to edit repo", e);
|
||||||
|
@ -609,7 +633,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
/**
|
/**
|
||||||
* Updates or creates the given node.
|
* Updates or creates the given node.
|
||||||
*/
|
*/
|
||||||
public void editRepo(Repo repo, boolean create) {
|
public void editRepo(Repo repo, boolean create, Activity activity) {
|
||||||
try {
|
try {
|
||||||
JSONArray repos = mConfig.getJSONArray("Repositories");
|
JSONArray repos = mConfig.getJSONArray("Repositories");
|
||||||
JSONObject r = null;
|
JSONObject r = null;
|
||||||
|
@ -647,7 +671,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
params.put(key, repo.Versioning.getParams().get(key));
|
params.put(key, repo.Versioning.getParams().get(key));
|
||||||
}
|
}
|
||||||
r.put("Versioning", versioning);
|
r.put("Versioning", versioning);
|
||||||
configUpdated();
|
configUpdated(activity);
|
||||||
}
|
}
|
||||||
catch (JSONException e) {
|
catch (JSONException e) {
|
||||||
Log.w(TAG, "Failed to edit repo " + repo.ID + " at " + repo.Directory, e);
|
Log.w(TAG, "Failed to edit repo " + repo.ID + " at " + repo.Directory, e);
|
||||||
|
@ -657,7 +681,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
/**
|
/**
|
||||||
* Deletes the given repository from syncthing.
|
* Deletes the given repository from syncthing.
|
||||||
*/
|
*/
|
||||||
public void deleteRepo(Repo repo) {
|
public void deleteRepo(Repo repo, Activity activity) {
|
||||||
try {
|
try {
|
||||||
JSONArray repos = mConfig.getJSONArray("Repositories");
|
JSONArray repos = mConfig.getJSONArray("Repositories");
|
||||||
|
|
||||||
|
@ -669,7 +693,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configUpdated();
|
configUpdated(activity);
|
||||||
}
|
}
|
||||||
catch (JSONException e) {
|
catch (JSONException e) {
|
||||||
Log.w(TAG, "Failed to edit repo", e);
|
Log.w(TAG, "Failed to edit repo", e);
|
||||||
|
|
|
@ -3,15 +3,6 @@
|
||||||
|
|
||||||
<string name="app_name">Syncthing</string>
|
<string name="app_name">Syncthing</string>
|
||||||
|
|
||||||
<!-- Title of the notification shown when a restart is needed -->
|
|
||||||
<string name="restart_notif_title">Restart Needed</string>
|
|
||||||
|
|
||||||
<!-- Text of the notification shown when a restart is needed -->
|
|
||||||
<string name="restart_notif_text">Click here to restart syncthing now</string>
|
|
||||||
|
|
||||||
<!-- ActionBar title shown when the drawer is open -->
|
|
||||||
<string name="system_info">System Info</string>
|
|
||||||
|
|
||||||
<!-- MainActivity -->
|
<!-- MainActivity -->
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,6 +59,9 @@
|
||||||
<!-- LocalNodeInfoFragment -->
|
<!-- LocalNodeInfoFragment -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ActionBar title shown when the drawer is open -->
|
||||||
|
<string name="system_info">System Info</string>
|
||||||
|
|
||||||
<!-- Same as download_title with a colon and space appended -->
|
<!-- Same as download_title with a colon and space appended -->
|
||||||
<string name="download_title_colon">Download:\u0020</string>
|
<string name="download_title_colon">Download:\u0020</string>
|
||||||
|
|
||||||
|
@ -220,6 +214,15 @@ Please report any problems you encounter.</string>
|
||||||
<!-- RestApi -->
|
<!-- RestApi -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Title of the notification shown when a restart is needed -->
|
||||||
|
<string name="restart_title">Restart Needed</string>
|
||||||
|
|
||||||
|
<!-- Text of the notification shown when a restart is needed -->
|
||||||
|
<string name="restart_notification_text">Click here to restart syncthing now</string>
|
||||||
|
|
||||||
|
<!-- Text for the dismiss button of the restart Activity -->
|
||||||
|
<string name="restart_later">Restart Later</string>
|
||||||
|
|
||||||
<!-- Strings representing units for file sizes, from smallest to largest -->
|
<!-- Strings representing units for file sizes, from smallest to largest -->
|
||||||
<string-array name="file_size_units">
|
<string-array name="file_size_units">
|
||||||
<item>B</item>
|
<item>B</item>
|
||||||
|
|
Loading…
Reference in a new issue