@TargetApi(Build.VERSION_CODES.KITKAT) @Override public boolean onPreferenceClick(Preference preference) { if (preference == exportConfig) { SyncthingUtils.exportConfig(getActivity()); return true; } else if (preference == importConfig) { final File[] availableExports = SyncthingUtils.listExportedConfigs(getActivity()); if (availableExports == null || availableExports.length == 0) { showFilePicker(); } else { String[] items = new String[availableExports.length]; for (int ii = 0; ii < items.length; ii++) { items[ii] = availableExports[ii].getName(); } AlertDialog.Builder bob = new AlertDialog.Builder(getActivity()) .setTitle(R.string.import_config) .setSingleChoiceItems( items, 0, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { File file = availableExports[which]; if (file.exists()) { SyncthingUtils.importConfig(getActivity(), Uri.fromFile(file), false); mSettings.setInitialized(ConfigXml.get(getActivity()) != null); } } }) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton( R.string.show_file_picker, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showFilePicker(); } }); bob.show(); } return true; } return false; }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == ActivityRequestCodes.IMPORT_CONFIG && resultCode == Activity.RESULT_OK) { SyncthingUtils.importConfig(getActivity(), data.getData(), false); mSettings.setInitialized(ConfigXml.get(getActivity()) != null); } else { super.onActivityResult(requestCode, resultCode, data); } }
@Override protected void onStop() { super.onStop(); SyncthingUtils.notifyForegroundStateChanged(this, false); }