package net.somethingdreadful.MAL;


import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;

import net.somethingdreadful.MAL.account.AccountService;

public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
    PrefManager Prefs;
    private Context context;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.settings);

        context = getActivity().getApplicationContext();
        Prefs = new PrefManager(context);
        PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(this);
    }


    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        String Auth = AccountService.getAuth();
        Bundle bundle = new Bundle();
        int interval = Prefs.getSyncTime() * 60;
        if (key.equals("synchronisation_time")) {
            ContentResolver.removePeriodicSync(AccountService.getAccount(context), Auth, bundle);
            ContentResolver.addPeriodicSync(AccountService.getAccount(context), Auth, bundle, interval);
        } else if (key.equals("synchronisation")) {
            if (Prefs.getSyncEnabled()) {
                ContentResolver.setSyncAutomatically(AccountService.getAccount(context), Auth, true);
                ContentResolver.addPeriodicSync(AccountService.getAccount(context), Auth, bundle, interval);
            } else {
                ContentResolver.removePeriodicSync(AccountService.getAccount(context), Auth, bundle);
                ContentResolver.setSyncAutomatically(AccountService.getAccount(context), Auth, false);
            }
        } else if (key.equals("locale")) {
            sharedPreferences.edit().commit();
            Intent Home = new Intent(context, Home.class);
            startActivity(Home);
            System.exit(0);
        }
    }
}

@@ -291,16 +291,86 @@
 Manager;
+%0Aimport android.util.Log;%0A%0Aimport com.crashlytics.android.Crashlytics;
 %0A%0Aimport
@@ -1082,24 +1082,42 @@
 ring key) %7B%0A
+        try %7B%0A    
         Stri
@@ -1160,16 +1160,20 @@
         
+    
 Bundle b
@@ -1190,24 +1190,28 @@
 w Bundle();%0A
+    
         int 
@@ -1251,24 +1251,28 @@
 60;%0A        
+    
 if (key.equa
@@ -1297,24 +1297,28 @@
 n_time%22)) %7B%0A
+    
             
@@ -1407,32 +1407,36 @@
 e);%0A            
+    
 ContentResolver.
@@ -1512,32 +1512,36 @@
 erval);%0A        
+    
 %7D else if (key.e
@@ -1576,24 +1576,28 @@
             
+ 
+   
 if (Prefs.ge
@@ -1610,24 +1610,28 @@
 nabled()) %7B%0A
+    
             
@@ -1728,32 +1728,36 @@
                 
+ 
+   
 ContentResolver.
@@ -1841,24 +1841,28 @@
             
+    
 %7D else %7B%0A   
@@ -1866,32 +1866,36 @@
                 
+ 
+   
 ContentResolver.
@@ -1956,32 +1956,36 @@
  Auth, bundle);%0A
+    
                 
@@ -2079,26 +2079,34 @@
             
+ 
-%7D%0A
+   %7D%0A    
         %7D el
@@ -2132,24 +2132,28 @@
 locale%22)) %7B%0A
+    
             
@@ -2203,22 +2203,26 @@
     
-Intent Home = 
+    startActivity(
 new 
@@ -2248,16 +2248,17 @@
 e.class)
+)
 ;%0A      
@@ -2267,54 +2267,185 @@
     
+    
-startActivity(Home);%0A            System.exit(0
+System.exit(0);%0A            %7D%0A        %7Dcatch (Exception e) %7B%0A            Crashlytics.log(Log.ERROR, %22MALX%22, %22SettingsFragment.onSharedPreferenceChanged(): %22 + e.getMessage()
 );%0A 

Fix preference crash after the user pressed quickly back (Settings)