@Override protected void onDialogClosed(boolean positiveResult) { if (positiveResult) { persistInt(mValue); User user = ((CompassApplication) getContext().getApplicationContext()).getUser(); user.setDailyNotifications(mValue); HttpRequest.put(null, API.URL.putUserProfile(user), API.BODY.putUserProfile(user)); } else { mValue = parsePreference(getKey(), getContext()); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.notification_preferences); User user = ((CompassApplication) getActivity().getApplicationContext()).getUser(); Preference notificationNumber = findPreference(NUMBER_KEY); notificationNumber.setSummary(user.getDailyNotifications() + ""); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); preferences.registerOnSharedPreferenceChangeListener(this); }
@Override protected void showDialog(Bundle state) { super.showDialog(state); User user = ((CompassApplication) getContext().getApplicationContext()).getUser(); mValue = user.getDailyNotifications(); Dialog dialog = getDialog(); NumberPicker picker = (NumberPicker) dialog.findViewById(R.id.number_picker_picker); picker.setOnValueChangedListener(this); picker.setMinValue(0); picker.setMaxValue(20); picker.setValue(mValue); picker.setWrapSelectorWheel(false); }