package interdroid.vdb.persistence.ui;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import interdroid.vdb.R;

import android.os.Bundle;
import android.preference.PreferenceActivity;


public class VdbPreferences extends PreferenceActivity {
	private static final Logger logger = LoggerFactory
			.getLogger(VdbPreferences.class);


    public static final String PREFERENCES_NAME = "interdroid.vdb_preferences";

    // If you change these change the android:key value in vdb_preferences.xml
    public static final String PREF_SHARING_ENABLED = "sharingEnabled";
    public static final String PREF_NAME = "name";
    public static final String PREF_EMAIL = "email";

    // TODO: Add listener to synch toggle and start and stop service based on that.

	@Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.vdb_preferences);
            logger.debug("Storing preferences to: " + getPreferenceManager().getSharedPreferencesName());
    }
}

@@ -117,16 +117,58 @@
 vdb.R;%0A%0A
+import android.content.SharedPreferences;%0A
 import a
@@ -345,12 +345,8 @@
 tory
-%0A%09%09%09
 .get
@@ -376,21 +376,17 @@
 lass);%0A%0A
-%0A    
+%09
 public s
@@ -454,20 +454,17 @@
 nces%22;%0A%0A
-    
+%09
 // If yo
@@ -530,20 +530,17 @@
 ces.xml%0A
-    
+%09
 public s
@@ -599,20 +599,17 @@
 abled%22;%0A
-    
+%09
 public s
@@ -647,20 +647,17 @@
 %22name%22;%0A
-    
+%09
 public s
@@ -698,20 +698,17 @@
 mail%22;%0A%0A
-    
+%09
 // TODO:
@@ -791,20 +791,17 @@
 verride%0A
-    
+%09
 protecte
@@ -845,28 +845,18 @@
 tate) %7B%0A
-            
+%09%09
 super.on
@@ -883,28 +883,18 @@
 State);%0A
-            
+%09%09
 addPrefe
@@ -940,20 +940,10 @@
 s);%0A
-            
+%09%09
 logg
@@ -1036,12 +1036,485 @@
 ));%0A
-    
+%09%09SharedPreferences prefs = getSharedPreferences(PREFERENCES_NAME, MODE_PRIVATE);%0A%09%09if (prefSet(prefs, PREF_NAME) && prefSet(prefs, PREF_EMAIL)) %7B%0A%09%09%09setResult(RESULT_OK);%0A%09%09%7D else %7B%0A%09%09%09setResult(RESULT_CANCELED);%0A%09%09%7D%0A%09%7D%0A%0A%09private boolean prefSet(SharedPreferences prefs, String prefName) %7B%0A%09%09// Has preference which is not null or the empty string%0A%09%09return prefs.contains(prefName) &&%0A%09%09null != prefs.getString(prefName, null) &&%0A%09%09!%22%22.equals(prefs.getString(prefName, %22%22));%0A%09
 %7D%0A%7D%0A

Return result and whitespace fixes.