From a83106f71743c42b3a9639f3c8a4d8bf8317b98e Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Mon, 22 Mar 2021 16:38:36 -0400 Subject: [PATCH] Clean up unnecessary onCreate in settings fragments --- .../settings/DebugSettingsFragment.java | 10 +-- .../settings/AppearanceSettingsFragment.java | 10 +-- .../settings/ContentSettingsFragment.java | 63 +++++++++---------- .../settings/DownloadSettingsFragment.java | 10 +-- .../settings/HistorySettingsFragment.java | 11 +--- .../settings/UpdateSettingsFragment.java | 10 +-- .../settings/VideoAudioSettingsFragment.java | 10 +-- 7 files changed, 42 insertions(+), 82 deletions(-) diff --git a/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index 7e2ff69b8..d5d223ff2 100644 --- a/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -2,7 +2,6 @@ package org.schabi.newpipe.settings; import android.os.Bundle; -import androidx.annotation.Nullable; import androidx.preference.Preference; import org.schabi.newpipe.R; @@ -11,8 +10,8 @@ import leakcanary.LeakCanary; public class DebugSettingsFragment extends BasePreferenceFragment { @Override - public void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { + addPreferencesFromResource(R.xml.debug_settings); final Preference showMemoryLeaksPreference = findPreference(getString(R.string.show_memory_leaks_key)); @@ -31,9 +30,4 @@ public class DebugSettingsFragment extends BasePreferenceFragment { throw new RuntimeException(); }); } - - @Override - public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { - addPreferencesFromResource(R.xml.debug_settings); - } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java index e2ac2c20d..fe89f62a0 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java @@ -7,7 +7,6 @@ import android.os.Bundle; import android.provider.Settings; import android.widget.Toast; -import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; import androidx.preference.Preference; @@ -21,8 +20,8 @@ public class AppearanceSettingsFragment extends BasePreferenceFragment { private String captionSettingsKey; @Override - public void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { + addPreferencesFromResource(R.xml.appearance_settings); final String themeKey = getString(R.string.theme_key); // the key of the active theme when settings were opened (or recreated after theme change) @@ -58,11 +57,6 @@ public class AppearanceSettingsFragment extends BasePreferenceFragment { } } - @Override - public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { - addPreferencesFromResource(R.xml.appearance_settings); - } - @Override public boolean onPreferenceTreeClick(final Preference preference) { if (preference.getKey().equals(captionSettingsKey) && CAPTIONING_SETTINGS_ACCESSIBLE) { diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index dbe05bbd2..ad8400401 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -10,7 +10,6 @@ import android.util.Log; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.preference.Preference; import androidx.preference.PreferenceManager; @@ -50,8 +49,35 @@ public class ContentSettingsFragment extends BasePreferenceFragment { private String initialLanguage; @Override - public void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { + final File homeDir = ContextCompat.getDataDir(requireContext()); + manager = new ContentSettingsManager(new NewPipeFileLocator(homeDir)); + manager.deleteSettingsFile(); + + addPreferencesFromResource(R.xml.content_settings); + + final Preference importDataPreference = findPreference(getString(R.string.import_data)); + importDataPreference.setOnPreferenceClickListener(p -> { + final Intent i = new Intent(getActivity(), FilePickerActivityHelper.class) + .putExtra(FilePickerActivityHelper.EXTRA_ALLOW_MULTIPLE, false) + .putExtra(FilePickerActivityHelper.EXTRA_ALLOW_CREATE_DIR, false) + .putExtra(FilePickerActivityHelper.EXTRA_MODE, + FilePickerActivityHelper.MODE_FILE); + startActivityForResult(i, REQUEST_IMPORT_PATH); + return true; + }); + + final Preference exportDataPreference = findPreference(getString(R.string.export_data)); + exportDataPreference.setOnPreferenceClickListener(p -> { + final Intent i = new Intent(getActivity(), FilePickerActivityHelper.class) + .putExtra(FilePickerActivityHelper.EXTRA_ALLOW_MULTIPLE, false) + .putExtra(FilePickerActivityHelper.EXTRA_ALLOW_CREATE_DIR, true) + .putExtra(FilePickerActivityHelper.EXTRA_MODE, + FilePickerActivityHelper.MODE_DIR); + startActivityForResult(i, REQUEST_EXPORT_PATH); + return true; + }); + thumbnailLoadToggleKey = getString(R.string.download_thumbnail_key); youtubeRestrictedModeEnabledKey = getString(R.string.youtube_restricted_mode_enabled); @@ -103,37 +129,6 @@ public class ContentSettingsFragment extends BasePreferenceFragment { return super.onPreferenceTreeClick(preference); } - @Override - public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { - final File homeDir = ContextCompat.getDataDir(requireContext()); - manager = new ContentSettingsManager(new NewPipeFileLocator(homeDir)); - manager.deleteSettingsFile(); - - addPreferencesFromResource(R.xml.content_settings); - - final Preference importDataPreference = findPreference(getString(R.string.import_data)); - importDataPreference.setOnPreferenceClickListener(p -> { - final Intent i = new Intent(getActivity(), FilePickerActivityHelper.class) - .putExtra(FilePickerActivityHelper.EXTRA_ALLOW_MULTIPLE, false) - .putExtra(FilePickerActivityHelper.EXTRA_ALLOW_CREATE_DIR, false) - .putExtra(FilePickerActivityHelper.EXTRA_MODE, - FilePickerActivityHelper.MODE_FILE); - startActivityForResult(i, REQUEST_IMPORT_PATH); - return true; - }); - - final Preference exportDataPreference = findPreference(getString(R.string.export_data)); - exportDataPreference.setOnPreferenceClickListener(p -> { - final Intent i = new Intent(getActivity(), FilePickerActivityHelper.class) - .putExtra(FilePickerActivityHelper.EXTRA_ALLOW_MULTIPLE, false) - .putExtra(FilePickerActivityHelper.EXTRA_ALLOW_CREATE_DIR, true) - .putExtra(FilePickerActivityHelper.EXTRA_MODE, - FilePickerActivityHelper.MODE_DIR); - startActivityForResult(i, REQUEST_EXPORT_PATH); - return true; - }); - } - @Override public void onDestroy() { super.onDestroy(); diff --git a/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java index 8742f0937..abd543643 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java @@ -11,7 +11,6 @@ import android.os.Bundle; import android.util.Log; import android.widget.Toast; -import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.preference.Preference; @@ -46,8 +45,8 @@ public class DownloadSettingsFragment extends BasePreferenceFragment { private Context ctx; @Override - public void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { + addPreferencesFromResource(R.xml.download_settings); downloadPathVideoPreference = getString(R.string.download_path_video_key); downloadPathAudioPreference = getString(R.string.download_path_audio_key); @@ -76,11 +75,6 @@ public class DownloadSettingsFragment extends BasePreferenceFragment { }); } - @Override - public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { - addPreferencesFromResource(R.xml.download_settings); - } - @Override public void onAttach(final Context context) { super.onAttach(context); diff --git a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java index 89fabbdde..cb6ce263d 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java @@ -5,7 +5,6 @@ import android.os.Bundle; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.preference.Preference; @@ -29,8 +28,9 @@ public class HistorySettingsFragment extends BasePreferenceFragment { private CompositeDisposable disposables; @Override - public void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { + addPreferencesFromResource(R.xml.history_settings); + cacheWipeKey = getString(R.string.metadata_cache_wipe_key); viewsHistoryClearKey = getString(R.string.clear_views_history_key); playbackStatesClearKey = getString(R.string.clear_playback_states_key); @@ -39,11 +39,6 @@ public class HistorySettingsFragment extends BasePreferenceFragment { disposables = new CompositeDisposable(); } - @Override - public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { - addPreferencesFromResource(R.xml.history_settings); - } - @Override public boolean onPreferenceTreeClick(final Preference preference) { if (preference.getKey().equals(cacheWipeKey)) { diff --git a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java index f25b25df2..0ca15e245 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java @@ -2,7 +2,6 @@ package org.schabi.newpipe.settings; import android.os.Bundle; -import androidx.annotation.Nullable; import androidx.preference.Preference; import org.schabi.newpipe.R; @@ -16,15 +15,10 @@ public class UpdateSettingsFragment extends BasePreferenceFragment { }; @Override - public void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { + addPreferencesFromResource(R.xml.update_settings); final String updateToggleKey = getString(R.string.update_app_key); findPreference(updateToggleKey).setOnPreferenceChangeListener(updatePreferenceChange); } - - @Override - public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { - addPreferencesFromResource(R.xml.update_settings); - } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java index 5eca99822..c0d274fe0 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java @@ -8,7 +8,6 @@ import android.provider.Settings; import android.text.format.DateUtils; import android.widget.Toast; -import androidx.annotation.Nullable; import androidx.preference.ListPreference; import com.google.android.material.snackbar.Snackbar; @@ -23,8 +22,8 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { private SharedPreferences.OnSharedPreferenceChangeListener listener; @Override - public void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { + addPreferencesFromResource(R.xml.video_audio_settings); updateSeekOptions(); @@ -104,11 +103,6 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { } } - @Override - public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { - addPreferencesFromResource(R.xml.video_audio_settings); - } - @Override public void onResume() { super.onResume();