use of com.amaze.filemanager.activities.PreferencesActivity in project AmazeFileManager by TeamAmaze.
the class PrefFrag method onPreferenceClick.
@Override
public boolean onPreferenceClick(Preference preference) {
final String[] sort;
MaterialDialog.Builder builder;
switch(preference.getKey()) {
case PreferencesConstants.PREFERENCE_GRID_COLUMNS:
sort = getResources().getStringArray(R.array.columns);
builder = new MaterialDialog.Builder(getActivity());
builder.theme(utilsProvider.getAppTheme().getMaterialDialogTheme());
builder.title(R.string.gridcolumnno);
int current = Integer.parseInt(sharedPref.getString(PreferencesConstants.PREFERENCE_GRID_COLUMNS, "-1"));
current = current == -1 ? 0 : current;
if (current != 0)
current = current - 1;
builder.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
sharedPref.edit().putString(PreferencesConstants.PREFERENCE_GRID_COLUMNS, "" + (which != 0 ? sort[which] : "" + -1)).commit();
dialog.dismiss();
return true;
}
});
builder.build().show();
return true;
case PreferencesConstants.FRAGMENT_THEME:
sort = getResources().getStringArray(R.array.theme);
current = Integer.parseInt(sharedPref.getString(PreferencesConstants.FRAGMENT_THEME, "0"));
builder = new MaterialDialog.Builder(getActivity());
// builder.theme(utilsProvider.getAppTheme().getMaterialDialogTheme());
builder.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
utilsProvider.getThemeManager().setAppTheme(AppTheme.getTheme(which));
dialog.dismiss();
restartPC(getActivity());
return true;
}
});
builder.title(R.string.theme);
builder.build().show();
return true;
case PreferencesConstants.FRAGMENT_FEEDBACK:
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "vishalmeham2@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback : Amaze File Manager");
PackageManager packageManager = getActivity().getPackageManager();
List activities = packageManager.queryIntentActivities(emailIntent, PackageManager.MATCH_DEFAULT_ONLY);
boolean isIntentSafe = activities.size() > 0;
if (isIntentSafe)
startActivity(Intent.createChooser(emailIntent, getResources().getString(feedback)));
else
Toast.makeText(getActivity(), getResources().getString(R.string.send_email_to) + " vishalmeham2@gmail.com", Toast.LENGTH_LONG).show();
return false;
case PreferencesConstants.FRAGMENT_ABOUT:
startActivity(new Intent(getActivity(), AboutActivity.class));
return false;
/*FROM HERE BE FRAGMENTS*/
case PreferencesConstants.FRAGMENT_COLORS:
((PreferencesActivity) getActivity()).selectItem(PreferencesActivity.COLORS_PREFERENCE);
return true;
case PreferencesConstants.FRAGMENT_FOLDERS:
((PreferencesActivity) getActivity()).selectItem(PreferencesActivity.FOLDERS_PREFERENCE);
return true;
case PreferencesConstants.FRAGMENT_QUICKACCESSES:
((PreferencesActivity) getActivity()).selectItem(PreferencesActivity.QUICKACCESS_PREFERENCE);
return true;
case PreferencesConstants.FRAGMENT_ADVANCED_SEARCH:
((PreferencesActivity) getActivity()).selectItem(PreferencesActivity.ADVANCEDSEARCH_PREFERENCE);
return true;
case PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD:
MaterialDialog.Builder masterPasswordDialogBuilder = new MaterialDialog.Builder(getActivity());
masterPasswordDialogBuilder.title(getResources().getString(R.string.crypt_pref_master_password_title));
String decryptedPassword = null;
try {
String preferencePassword = sharedPref.getString(PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD, PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD_DEFAULT);
if (!preferencePassword.equals(PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD_DEFAULT)) {
// password is set, try to decrypt
decryptedPassword = CryptUtil.decryptPassword(getActivity(), preferencePassword);
} else {
// no password set in preferences, just leave the field empty
decryptedPassword = "";
}
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
}
masterPasswordDialogBuilder.input(getResources().getString(R.string.authenticate_password), decryptedPassword, false, new MaterialDialog.InputCallback() {
@Override
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
}
});
masterPasswordDialogBuilder.theme(utilsProvider.getAppTheme().getMaterialDialogTheme());
masterPasswordDialogBuilder.positiveText(getResources().getString(R.string.ok));
masterPasswordDialogBuilder.negativeText(getResources().getString(R.string.cancel));
masterPasswordDialogBuilder.positiveColor(utilsProvider.getColorPreference().getColor(ColorUsage.ACCENT));
masterPasswordDialogBuilder.negativeColor(utilsProvider.getColorPreference().getColor(ColorUsage.ACCENT));
masterPasswordDialogBuilder.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
try {
String inputText = dialog.getInputEditText().getText().toString();
if (!inputText.equals(PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD_DEFAULT)) {
sharedPref.edit().putString(PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD, CryptUtil.encryptPassword(getActivity(), dialog.getInputEditText().getText().toString())).apply();
} else {
// empty password, remove the preference
sharedPref.edit().putString(PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD, "").apply();
}
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
sharedPref.edit().putString(PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD, PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD_DEFAULT).apply();
}
}
});
masterPasswordDialogBuilder.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.cancel();
}
});
masterPasswordDialogBuilder.build().show();
return true;
}
return false;
}
Aggregations