1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-27 06:41:15 +00:00

Show confirm dialog before config import/export (fixes #456).

This commit is contained in:
Felix Ableitner 2015-09-11 17:24:56 +02:00
parent 82ccd340bf
commit 3986198fa4
2 changed files with 42 additions and 11 deletions

View file

@ -1,5 +1,7 @@
package com.nutomic.syncthingandroid.fragments; package com.nutomic.syncthingandroid.fragments;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -308,19 +310,42 @@ public class SettingsFragment extends PreferenceFragment
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
switch (preference.getKey()) { switch (preference.getKey()) {
case EXPORT_CONFIG: case EXPORT_CONFIG:
mSyncthingService.exportConfig(); new AlertDialog.Builder(getActivity())
Toast.makeText(getActivity(), getString(R.string.config_export_successful, .setMessage(R.string.dialog_confirm_export)
SyncthingService.EXPORT_PATH), Toast.LENGTH_LONG).show(); .setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mSyncthingService.exportConfig();
Toast.makeText(getActivity(),
getString(R.string.config_export_successful,
SyncthingService.EXPORT_PATH), Toast.LENGTH_LONG).show();
}
})
.setNegativeButton(android.R.string.no, null)
.show();
return true; return true;
case IMPORT_CONFIG: case IMPORT_CONFIG:
if (mSyncthingService.importConfig()) { new AlertDialog.Builder(getActivity())
Toast.makeText(getActivity(), getString(R.string.config_imported_successful), .setMessage(R.string.dialog_confirm_import)
Toast.LENGTH_SHORT).show(); .setPositiveButton(android.R.string.yes,
mSyncthingService.getApi().requireRestart(getActivity(), false); new DialogInterface.OnClickListener() {
} else { @Override
Toast.makeText(getActivity(), getString(R.string.config_import_failed, public void onClick(DialogInterface dialog, int which) {
SyncthingService.EXPORT_PATH), Toast.LENGTH_LONG).show(); if (mSyncthingService.importConfig()) {
} Toast.makeText(getActivity(),
getString(R.string.config_imported_successful),
Toast.LENGTH_SHORT).show();
mSyncthingService.getApi().requireRestart(getActivity(), false);
} else {
Toast.makeText(getActivity(),
getString(R.string.config_import_failed,
SyncthingService.EXPORT_PATH), Toast.LENGTH_LONG).show();
}
}
})
.setNegativeButton(android.R.string.no, null)
.show();
return true; return true;
case SYNCTHING_RESET: case SYNCTHING_RESET:
((SyncthingActivity) getActivity()).getApi().resetSyncthing(getActivity()); ((SyncthingActivity) getActivity()).getApi().resetSyncthing(getActivity());

View file

@ -136,6 +136,12 @@
<!-- Toast shown when selecting 'devices' if no devices have been added --> <!-- Toast shown when selecting 'devices' if no devices have been added -->
<string name="no_devices">Please connect a device first.</string> <string name="no_devices">Please connect a device first.</string>
<!-- Dialog shown before config export -->
<string name="dialog_confirm_export">Do you really want to export your configuration? Existing files will be overwritten.</string>
<!-- Dialog shown before config import -->
<string name="dialog_confirm_import">Do you really want to import a new configuration? Existing files will be overwritten.</string>
<!-- DeviceSettingsFragment --> <!-- DeviceSettingsFragment -->