Browse Source

preferences update settings value after they've been edited

Fabio Arnold 9 years ago
parent
commit
0ef39be0fb

+ 10 - 17
src/de/tudarmstadt/informatik/hostage/ui/fragment/PreferenceHostageFragment.java

@@ -10,7 +10,9 @@ import android.preference.PreferenceFragment;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.sync.android.SyncUtils;
@@ -23,9 +25,9 @@ import de.tudarmstadt.informatik.hostage.sync.android.SyncUtils;
 */
 public class PreferenceHostageFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
 	/**
-	 * Maps an text preference to an suffix string
+	 * Contains preferences for which to display a preview of the value in the summary
 	 */
-	private HashMap<String, String> mSuffixMap;
+	private HashSet<String> mPrefValuePreviewSet;
 
 	/**
 	 * {@inheritDoc}
@@ -47,12 +49,9 @@ public class PreferenceHostageFragment extends PreferenceFragment implements Sha
 				"pref_portscan_timeout"
 		};
 
-		// map the text preferences to suffixes
-		this.mSuffixMap = new HashMap<String, String>();
-		this.mSuffixMap.put("pref_timeout", "s");
-		this.mSuffixMap.put("pref_sleeptime", "ms");
-		this.mSuffixMap.put("pref_location_time", "ms");
-		this.mSuffixMap.put("pref_portscan_timeout", "s");
+		mPrefValuePreviewSet = new HashSet<String>();
+		mPrefValuePreviewSet.add("pref_external_location");
+		mPrefValuePreviewSet.add("pref_upload_server");
 
 		addPreferencesFromResource(R.xml.settings_preferences);
 
@@ -69,15 +68,9 @@ public class PreferenceHostageFragment extends PreferenceFragment implements Sha
 		Preference p = findPreference(key);
 		SharedPreferences sharedPreferences = this.getPreferenceManager().getSharedPreferences();
 
-		if(p != null && p instanceof EditTextPreference){
-			String suffix = "";
-
-			if(this.mSuffixMap.containsKey(key)){
-				suffix = this.mSuffixMap.get(key);
-			}
-
-			if (p.getSummary() == null) {
-				p.setSummary(sharedPreferences.getString(key, "") + " " + suffix);
+		if(p != null && p instanceof EditTextPreference) {
+			if (mPrefValuePreviewSet.contains(key)) {
+				p.setSummary(sharedPreferences.getString(key, ""));
 			}
 		}
 	}