use of ar.rulosoft.custompref.SeekBarCustomPreference in project MiMangaNu by raulhaag.
the class PreferencesFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.fragment_preferences);
ColorListDialogPref primaryColor = (ColorListDialogPref) getPreferenceManager().findPreference("primario");
primaryColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
((MainActivity) getActivity()).setColorToBars();
return false;
}
});
PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("account");
ServerBase[] servers = ServerBase.getServers(getContext());
for (final ServerBase sb : servers) {
if (sb.needLogin()) {
SwitchPreferenceCompat preference = new SwitchPreferenceCompat(getContext());
preference.setTitle(sb.getServerName());
preference.setSelectable(true);
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
new LoginDialog(getContext(), sb).show();
return false;
}
});
preferenceGroup.addPreference(preference);
}
}
/* Once, create necessary Data */
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
final String current_filepath = prefs.getString("directorio", Environment.getExternalStorageDirectory().getAbsolutePath()) + "/MiMangaNu/";
/* This enables to hide downloaded images from gallery, just a toggle */
final SwitchPreferenceCompat cBoxPref = (SwitchPreferenceCompat) getPreferenceManager().findPreference("mostrar_en_galeria");
// actuate the switch based on the existence of the .nomedia file
final File noMedia = new File(current_filepath, ".nomedia");
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
cBoxPref.setChecked(noMedia.exists());
} else {
cBoxPref.setEnabled(false);
}
cBoxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// reject change event in case the external storage is not available
if (!android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
return false;
}
try {
if ((Boolean) newValue) {
if (!noMedia.createNewFile()) {
Log.w("PF", "failed to create .nomedia file");
}
} else {
if (!noMedia.delete()) {
Log.w("PF", "failed to delete .nomedia file");
}
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
});
/* Set summary for Reader preference + seamless chapter transitions summary */
// true: Paged Reader; false: Continuous Reader
Boolean readType = prefs.getBoolean("reader_type", false);
Preference reader_type = getPreferenceManager().findPreference("reader_type");
Preference seamlessChapterTransitionsPref = getPreferenceManager().findPreference("seamless_chapter_transitions");
if (readType) {
reader_type.setTitle(getString(R.string.paged_reader));
seamlessChapterTransitionsPref.setSummary(getString(R.string.seamless_chapter_transitions_paged_reader_subtitle));
} else {
reader_type.setTitle(getString(R.string.continuous_reader));
seamlessChapterTransitionsPref.setSummary(getString(R.string.seamless_chapter_transitions_continuous_reader_subtitle));
}
final SwitchPreferenceCompat readerTypePref = (SwitchPreferenceCompat) getPreferenceManager().findPreference("reader_type");
readerTypePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
Boolean readType = prefs.getBoolean("reader_type", false);
Preference reader_type = getPreferenceManager().findPreference("reader_type");
Preference seamlessChapterTransitions = getPreferenceManager().findPreference("seamless_chapter_transitions");
if (!readType) {
reader_type.setTitle(getString(R.string.paged_reader));
seamlessChapterTransitions.setSummary(getString(R.string.seamless_chapter_transitions_paged_reader_subtitle));
} else {
reader_type.setTitle(getString(R.string.continuous_reader));
seamlessChapterTransitions.setSummary(getString(R.string.seamless_chapter_transitions_continuous_reader_subtitle));
}
return true;
}
});
/* enable / disable seamless_chapter_transitions_delete_read depending on the state of seamless_chapter_transitions */
Preference seamlessChapterTransitionsDeleteReadPreference = getPreferenceManager().findPreference("seamless_chapter_transitions_delete_read");
if (prefs.getBoolean("seamless_chapter_transitions", false)) {
seamlessChapterTransitionsDeleteReadPreference.setEnabled(true);
} else {
seamlessChapterTransitionsDeleteReadPreference.setEnabled(false);
}
final SwitchPreferenceCompat seamlessChapterTransitionsSPC = (SwitchPreferenceCompat) getPreferenceManager().findPreference("seamless_chapter_transitions");
seamlessChapterTransitionsSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
Preference seamlessChapterTransitionsDeleteReadPreference = getPreferenceManager().findPreference("seamless_chapter_transitions_delete_read");
if (!prefs.getBoolean("seamless_chapter_transitions", false)) {
seamlessChapterTransitionsDeleteReadPreference.setEnabled(true);
} else {
seamlessChapterTransitionsDeleteReadPreference.setEnabled(false);
SharedPreferences.Editor prefEdit = prefs.edit();
prefEdit.putBoolean("seamless_chapter_transitions_delete_read", false);
prefEdit.apply();
}
return true;
}
});
/* enable / disable auto_import_path depending on the state of auto_import */
Preference autoImportPath = getPreferenceManager().findPreference("auto_import_path");
if (prefs.getBoolean("auto_import", false)) {
autoImportPath.setEnabled(true);
} else {
autoImportPath.setEnabled(false);
}
final SwitchPreferenceCompat autoImportSPC = (SwitchPreferenceCompat) getPreferenceManager().findPreference("auto_import");
autoImportSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
Preference autoImportPath = getPreferenceManager().findPreference("auto_import_path");
if (!prefs.getBoolean("auto_import", false)) {
autoImportPath.setEnabled(true);
} else {
autoImportPath.setEnabled(false);
}
return true;
}
});
/* This sets the download threads (parallel downloads) */
final SeekBarCustomPreference listPreferenceDT = (SeekBarCustomPreference) getPreferenceManager().findPreference("download_threads");
listPreferenceDT.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int threads = (int) newValue;
int antes = DownloadPoolService.SLOTS;
DownloadPoolService.SLOTS = threads;
if (DownloadPoolService.actual != null)
DownloadPoolService.actual.slots += (threads - antes);
return true;
}
});
/* This sets the maximum number of errors to tolerate */
final SeekBarCustomPreference listPrefET = (SeekBarCustomPreference) getPreferenceManager().findPreference("error_tolerancia");
listPrefET.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ChapterDownload.MAX_ERRORS = (int) newValue;
return true;
}
});
/* This sets the number of retries to fetch images */
SeekBarCustomPreference listPrefRT = (SeekBarCustomPreference) getPreferenceManager().findPreference("reintentos");
listPrefRT.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
SingleDownload.RETRY = (int) newValue;
return true;
}
});
/* This sets the Update Interval of the mangas (i.e. once per week) */
final ListPreference listPrefCU = (ListPreference) getPreferenceManager().findPreference("update_interval");
listPrefCU.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
long time = Long.parseLong((String) newValue);
JobManager.instance().cancelAllForTag(UpdateJobCreator.UPDATE_TAG);
if (time > 0) {
new JobRequest.Builder(UpdateJobCreator.UPDATE_TAG).setPeriodic(time, TimeUnit.MINUTES.toMillis(5)).setRequiresCharging(false).setRequiresDeviceIdle(false).setUpdateCurrent(true).build().schedule();
}
if (time < 0)
MainActivity.coldStart = false;
return true;
}
});
/* This is for Custom language selection */
final ListPreference listPrefBatotoLang = (ListPreference) getPreferenceManager().findPreference("batoto_lang_selection");
listPrefBatotoLang.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue.equals("Custom")) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = inflater.inflate(R.layout.simple_input_dialog, null);
final EditText CustomLang = (EditText) rootView.findViewById(R.id.txtCustomLang);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
dialogBuilder.setTitle(getString(R.string.custom_language));
dialogBuilder.setView(rootView);
dialogBuilder.setPositiveButton("Ok", null);
dialogBuilder.setNegativeButton(getString(R.string.cancel), null);
AlertDialog dialog = dialogBuilder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(final DialogInterface dialog) {
Button accept = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
prefs.edit().putString("batoto_custom_lang", CustomLang.getText().toString()).apply();
Util.getInstance().toast(getContext(), getString(R.string.custom_language) + ": " + CustomLang.getText().toString());
dialog.dismiss();
}
});
}
});
dialog.show();
}
return true;
}
});
/* This sets the Version Number, that's all */
final Preference prefAbout = getPreferenceManager().findPreference("about_text");
prefAbout.setSummary("v" + BuildConfig.VERSION_NAME);
/* This will check how much storage is taken by the mangas */
new calcStorage().execute(current_filepath);
final Preference prefLicense = getPreferenceManager().findPreference("license_view");
prefLicense.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
((MainActivity) getActivity()).replaceFragment(new LicenseFragment(), "licence_fragment");
return false;
}
});
final SwitchPreferenceCompat onlyWifiUpdateSwitch = (SwitchPreferenceCompat) getPreferenceManager().findPreference("update_only_wifi");
SwitchPreferenceCompat onlyWifiSwitch = (SwitchPreferenceCompat) getPreferenceManager().findPreference("only_wifi");
onlyWifiSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
NetworkUtilsAndReceiver.ONLY_WIFI = (Boolean) o;
NetworkUtilsAndReceiver.connectionStatus = NetworkUtilsAndReceiver.ConnectionStatus.UNCHECKED;
onlyWifiUpdateSwitch.setEnabled(!(Boolean) o);
return true;
}
});
if (onlyWifiSwitch.isChecked()) {
onlyWifiUpdateSwitch.setEnabled(false);
} else {
onlyWifiUpdateSwitch.setEnabled(true);
}
final SeekBarCustomPreference seekBarConnectionRetry = (SeekBarCustomPreference) getPreferenceManager().findPreference("connection_retry");
seekBarConnectionRetry.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Navigator.connectionRetry = Integer.parseInt(prefs.getString("connection_retry", "10"));
return true;
}
});
final SeekBarCustomPreference seekBarConnectionTimeout = (SeekBarCustomPreference) getPreferenceManager().findPreference("connection_timeout");
seekBarConnectionTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Navigator.connectionTimeout = Integer.parseInt(prefs.getString("connection_timeout", "10"));
return true;
}
});
final SeekBarCustomPreference seekBarWriteTimeout = (SeekBarCustomPreference) getPreferenceManager().findPreference("write_timeout");
seekBarWriteTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Navigator.writeTimeout = Integer.parseInt(prefs.getString("write_timeout", "10"));
return true;
}
});
final SeekBarCustomPreference seekBarReadTimeout = (SeekBarCustomPreference) getPreferenceManager().findPreference("read_timeout");
seekBarReadTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Navigator.readTimeout = Integer.parseInt(prefs.getString("read_timeout", "30"));
return true;
}
});
Preference gridColumnsPref = getPreferenceManager().findPreference("grid_columns");
if (prefs.getBoolean("grid_columns_automatic_detection", true)) {
gridColumnsPref.setEnabled(false);
} else {
gridColumnsPref.setEnabled(true);
}
final SwitchPreferenceCompat gridColumnsAutomaticDetectionSPC = (SwitchPreferenceCompat) getPreferenceManager().findPreference("grid_columns_automatic_detection");
gridColumnsAutomaticDetectionSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
Preference gridColumns = getPreferenceManager().findPreference("grid_columns");
if (prefs.getBoolean("grid_columns_automatic_detection", true)) {
gridColumns.setEnabled(true);
} else {
gridColumns.setEnabled(false);
}
return true;
}
});
final Preference prefClearCache = getPreferenceManager().findPreference("clear_cache");
prefClearCache.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Preference clearCache = getPreferenceManager().findPreference("clear_cache");
clearCache.setEnabled(false);
Thread t0 = new Thread(new Runnable() {
@Override
public void run() {
new FileCache(getActivity()).clearCache();
}
});
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
Util.getInstance().createNotificationWithProgressbar(getContext(), 69, getString(R.string.deleting_empty_directories), "");
Util.getInstance().deleteEmptyDirectoriesRecursive(new File(current_filepath));
Util.getInstance().cancelNotification(69);
}
});
t0.start();
t1.start();
return true;
}
});
final Preference prefClearSpecificCookies = getPreferenceManager().findPreference("clear_specific_cookies");
prefClearSpecificCookies.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Preference clearSpecificCookies = getPreferenceManager().findPreference("clear_specific_cookies");
clearSpecificCookies.setEnabled(false);
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = inflater.inflate(R.layout.simple_input_dialog, null);
final EditText SpecificCookiesToClear = (EditText) rootView.findViewById(R.id.txtCustomLang);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
dialogBuilder.setTitle("Cookies to clear contain");
dialogBuilder.setView(rootView);
dialogBuilder.setPositiveButton("Ok", null);
dialogBuilder.setNegativeButton(getString(R.string.cancel), null);
AlertDialog dialog = dialogBuilder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(final DialogInterface dialog) {
Button accept = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Thread t0 = new Thread(new Runnable() {
@Override
public void run() {
Util.getInstance().removeSpecificCookies(getContext(), SpecificCookiesToClear.getText().toString());
}
});
t0.start();
dialog.dismiss();
}
});
Button cancel = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
}
});
dialog.show();
return true;
}
});
final Preference prefClearAllCookies = getPreferenceManager().findPreference("clear_all_cookies");
prefClearAllCookies.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Preference clearAllCookies = getPreferenceManager().findPreference("clear_all_cookies");
clearAllCookies.setEnabled(false);
Thread t0 = new Thread(new Runnable() {
@Override
public void run() {
Util.getInstance().removeAllCookies(getContext());
}
});
t0.start();
return true;
}
});
final Preference prefResetServersToDefaults = getPreferenceManager().findPreference("reset_server_list_to_defaults");
prefResetServersToDefaults.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Preference resetServerListToDefaults = getPreferenceManager().findPreference("reset_server_list_to_defaults");
resetServerListToDefaults.setEnabled(false);
prefs.edit().putString("unused_servers", "").apply();
return true;
}
});
final Preference prefVacuumDatabase = getPreferenceManager().findPreference("vacuum_database");
prefVacuumDatabase.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Preference vacuumDatabase = getPreferenceManager().findPreference("vacuum_database");
vacuumDatabase.setEnabled(false);
Thread t0 = new Thread(new Runnable() {
@Override
public void run() {
Util.getInstance().createNotificationWithProgressbar(getContext(), 70, getString(R.string.vacuum_database_notification_text), "");
Database.vacuumDatabase(getContext());
Util.getInstance().cancelNotification(70);
}
});
t0.start();
return true;
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
getPreferenceManager().findPreference("update_sound").setVisible(false);
getPreferenceManager().findPreference("update_vibrate").setVisible(false);
getPreferenceManager().findPreference("update_notif_options").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_CHANNEL_ID, Util.channelIdNews);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
startActivity(intent);
return true;
}
});
} else {
getPreferenceManager().findPreference("update_notif_options").setVisible(false);
}
setFirstRunDefaults();
}
use of ar.rulosoft.custompref.SeekBarCustomPreference in project MiMangaNu by raulhaag.
the class PreferencesFragment method setNumberOfThreadsToBeEqualToNumberOfCores.
private void setNumberOfThreadsToBeEqualToNumberOfCores(int threadsMax, String preference) {
int threads, availableProcessors = Runtime.getRuntime().availableProcessors();
if (availableProcessors <= threadsMax) {
threads = availableProcessors;
} else {
threads = threadsMax;
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = preferences.edit();
editor.putString(preference, "" + threads).apply();
final SeekBarCustomPreference tmpSeekBar = (SeekBarCustomPreference) getPreferenceManager().findPreference(preference);
tmpSeekBar.setProgress(threads);
}
Aggregations