Mholloway has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/360861 )
Change subject: Hygiene: Update SettingsPreferenceLoader listeners ...................................................................... Hygiene: Update SettingsPreferenceLoader listeners * Make all private classes rather than one-time-use variables * Make all static classes Change-Id: I43a85502fe8d9f2d34658312f0576f23bc0798af --- M app/src/main/java/org/wikipedia/settings/SettingsPreferenceLoader.java 1 file changed, 19 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/61/360861/1 diff --git a/app/src/main/java/org/wikipedia/settings/SettingsPreferenceLoader.java b/app/src/main/java/org/wikipedia/settings/SettingsPreferenceLoader.java index 78422c0..eba12a4 100644 --- a/app/src/main/java/org/wikipedia/settings/SettingsPreferenceLoader.java +++ b/app/src/main/java/org/wikipedia/settings/SettingsPreferenceLoader.java @@ -1,5 +1,6 @@ package org.wikipedia.settings; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.support.annotation.NonNull; @@ -38,14 +39,14 @@ loadPreferences(R.xml.preferences_zero); findPreference(R.string.preference_key_zero_interstitial) - .setOnPreferenceChangeListener(showZeroInterstitialListener); + .setOnPreferenceChangeListener(new ShowZeroInterstitialListener()); } findPreference(R.string.preference_key_sync_reading_lists) - .setOnPreferenceChangeListener(syncReadingListsListener); + .setOnPreferenceChangeListener(new SyncReadingListsListener(getActivity())); findPreference(R.string.preference_key_color_theme) - .setOnPreferenceChangeListener(themeChangeListener); + .setOnPreferenceChangeListener(new ThemeChangeListener()); loadPreferences(R.xml.preferences_about); @@ -104,19 +105,22 @@ languagePref.setSummary(WikipediaApp.getInstance().getAppOrSystemLanguageLocalizedName()); } - private Preference.OnPreferenceChangeListener showZeroInterstitialListener - = new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { + private static class ShowZeroInterstitialListener implements Preference.OnPreferenceChangeListener { + @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue == Boolean.FALSE) { WikipediaApp.getInstance().getWikipediaZeroHandler().getZeroFunnel().logExtLinkAlways(); } return true; } - }; + } - private Preference.OnPreferenceChangeListener syncReadingListsListener - = new Preference.OnPreferenceChangeListener() { + private static final class SyncReadingListsListener implements Preference.OnPreferenceChangeListener { + private Context context; + + private SyncReadingListsListener(Context context) { + this.context = context; + } + @Override public boolean onPreferenceChange(final Preference preference, Object newValue) { final ReadingListSynchronizer synchronizer = ReadingListSynchronizer.instance(); if (newValue == Boolean.TRUE) { @@ -124,7 +128,7 @@ Prefs.setReadingListSyncEnabled(true); synchronizer.sync(); } else { - new AlertDialog.Builder(getActivity()) + new AlertDialog.Builder(context) .setMessage(R.string.reading_lists_confirm_remote_delete) .setPositiveButton(R.string.yes, new DeleteRemoteListsYesListener(preference, synchronizer)) .setNegativeButton(R.string.no, new DeleteRemoteListsNoListener(preference)) @@ -135,17 +139,16 @@ } }; - private Preference.OnPreferenceChangeListener themeChangeListener - = new Preference.OnPreferenceChangeListener() { + private static class ThemeChangeListener implements Preference.OnPreferenceChangeListener { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { WikipediaApp.getInstance().setCurrentTheme(Theme.ofMarshallingId((Integer) newValue)); // The setCurrentTheme call updates the nonvolatile Preference state and updates the UI // accordingly. Return false since the pref state is already updated by the method call. return false; } - }; + } - private final class DeleteRemoteListsYesListener implements DialogInterface.OnClickListener { + private static final class DeleteRemoteListsYesListener implements DialogInterface.OnClickListener { private Preference preference; private ReadingListSynchronizer synchronizer; @@ -162,7 +165,7 @@ } } - private final class DeleteRemoteListsNoListener implements DialogInterface.OnClickListener { + private static final class DeleteRemoteListsNoListener implements DialogInterface.OnClickListener { private Preference preference; private DeleteRemoteListsNoListener(Preference preference) { -- To view, visit https://gerrit.wikimedia.org/r/360861 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I43a85502fe8d9f2d34658312f0576f23bc0798af Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Mholloway <mhollo...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits