From 2baa56c2629532adad82d0f67abe9dd568a24760 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Fri, 11 Sep 2015 10:57:30 -0700 Subject: Revert "Never cache instances of the HostDatabase" This reverts commit 57afa9bdc5b269a48bd27fc8455cab4cb956d02a. This won't work with injection and makes testing a bit harder, so revert it. --- .../main/java/org/connectbot/HostEditorActivity.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'app/src/main/java/org/connectbot/HostEditorActivity.java') diff --git a/app/src/main/java/org/connectbot/HostEditorActivity.java b/app/src/main/java/org/connectbot/HostEditorActivity.java index 7316775..f9dee45 100644 --- a/app/src/main/java/org/connectbot/HostEditorActivity.java +++ b/app/src/main/java/org/connectbot/HostEditorActivity.java @@ -68,7 +68,6 @@ public class HostEditorActivity extends PreferenceActivity implements OnSharedPr // fill a cursor and cache the values locally // this makes sure we don't have any floating cursor to dispose later - HostDatabase hostdb = HostDatabase.get(HostEditorActivity.this); SQLiteDatabase db = hostdb.getWritableDatabase(); Cursor cursor = db.query(table, null, "_id = ?", new String[] { String.valueOf(id) }, null, null, null); @@ -99,7 +98,6 @@ public class HostEditorActivity extends PreferenceActivity implements OnSharedPr } public boolean commit() { - HostDatabase hostdb = HostDatabase.get(HostEditorActivity.this); SQLiteDatabase db = hostdb.getWritableDatabase(); db.beginTransaction(); try { @@ -215,6 +213,9 @@ public class HostEditorActivity extends PreferenceActivity implements OnSharedPr protected static final String TAG = "CB.HostEditorActivity"; + protected HostDatabase hostdb = null; + private PubkeyDatabase pubkeydb = null; + private CursorPreferenceHack pref; private ServiceConnection connection; @@ -230,7 +231,8 @@ public class HostEditorActivity extends PreferenceActivity implements OnSharedPr // TODO: we could pass through a specific ContentProvider uri here //this.getPreferenceManager().setSharedPreferencesName(uri); - HostDatabase hostdb = HostDatabase.get(this); + this.hostdb = HostDatabase.get(this); + this.pubkeydb = PubkeyDatabase.get(this); host = hostdb.findHostById(hostId); @@ -256,7 +258,6 @@ public class HostEditorActivity extends PreferenceActivity implements OnSharedPr // TODO: should consider moving into onStart, but we dont have a good way of resetting the listpref after filling once ListPreference pubkeyPref = (ListPreference) findPreference(HostDatabase.FIELD_HOST_PUBKEYID); - PubkeyDatabase pubkeydb = PubkeyDatabase.get(this); List pubkeyNicks = new LinkedList(Arrays.asList(pubkeyPref.getEntries())); pubkeyNicks.addAll(pubkeydb.allValues(PubkeyDatabase.FIELD_PUBKEY_NICKNAME)); pubkeyPref.setEntries(pubkeyNicks.toArray(new CharSequence[pubkeyNicks.size()])); @@ -291,6 +292,9 @@ public class HostEditorActivity extends PreferenceActivity implements OnSharedPr super.onStart(); bindService(new Intent(this, TerminalManager.class), connection, Context.BIND_AUTO_CREATE); + + hostdb = HostDatabase.get(this); + pubkeydb = PubkeyDatabase.get(this); } @Override @@ -298,11 +302,12 @@ public class HostEditorActivity extends PreferenceActivity implements OnSharedPr super.onStop(); unbindService(connection); + + hostdb = null; + pubkeydb = null; } private void updateSummaries() { - PubkeyDatabase pubkeydb = PubkeyDatabase.get(this); - // for all text preferences, set hint as current database value for (String key : this.pref.values.keySet()) { if (key.equals(HostDatabase.FIELD_HOST_POSTLOGIN)) continue; -- cgit v1.2.3