mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 19:31:30 +00:00
Restart now when importing config (fixes #386)
This commit is contained in:
parent
cde276891c
commit
9ef1474cbe
2 changed files with 16 additions and 1 deletions
|
@ -1,5 +1,9 @@
|
||||||
package com.nutomic.syncthingandroid.fragments;
|
package com.nutomic.syncthingandroid.fragments;
|
||||||
|
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -16,6 +20,7 @@ import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
|
import com.nutomic.syncthingandroid.activities.MainActivity;
|
||||||
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
|
@ -269,6 +274,16 @@ public class SettingsFragment extends PreferenceFragment
|
||||||
if (mSyncthingService.importConfig()) {
|
if (mSyncthingService.importConfig()) {
|
||||||
Toast.makeText(getActivity(), getString(R.string.config_imported_successful),
|
Toast.makeText(getActivity(), getString(R.string.config_imported_successful),
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
|
// Restart application because API key changed
|
||||||
|
// TODO Should be nicer
|
||||||
|
Intent mStartActivity = new Intent(this.getActivity(), MainActivity.class);
|
||||||
|
int mPendingIntentId = 838465;
|
||||||
|
PendingIntent mPendingIntent = PendingIntent.getActivity(this.getActivity(),
|
||||||
|
mPendingIntentId,
|
||||||
|
mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
AlarmManager mgr = (AlarmManager)this.getActivity().getSystemService(Context.ALARM_SERVICE);
|
||||||
|
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
|
||||||
|
System.exit(0);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getActivity(), getString(R.string.config_import_failed,
|
Toast.makeText(getActivity(), getString(R.string.config_import_failed,
|
||||||
SyncthingService.EXPORT_PATH), Toast.LENGTH_LONG).show();
|
SyncthingService.EXPORT_PATH), Toast.LENGTH_LONG).show();
|
||||||
|
|
|
@ -339,7 +339,6 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the updated mConfig via Rest API to syncthing and displays a "restart"
|
* Sends the updated mConfig via Rest API to syncthing and displays a "restart"
|
||||||
* dialog or notification.
|
* dialog or notification.
|
||||||
|
@ -347,6 +346,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
@TargetApi(11)
|
@TargetApi(11)
|
||||||
public void requireRestart(Activity activity) {
|
public void requireRestart(Activity activity) {
|
||||||
new PostTask(mHttpsCertPath).execute(mUrl, PostTask.URI_CONFIG, mApiKey, mConfig.toString());
|
new PostTask(mHttpsCertPath).execute(mUrl, PostTask.URI_CONFIG, mApiKey, mConfig.toString());
|
||||||
|
// TODO Should wait for completion...
|
||||||
|
|
||||||
if (mRestartPostponed)
|
if (mRestartPostponed)
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue