package com.omralcorut.guardiannews;

import android.content.SharedPreferences;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SettingsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
    }

    public static class NewsPreferenceFragment extends PreferenceFragment
        implements Preference.OnPreferenceChangeListener {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.settings_main);

            Preference section = findPreference(getString(R.string.settings_section_key));
            bindPreferenceSummaryToValue(section);
        }

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String stringValue = newValue.toString();
            preference.setSummary(stringValue);
            return true;
        }

        private void bindPreferenceSummaryToValue(Preference preference) {
            preference.setOnPreferenceChangeListener(this);
            SharedPreferences preferences =
                    PreferenceManager.getDefaultSharedPreferences(preference.getContext());
            String preferenceString = preferences.getString(preference.getKey(), "");
            onPreferenceChange(preference, preferenceString);
        }
    }
}

@@ -1218,16 +1218,35 @@
 Summary(
+getLabelGivenValue(
 stringVa
@@ -1249,16 +1249,17 @@
 ngValue)
+)
 ;%0A      
@@ -1645,16 +1645,16 @@
 ), %22%22);%0A
-
         
@@ -1716,16 +1716,479 @@
        %7D
+%0A%0A        private String getLabelGivenValue(String value) %7B%0A            String result = %22All Sections%22;%0A            String values%5B%5D = getResources().getStringArray(R.array.settings_section_values);%0A            for (int i = 0; i %3C values.length; i++) %7B%0A                if (value.equals(values%5Bi%5D)) %7B%0A                    result = getResources().getStringArray(R.array.settings_section_labels)%5Bi%5D;%0A                %7D%0A            %7D%0A            return result;%0A        %7D
 %0A    %7D%0A%7D

Fix section label issue in settings