diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java index 546292ddb..868486775 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java @@ -314,8 +314,7 @@ public class BTInviteDelegate extends InviteDelegate { { if ( null == sPersisted ) { try { - String str64 = DBUtils.getStringFor( context, KEY_PERSIST, null ); - sPersisted = (Persisted)Utils.string64ToSerializable( str64 ); + sPersisted = (Persisted)DBUtils.getSerializableFor( context, KEY_PERSIST ); } catch ( Exception ex ) {} // NPE, de-serialization problems, etc. if ( null == sPersisted ) { @@ -326,9 +325,7 @@ public class BTInviteDelegate extends InviteDelegate { private synchronized static void store( Context context ) { - String str64 = sPersisted == null - ? "" : Utils.serializableToString64( sPersisted ); - DBUtils.setStringFor( context, KEY_PERSIST, str64 ); + DBUtils.setSerializableFor( context, KEY_PERSIST, sPersisted ); } // DlgDelegate.DlgClickNotify interface diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java index 3b90df8ce..d671b063b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java @@ -43,6 +43,7 @@ import java.util.Map; public class ConnStatusHandler { private static final String TAG = ConnStatusHandler.class.getSimpleName(); + private static final String RECS_KEY = TAG + "/recs"; public interface ConnStatusCBacks { public void invalidateParent(); @@ -355,14 +356,10 @@ public class ConnStatusHandler { { synchronized( ConnStatusHandler.class ) { if ( s_records == null ) { - String as64 = XWPrefs.getPrefsString( context, - R.string.key_connstat_data ); - if ( null != as64 && 0 < as64.length() ) { - s_records = (HashMap)Utils. - string64ToSerializable(as64); - } + s_records = (HashMap) + DBUtils.getSerializableFor( context, RECS_KEY ); if ( null == s_records ) { - s_records = new HashMap(); + s_records = new HashMap<>(); } } } @@ -472,9 +469,7 @@ public class ConnStatusHandler { private static void doSave( Context context ) { synchronized( ConnStatusHandler.class ) { - String as64 = Utils.serializableToString64( getRecords( context ) ); - XWPrefs.setPrefsString( context, R.string.key_connstat_data, - as64 ); + DBUtils.setSerializableFor( context, RECS_KEY, getRecords( context ) ); s_needsSave = false; } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java index e785dc230..504aa4e92 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java @@ -2517,6 +2517,23 @@ public class DBUtils { return bytes; } + public static Serializable getSerializableFor( Context context, String key ) + { + Serializable value = null; + String str64 = getStringFor( context, key, "" ); + if ( str64 != null ) { + value = (Serializable)Utils.string64ToSerializable( str64 ); + } + return value; + } + + public static void setSerializableFor( Context context, String key, + Serializable value ) + { + String str64 = null == value ? "" : Utils.serializableToString64( value ); + setStringFor( context, key, str64 ); + } + public static void appendLog( String tag, String msg ) { appendLog( XWApp.getContext(), msg ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java index 89e9fd218..b6a4ecb29 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java @@ -471,20 +471,15 @@ public class RelayInviteDelegate extends InviteDelegate { private void getSavedState() { - String dataString = DBUtils.getStringFor( m_activity, RECS_KEY, null ); - if ( null != dataString ) { - m_devIDRecs = (ArrayList)Utils.string64ToSerializable( dataString ); - } - + m_devIDRecs = (ArrayList)DBUtils.getSerializableFor( m_activity, RECS_KEY ); if ( null == m_devIDRecs ) { - m_devIDRecs = new ArrayList(); + m_devIDRecs = new ArrayList<>(); } } private void saveAndRebuild() { - String as64 = Utils.serializableToString64( m_devIDRecs ); - DBUtils.setStringFor( m_activity, RECS_KEY, as64 ); + DBUtils.setSerializableFor( m_activity, RECS_KEY, m_devIDRecs ); rebuildList( false ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index 1d8306fe0..74c76393c 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -618,7 +618,7 @@ public class Utils { new ObjectInputStream( new ByteArrayInputStream(bytes) ); result = ois.readObject(); } catch ( Exception ex ) { - Log.d( TAG, ex.getMessage() ); + Log.d( TAG, "%s", ex.getMessage() ); } return result; }