use of androidx.preference.ListPreference in project AntennaPod by AntennaPod.
the class PlaybackPreferencesFragment method buildSmartMarkAsPlayedPreference.
private void buildSmartMarkAsPlayedPreference() {
final Resources res = getActivity().getResources();
ListPreference pref = findPreference(UserPreferences.PREF_SMART_MARK_AS_PLAYED_SECS);
String[] values = res.getStringArray(R.array.smart_mark_as_played_values);
String[] entries = new String[values.length];
for (int x = 0; x < values.length; x++) {
if (x == 0) {
entries[x] = res.getString(R.string.pref_smart_mark_as_played_disabled);
} else {
int v = Integer.parseInt(values[x]);
if (v < 60) {
entries[x] = res.getQuantityString(R.plurals.time_seconds_quantified, v, v);
} else {
v /= 60;
entries[x] = res.getQuantityString(R.plurals.time_minutes_quantified, v, v);
}
}
}
pref.setEntries(entries);
}
use of androidx.preference.ListPreference in project AntennaPod by AntennaPod.
the class PlaybackPreferencesFragment method setupPlaybackScreen.
private void setupPlaybackScreen() {
final Activity activity = getActivity();
findPreference(PREF_PLAYBACK_SPEED_LAUNCHER).setOnPreferenceClickListener(preference -> {
new VariableSpeedDialog().show(getChildFragmentManager(), null);
return true;
});
findPreference(PREF_PLAYBACK_REWIND_DELTA_LAUNCHER).setOnPreferenceClickListener(preference -> {
SkipPreferenceDialog.showSkipPreference(activity, SkipPreferenceDialog.SkipDirection.SKIP_REWIND, null);
return true;
});
findPreference(PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER).setOnPreferenceClickListener(preference -> {
SkipPreferenceDialog.showSkipPreference(activity, SkipPreferenceDialog.SkipDirection.SKIP_FORWARD, null);
return true;
});
if (!PictureInPictureUtil.supportsPictureInPicture(activity)) {
ListPreference behaviour = findPreference(UserPreferences.PREF_VIDEO_BEHAVIOR);
behaviour.setEntries(R.array.video_background_behavior_options_without_pip);
behaviour.setEntryValues(R.array.video_background_behavior_values_without_pip);
}
findPreference(PREF_PLAYBACK_PREFER_STREAMING).setOnPreferenceChangeListener((preference, newValue) -> {
// Update all visible lists to reflect new streaming action button
EventBus.getDefault().post(new UnreadItemsUpdateEvent());
UsageStatistics.askAgainLater(UsageStatistics.ACTION_STREAM);
return true;
});
buildEnqueueLocationPreference();
}
use of androidx.preference.ListPreference in project AntennaPod by AntennaPod.
the class AutoDownloadPreferencesFragment method buildEpisodeCleanupPreference.
private void buildEpisodeCleanupPreference() {
final Resources res = getActivity().getResources();
ListPreference pref = findPreference(UserPreferences.PREF_EPISODE_CLEANUP);
String[] values = res.getStringArray(R.array.episode_cleanup_values);
String[] entries = new String[values.length];
for (int x = 0; x < values.length; x++) {
int v = Integer.parseInt(values[x]);
if (v == UserPreferences.EPISODE_CLEANUP_EXCEPT_FAVORITE) {
entries[x] = res.getString(R.string.episode_cleanup_except_favorite_removal);
} else if (v == UserPreferences.EPISODE_CLEANUP_QUEUE) {
entries[x] = res.getString(R.string.episode_cleanup_queue_removal);
} else if (v == UserPreferences.EPISODE_CLEANUP_NULL) {
entries[x] = res.getString(R.string.episode_cleanup_never);
} else if (v == 0) {
entries[x] = res.getString(R.string.episode_cleanup_after_listening);
} else if (v > 0 && v < 24) {
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_hours_after_listening, v, v);
} else {
// assume underlying value will be NOT fraction of days, e.g., 36 (hours)
int numDays = v / 24;
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, numDays, numDays);
}
}
pref.setEntries(entries);
}
use of androidx.preference.ListPreference in project IITB-App by wncc.
the class SettingsFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences, rootKey);
// Get preferences and editor
SharedPreferences sharedPref = getActivity().getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
editor = sharedPref.edit();
// Show contact number
showContactPref = (SwitchPreferenceCompat) findPreference("show_contact");
showContactPref.setOnPreferenceChangeListener((preference, option) -> {
toggleShowContact((SwitchPreferenceCompat) preference, option);
return false;
});
showContactPref.setEnabled(false);
// Dark Theme
SwitchPreferenceCompat darkThemePref = (SwitchPreferenceCompat) findPreference("dark_theme");
darkThemePref.setOnPreferenceChangeListener((preference, option) -> {
toggleDarkTheme((boolean) option);
return true;
});
darkThemePref.setChecked(sharedPref.getBoolean(Constants.DARK_THEME, false));
// Add to Calendar
ListPreference calendarPref = (ListPreference) findPreference("add_to_calendar");
calendarPref.setOnPreferenceChangeListener((preference, option) -> {
toggleCalendarDialog((String) option);
return true;
});
calendarPref.setValue(sharedPref.getString(Constants.CALENDAR_DIALOG, Constants.CALENDAR_DIALOG_ALWAYS_ASK));
// Update Profile
Preference profilePref = findPreference("profile");
profilePref.setOnPreferenceClickListener(preference -> {
openWebURL("https://gymkhana.iitb.ac.in/sso/user");
return false;
});
// Feedback
Preference feedbackPref = findPreference("feedback");
feedbackPref.setOnPreferenceClickListener(preference -> {
openWebURL("https://www.insti.app/feedback");
return false;
});
// About
Preference aboutPref = findPreference("about");
aboutPref.setOnPreferenceClickListener(preference -> {
openAbout();
return false;
});
// Logout
Preference logoutPref = findPreference("logout");
logoutPref.setOnPreferenceClickListener(preference -> {
logout();
return false;
});
// Disable buttons if not logged in
final SessionManager sessionManager = new SessionManager(getContext());
if (!sessionManager.isLoggedIn()) {
showContactPref.setVisible(false);
logoutPref.setVisible(false);
}
}
use of androidx.preference.ListPreference in project twicalico by moko256.
the class SettingsFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
setPreferencesFromResource(R.xml.settings, rootKey);
if (rootKey == null) {
AccountsModel accountsModel = GlobalApplicationKt.getAccountsModel(requireActivity());
List<AccessToken> accessTokens = accountsModel.getAccessTokens();
CharSequence[] entriesAccountList = new CharSequence[accessTokens.size() + 1];
CharSequence[] entryValues = new CharSequence[accessTokens.size() + 1];
for (int i = 0; i < accessTokens.size(); i++) {
AccessToken accessToken = accessTokens.get(i);
entriesAccountList[i] = TwitterStringUtils.plusAtMark(accessToken.getScreenName(), accessToken.getUrl());
entryValues[i] = accessToken.getKeyString();
}
entriesAccountList[entriesAccountList.length - 1] = getString(R.string.login_with_another_account);
entryValues[entryValues.length - 1] = "-1";
ListPreference nowAccountList = findPreference(KEY_ACCOUNT_KEY);
nowAccountList.setEntries(entriesAccountList);
nowAccountList.setEntryValues(entryValues);
nowAccountList.setDefaultValue(GlobalApplicationKt.preferenceRepository.getString(KEY_ACCOUNT_KEY, "-1"));
nowAccountList.setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue.equals("-1")) {
startActivityForResult(new Intent(getContext(), OAuthActivity.class), REQUEST_OAUTH_OR_CANCEL);
return false;
} else {
AccessToken accessToken = GlobalApplicationKt.getAccountsModel(requireActivity()).get((String) newValue);
((GlobalApplication) requireActivity().getApplication()).initCurrentClient(accessToken);
startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
return true;
}
});
List<AccessToken> accessTokensTwitter = accountsModel.getAccessTokensByType(CLIENT_TYPE_TWITTER);
CharSequence[] entriesLinkOpen = new CharSequence[accessTokensTwitter.size() + 1];
CharSequence[] entriesLinkOpenValue = new CharSequence[accessTokensTwitter.size() + 1];
for (int i = 0; i < accessTokensTwitter.size(); i++) {
AccessToken accessToken = accessTokensTwitter.get(i);
entriesLinkOpen[i] = TwitterStringUtils.plusAtMark(accessToken.getScreenName(), accessToken.getUrl());
entriesLinkOpenValue[i] = accessToken.getKeyString();
}
entriesLinkOpen[entriesLinkOpen.length - 1] = getString(R.string.not_set);
entriesLinkOpenValue[entriesLinkOpenValue.length - 1] = "-1";
ListPreference linkOpenAccountList = findPreference(KEY_ACCOUNT_KEY_LINK_OPEN);
linkOpenAccountList.setEntries(entriesLinkOpen);
linkOpenAccountList.setEntryValues(entriesLinkOpenValue);
linkOpenAccountList.setDefaultValue("-1");
findPreference("logout").setOnPreferenceClickListener(preference -> {
new AlertDialog.Builder(requireContext()).setMessage(R.string.confirm_logout).setCancelable(true).setPositiveButton(R.string.do_logout, (dialog, i) -> {
accountsModel.delete(accountsModel.get(GlobalApplicationKt.preferenceRepository.getString(KEY_ACCOUNT_KEY, "-1")));
int point = accountsModel.size() - 1;
if (point != -1) {
AccessToken accessToken = accountsModel.getAccessTokens().get(point);
GlobalApplicationKt.preferenceRepository.putString(KEY_ACCOUNT_KEY, accessToken.getKeyString());
((GlobalApplication) requireActivity().getApplication()).initCurrentClient(accessToken);
startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
} else {
GlobalApplicationKt.preferenceRepository.putString(KEY_ACCOUNT_KEY, "-1");
((GlobalApplication) requireActivity().getApplication()).clearCurrentClient();
startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
}
}).setNegativeButton(android.R.string.cancel, null).show();
return false;
});
ListPreference nowThemeMode = findPreference(KEY_NIGHT_MODE);
nowThemeMode.setOnPreferenceChangeListener((preference, newValue) -> {
AppCompatDelegate.setDefaultNightMode(ThemePreferenceConverterKt.convertToAppCompatNightThemeMode(String.valueOf(newValue)));
((AppCompatActivity) requireActivity()).getDelegate().applyDayNight();
return true;
});
Preference licenseThisApp = findPreference("license_at_this_app");
licenseThisApp.setOnPreferenceClickListener(preference -> {
requireContext().startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", getResources().getText(R.string.app_name)).putExtra("library_name", "twitlatte"));
return true;
});
Preference sourceCodeLink = findPreference("source_code_link");
sourceCodeLink.setOnPreferenceClickListener(preference -> {
AppCustomTabsKt.launchChromeCustomTabs(requireContext(), "https://github.com/moko256/twitlatte", false);
return true;
});
Preference version = findPreference("app_version");
version.setSummary(BuildConfig.VERSION_NAME);
version.setOnPreferenceClickListener(preference -> {
eggCount--;
if (eggCount <= 0) {
startActivity(new Intent(getActivity(), AboutActivity.class));
eggCount = 3;
}
return true;
});
} else if (rootKey.equals("regexMute")) {
PreferenceScreen regexMute = getPreferenceScreen();
for (int i = 0, length = regexMute.getPreferenceCount(); i < length; i++) {
Preference name = regexMute.getPreference(i);
if (name instanceof EditTextPreference) {
name.setOnPreferenceChangeListener((preference, newValue) -> {
try {
GlobalApplicationKt.preferenceRepository.updateRegex(preference.getKey(), (String) newValue);
} catch (PatternSyntaxException e) {
e.printStackTrace();
Toast.makeText(requireContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
return true;
});
}
}
} else if (rootKey.equals("license")) {
PreferenceScreen license = getPreferenceScreen();
for (int i = 0, length = license.getPreferenceCount(); i < length; i++) {
license.getPreference(i).setOnPreferenceClickListener(preference -> {
startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", preference.getTitle()).putExtra("library_name", // "license_lib_".length
preference.getKey().substring(12)));
return true;
});
}
} else if (rootKey.equals("contributors")) {
PreferenceScreen contributorCategory = getPreferenceScreen();
for (int c = 0, length = contributorCategory.getPreferenceCount(); c < length; c++) {
PreferenceCategory contributor = (PreferenceCategory) contributorCategory.getPreference(c);
for (int i = 0, l = contributor.getPreferenceCount(); i < l; i++) {
Preference name = contributor.getPreference(i);
String uri = "https://github.com/" + name.getKey();
name.setSummary(uri);
name.setOnPreferenceClickListener(preference -> {
AppCustomTabsKt.launchChromeCustomTabs(requireContext(), uri, false);
return true;
});
}
}
}
}
Aggregations