|
|
@ -28,8 +28,8 @@ import android.os.Bundle; |
|
|
|
import android.preference.CheckBoxPreference; |
|
|
|
import android.preference.CheckBoxPreference; |
|
|
|
import android.preference.Preference; |
|
|
|
import android.preference.Preference; |
|
|
|
import android.preference.Preference.OnPreferenceClickListener; |
|
|
|
import android.preference.Preference.OnPreferenceClickListener; |
|
|
|
import android.preference.PreferenceActivity; |
|
|
|
|
|
|
|
import android.preference.PreferenceManager; |
|
|
|
import android.preference.PreferenceManager; |
|
|
|
|
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import android.text.TextUtils; |
|
|
|
import android.text.TextUtils; |
|
|
|
|
|
|
|
|
|
|
|
import com.nispok.snackbar.Snackbar; |
|
|
|
import com.nispok.snackbar.Snackbar; |
|
|
@ -81,6 +81,7 @@ public class SystemSettingsActivity extends PreferenceCompatActivity { |
|
|
|
protected ErrorLogSender errorLogSender; |
|
|
|
protected ErrorLogSender errorLogSender; |
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
protected SettingsPersistence settingsPersistence; |
|
|
|
protected SettingsPersistence settingsPersistence; |
|
|
|
|
|
|
|
|
|
|
|
private OnPreferenceClickListener onCheckUpdatesClick = new OnPreferenceClickListener() { |
|
|
|
private OnPreferenceClickListener onCheckUpdatesClick = new OnPreferenceClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean onPreferenceClick(Preference preference) { |
|
|
|
public boolean onPreferenceClick(Preference preference) { |
|
|
@ -103,19 +104,12 @@ public class SystemSettingsActivity extends PreferenceCompatActivity { |
|
|
|
private OnClickListener importSettingsFromFile = new OnClickListener() { |
|
|
|
private OnClickListener importSettingsFromFile = new OnClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SystemSettingsActivity.this); |
|
|
|
if (!navigationHelper.checkSettingsReadPermission(SystemSettingsActivity.this)) |
|
|
|
try { |
|
|
|
return; // We are requesting permission to access file storage
|
|
|
|
settingsPersistence.importSettingsFromFile(prefs, SettingsPersistence.DEFAULT_SETTINGS_FILE); |
|
|
|
importSettingsFromFile(); |
|
|
|
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_import_success)); |
|
|
|
|
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
|
|
|
|
SnackbarManager |
|
|
|
|
|
|
|
.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.error_file_not_found).colorResource(R.color.red)); |
|
|
|
|
|
|
|
} catch (JSONException e) { |
|
|
|
|
|
|
|
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this) |
|
|
|
|
|
|
|
.text(getString(R.string.error_no_valid_settings_file, getString(R.string.app_name))).colorResource(R.color.red)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private OnClickListener importSettingsFromQr = new OnClickListener() { |
|
|
|
private OnClickListener importSettingsFromQr = new OnClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
@ -125,16 +119,12 @@ public class SystemSettingsActivity extends PreferenceCompatActivity { |
|
|
|
private OnClickListener exportSettingsToFile = new OnClickListener() { |
|
|
|
private OnClickListener exportSettingsToFile = new OnClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SystemSettingsActivity.this); |
|
|
|
if (!navigationHelper.checkSettingsWritePermission(SystemSettingsActivity.this)) |
|
|
|
try { |
|
|
|
return; // We are requesting permission to access file storage
|
|
|
|
settingsPersistence.exportSettingsToFile(prefs, SettingsPersistence.DEFAULT_SETTINGS_FILE); |
|
|
|
exportSettingsToFile(); |
|
|
|
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_export_success)); |
|
|
|
|
|
|
|
} catch (JSONException | IOException e) { |
|
|
|
|
|
|
|
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.error_cant_write_settings_file) |
|
|
|
|
|
|
|
.colorResource(R.color.red)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private OnClickListener exportSettingsToQr = new OnClickListener() { |
|
|
|
private OnClickListener exportSettingsToQr = new OnClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
@ -176,8 +166,42 @@ public class SystemSettingsActivity extends PreferenceCompatActivity { |
|
|
|
MainSettingsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start(); |
|
|
|
MainSettingsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
|
|
|
|
|
|
|
if (Boolean.TRUE.equals(navigationHelper.handleSettingsReadPermissionResult(requestCode, grantResults))) { |
|
|
|
|
|
|
|
importSettingsFromFile(); |
|
|
|
|
|
|
|
} else if (Boolean.TRUE.equals(navigationHelper.handleSettingsWritePermissionResult(requestCode, grantResults))) { |
|
|
|
|
|
|
|
exportSettingsToFile(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void importSettingsFromFile() { |
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SystemSettingsActivity.this); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
settingsPersistence.importSettingsFromFile(prefs, SettingsPersistence.DEFAULT_SETTINGS_FILE); |
|
|
|
|
|
|
|
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_import_success)); |
|
|
|
|
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
|
|
|
|
SnackbarManager |
|
|
|
|
|
|
|
.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.error_file_not_found).colorResource(R.color.red)); |
|
|
|
|
|
|
|
} catch (JSONException e) { |
|
|
|
|
|
|
|
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this) |
|
|
|
|
|
|
|
.text(getString(R.string.error_no_valid_settings_file, getString(R.string.app_name))).colorResource(R.color.red)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void exportSettingsToFile() { |
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SystemSettingsActivity.this); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
settingsPersistence.exportSettingsToFile(prefs, SettingsPersistence.DEFAULT_SETTINGS_FILE); |
|
|
|
|
|
|
|
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_export_success)); |
|
|
|
|
|
|
|
} catch (JSONException | IOException e) { |
|
|
|
|
|
|
|
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.error_cant_write_settings_file) |
|
|
|
|
|
|
|
.colorResource(R.color.red)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@OnActivityResult(BarcodeHelper.ACTIVITY_BARCODE_QRSETTINGS) |
|
|
|
@OnActivityResult(BarcodeHelper.ACTIVITY_BARCODE_QRSETTINGS) |
|
|
|
public void onQrCodeScanned(int resultCode, Intent data) { |
|
|
|
public void onQrCodeScanned(@SuppressWarnings("UnusedParameters") int resultCode, Intent data) { |
|
|
|
// We should have received Intent extras with the QR-decoded data representing Transdroid settings
|
|
|
|
// We should have received Intent extras with the QR-decoded data representing Transdroid settings
|
|
|
|
if (data == null || !data.hasExtra("SCAN_RESULT")) |
|
|
|
if (data == null || !data.hasExtra("SCAN_RESULT")) |
|
|
|
return; // Cancelled scan; ignore
|
|
|
|
return; // Cancelled scan; ignore
|
|
|
|