use of com.keylesspalace.tusky.PreferencesActivity in project Tusky by tuskyapp.
the class PreferencesFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
accountManager = TuskyApplication.getInstance(getActivity()).getServiceLocator().get(AccountManager.class);
int preference = getArguments().getInt("preference");
addPreferencesFromResource(preference);
Preference notificationPreferences = findPreference("notificationPreferences");
if (notificationPreferences != null) {
AccountEntity activeAccount = accountManager.getActiveAccount();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O && activeAccount != null) {
notificationPreferences.setSummary(getString(R.string.pref_summary_notifications, activeAccount.getFullName()));
}
// on Android O and newer, launch the system notification settings instead of the app settings
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationPreferences.setOnPreferenceClickListener(pref -> {
Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.putExtra("android.provider.extra.APP_PACKAGE", BuildConfig.APPLICATION_ID);
startActivity(intent);
return true;
});
} else {
notificationPreferences.setOnPreferenceClickListener(pref -> {
PreferencesActivity activity = (PreferencesActivity) getActivity();
if (activity != null) {
activity.showFragment(R.xml.notification_preferences, R.string.pref_title_edit_notification_settings);
}
return true;
});
}
}
Preference timelineFilterPreferences = findPreference("timelineFilterPreferences");
if (timelineFilterPreferences != null) {
timelineFilterPreferences.setOnPreferenceClickListener(pref -> {
PreferencesActivity activity = (PreferencesActivity) getActivity();
if (activity != null) {
activity.showFragment(R.xml.timeline_filter_preferences, R.string.pref_title_status_tabs);
}
return true;
});
}
Preference httpProxyPreferences = findPreference("httpProxyPreferences");
if (httpProxyPreferences != null) {
httpProxyPreferences.setOnPreferenceClickListener(pref -> {
PreferencesActivity activity = (PreferencesActivity) getActivity();
if (activity != null) {
pendingRestart = false;
activity.showFragment(R.xml.http_proxy_preferences, R.string.pref_title_http_proxy_settings);
}
return true;
});
}
if (preference == R.xml.notification_preferences) {
AccountEntity activeAccount = accountManager.getActiveAccount();
if (activeAccount != null) {
CheckBoxPreference notificationPref = (CheckBoxPreference) findPreference("notificationsEnabled");
notificationPref.setChecked(activeAccount.getNotificationsEnabled());
CheckBoxPreference mentionedPref = (CheckBoxPreference) findPreference("notificationFilterMentions");
mentionedPref.setChecked(activeAccount.getNotificationsMentioned());
CheckBoxPreference followedPref = (CheckBoxPreference) findPreference("notificationFilterFollows");
followedPref.setChecked(activeAccount.getNotificationsFollowed());
CheckBoxPreference boostedPref = (CheckBoxPreference) findPreference("notificationFilterReblogs");
boostedPref.setChecked(activeAccount.getNotificationsReblogged());
CheckBoxPreference favoritedPref = (CheckBoxPreference) findPreference("notificationFilterFavourites");
favoritedPref.setChecked(activeAccount.getNotificationsFavorited());
CheckBoxPreference soundPref = (CheckBoxPreference) findPreference("notificationAlertSound");
soundPref.setChecked(activeAccount.getNotificationSound());
CheckBoxPreference vibrationPref = (CheckBoxPreference) findPreference("notificationAlertVibrate");
vibrationPref.setChecked(activeAccount.getNotificationVibration());
CheckBoxPreference lightPref = (CheckBoxPreference) findPreference("notificationAlertLight");
lightPref.setChecked(activeAccount.getNotificationLight());
}
}
}
Aggregations