package com.x1unix.avi;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.SwitchPreference;
import android.view.MenuItem;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;


public class SettingsActivity extends AppCompatPreferenceActivity {

    private boolean propIsAdEnabled;
    private String propIsAdEnabledKey;
    private SharedPreferences preferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        propIsAdEnabledKey = getResources().getString(R.string.avi_prop_no_ads);

        getPrefs();
        setContentView(R.layout.activity_settings);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        addPreferencesFromResource(R.xml.pref_main);
        registerPropsEventHandlers();
    }

    private void registerPropsEventHandlers() {
        // Get the custom preference
        Preference customPref = (Preference) findPreference(propIsAdEnabledKey);
        customPref
                .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newVal) {
                        boolean switched = (boolean) newVal;
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putBoolean(propIsAdEnabledKey,
                                switched);
                        editor.apply();
                        return true;
                    }

                });
    }

    private void getPrefs() {
        // Get the xml/preferences.xml preferences
        preferences = PreferenceManager
                .getDefaultSharedPreferences(getBaseContext());
        propIsAdEnabled = preferences.getBoolean(propIsAdEnabledKey, true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

@@ -448,30 +448,108 @@
 ate 
-String propIsAdEnabled
+boolean propIsAutoupdate;%0A%0A    private String propIsAdEnabledKey;%0A    public String propIsAutoupdate
 Key;
@@ -788,16 +788,109 @@
 no_ads);
+%0A        propIsAutoupdateKey = getResources().getString(R.string.avi_prop_autocheck_updates);
 %0A%0A      
@@ -1301,33 +1301,16 @@
 stomPref
-%0A                
 .setOnPr
@@ -1332,16 +1332,300 @@
 istener(
+onTogglePreferenceListener);%0A%0A        Preference autoUpdatePref = (Preference) findPreference(propIsAutoupdateKey);%0A        autoUpdatePref.setOnPreferenceChangeListener(onTogglePreferenceListener);%0A    %7D%0A%0A    private Preference.OnPreferenceChangeListener onTogglePreferenceListener = 
 new Pref
@@ -1658,36 +1658,24 @@
 istener() %7B%0A
-            
         @Ove
@@ -1680,28 +1680,16 @@
 verride%0A
-            
         
@@ -1762,28 +1762,16 @@
 wVal) %7B%0A
-            
         
@@ -1823,28 +1823,16 @@
         
-           
- 
 SharedPr
@@ -1873,36 +1873,24 @@
 ces.edit();%0A
-            
             
@@ -1913,38 +1913,27 @@
 n(pr
-opIsAdEnabledKey,%0A            
+eference.getKey(),%0A
     
@@ -1971,28 +1971,16 @@
         
-    
-        
 editor.a
@@ -1995,36 +1995,24 @@
             
-     
-       
 return true;
@@ -2024,48 +2024,16 @@
     
-      
-      %7D%0A%0A                %7D);%0A    %7D
+%7D%0A    %7D;
 %0A%0A  
@@ -2287,24 +2287,102 @@
 Key, true);%0A
+        propIsAutoupdate = preferences.getBoolean(propIsAutoupdateKey, true);%0A
     %7D%0A%0A    @

Use autoupdate prop value from sterrings storage