changeset 127:69db8af9508d

host editor database values override summary text only if non-empty
author Carl Byington <carl@five-ten-sg.com>
date Thu, 19 Jun 2014 09:40:28 -0700
parents f7e3abdbc8a5
children 377357365d68
files src/com/five_ten_sg/connectbot/HostEditorActivity.java
diffstat 1 files changed, 19 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/HostEditorActivity.java	Thu Jun 19 09:14:04 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/HostEditorActivity.java	Thu Jun 19 09:40:28 2014 -0700
@@ -22,6 +22,7 @@
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -54,7 +55,7 @@
         protected final long id;
 
         protected Map<String, String> values = new HashMap<String, String>();
-//      protected Map<String, String> pubkeys = new HashMap<String, String>();
+        protected Map<String, CharSequence> summaries = new HashMap<String, CharSequence>();
 
         public CursorPreferenceHack(String table, long id) {
             this.table = table;
@@ -82,21 +83,6 @@
 
             cursor.close();
             db.close();
-//          db = pubkeydb.getReadableDatabase();
-//          cursor = db.query(PubkeyDatabase.TABLE_PUBKEYS,
-//                  new String[] { "_id", PubkeyDatabase.FIELD_PUBKEY_NICKNAME },
-//                  null, null, null, null, null);
-//
-//          if (cursor.moveToFirst()) {
-//              do {
-//                  String pubkeyid = String.valueOf(cursor.getLong(0));
-//                  String value = cursor.getString(1);
-//                  pubkeys.put(pubkeyid, value);
-//              } while (cursor.moveToNext());
-//          }
-//
-//          cursor.close();
-//          db.close();
         }
 
         public boolean contains(String key) {
@@ -261,6 +247,8 @@
         this.pref = new CursorPreferenceHack(HostDatabase.TABLE_HOSTS, hostId);
         this.pref.registerOnSharedPreferenceChangeListener(this);
         this.addPreferencesFromResource(R.xml.host_prefs);
+        // get all the text summaries
+        getSummaries();
         // disable all preferences that are not applicable to this host
         findPreference(HostDatabase.FIELD_HOST_PUBKEYID).setEnabled(enableSSHFeatures);
         findPreference(HostDatabase.FIELD_HOST_USEAUTHAGENT).setEnabled(enableSSHFeatures);
@@ -271,10 +259,7 @@
         findPreference(HostDatabase.FIELD_HOST_USERNAME).setEnabled(enableSSHFeatures || enable5250Features);
         findPreference(HostDatabase.FIELD_HOST_EMULATION).setEnabled(!enable5250Features);
         findPreference(HostDatabase.CATEGORY_5250).setEnabled(enable5250Features);
-        findPreference(HostDatabase.FIELD_HOST_ENCRYPTION5250).setEnabled(enable5250Features);
         findPreference(HostDatabase.CATEGORY_X11).setEnabled(enableSSHFeatures);
-        findPreference(HostDatabase.FIELD_HOST_X11HOST).setEnabled(enableSSHFeatures);
-        findPreference(HostDatabase.FIELD_HOST_X11PORT).setEnabled(enableSSHFeatures);
         // add all existing pubkeys to our listpreference for user to choose from
         // TODO: may be an issue here when this activity is recycled after adding a new pubkey
         // TODO: should consider moving into onStart, but we dont have a good way of resetting the listpref after filling once
@@ -334,23 +319,27 @@
         }
     }
 
-    private void updateSummaries() {
-        // for all text preferences, set hint as current database value
+    private void getSummaries() {
+        // get all the original text summaries
         for (String key : this.pref.values.keySet()) {
-             if (key.equals(HostDatabase.FIELD_HOST_POSTLOGIN)) continue;
-             if (key.equals(HostDatabase.FIELD_HOST_EMULATION)) continue;
+            Preference pref = this.findPreference(key);
+            if (pref == null) continue;
+            if (pref instanceof CheckBoxPreference) continue;
+            CharSequence value = this.pref.getSummary(key, "");
+            summaries.put(key, value);
+    }
 
+    private void updateSummaries() {
+        // for all text preferences, set hint as current database value if it is non-empty
+        for (String key : this.pref.values.keySet()) {
             Preference pref = this.findPreference(key);
-
             if (pref == null) continue;
-
             if (pref instanceof CheckBoxPreference) continue;
-
             CharSequence value = this.pref.getString(key, "");
 
             if (key.equals(HostDatabase.FIELD_HOST_PUBKEYID)) {
                 try {
-                    int pubkeyId = Integer.parseInt((String) value);
+                    int pubkeyId = Integer.parseInt(value.toString());
 
                     if (pubkeyId >= 0)
                         pref.setSummary(pubkeydb.getNickname(pubkeyId));
@@ -367,12 +356,11 @@
             }
             else if (pref instanceof ListPreference) {
                 ListPreference listPref = (ListPreference) pref;
-                int entryIndex = listPref.findIndexOfValue((String) value);
-
-                if (entryIndex >= 0)
-                    value = listPref.getEntries()[entryIndex];
+                int entryIndex = listPref.findIndexOfValue(value);
+                if (entryIndex >= 0) value = listPref.getEntries()[entryIndex];
             }
 
+            if ((value == null) || value.length() == 0)) value = summaries.get(key);
             pref.setSummary(value);
         }
     }