SettingsNestedFragment.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package eu.kanade.mangafeed.ui.setting;
  2. import android.os.Bundle;
  3. import android.preference.PreferenceFragment;
  4. import eu.kanade.mangafeed.data.preference.PreferencesHelper;
  5. import eu.kanade.mangafeed.ui.base.activity.BaseActivity;
  6. public class SettingsNestedFragment extends PreferenceFragment {
  7. protected PreferencesHelper preferences;
  8. private static final String RESOURCE_FILE = "resource_file";
  9. private static final String TOOLBAR_TITLE = "toolbar_title";
  10. public static SettingsNestedFragment newInstance(int resourcePreference, int resourceTitle) {
  11. SettingsNestedFragment fragment = new SettingsNestedFragment();
  12. fragment.setBundle(resourcePreference, resourceTitle);
  13. return fragment;
  14. }
  15. @Override
  16. public void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. preferences = getSettingsActivity().preferences;
  19. addPreferencesFromResource(getArguments().getInt(RESOURCE_FILE));
  20. }
  21. @Override
  22. public void onResume() {
  23. super.onResume();
  24. ((BaseActivity) getActivity())
  25. .setToolbarTitle(getString(getArguments().getInt(TOOLBAR_TITLE)));
  26. }
  27. public void setBundle(int resourcePreference, int resourceTitle) {
  28. Bundle args = new Bundle();
  29. args.putInt(RESOURCE_FILE, resourcePreference);
  30. args.putInt(TOOLBAR_TITLE, resourceTitle);
  31. setArguments(args);
  32. }
  33. public SettingsActivity getSettingsActivity() {
  34. return (SettingsActivity) getActivity();
  35. }
  36. }