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 ed1f93c68..06435c061 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 @@ -1853,11 +1853,16 @@ public class DBUtils { public static boolean loadDB( Context context ) { - return copyGameDB( context, false ); + boolean success = copyGameDB( context, false ); + if ( success ) { + PrefsDelegate.loadPrefs( context ); + } + return success; } public static boolean saveDB( Context context ) { + PrefsDelegate.savePrefs( context ); return copyGameDB( context, true ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java index 7893d5df2..717395d03 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java @@ -47,6 +47,7 @@ public class PrefsDelegate extends DelegateBase implements SharedPreferences.OnSharedPreferenceChangeListener, View.OnClickListener, PopupMenu.OnMenuItemClickListener { private static final String TAG = PrefsDelegate.class.getSimpleName(); + private static final String PREFS_KEY = TAG + "/prefs"; private XWActivity mActivity; private PreferenceFragmentCompat mFragment; @@ -365,4 +366,41 @@ public class PrefsDelegate extends DelegateBase PreferenceManager.setDefaultValues( context, id, mustCheck ); } } + + static void savePrefs( Context context ) + { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( context ); + Map all = prefs.getAll(); + HashMap copy = new HashMap<>(); + for ( String key : all.keySet() ) { + copy.put( key, all.get(key) ); + } + DBUtils.setSerializableFor( context, PREFS_KEY, copy ); + } + + static void loadPrefs( Context context ) { + HashMap map = (HashMap)DBUtils + .getSerializableFor( context, PREFS_KEY ); + if ( null != map ) { + SharedPreferences.Editor editor = + PreferenceManager.getDefaultSharedPreferences( context ) + .edit(); + for ( String key : map.keySet() ) { + Object value = map.get( key ); + if ( value instanceof Boolean ) { + editor.putBoolean( key, (Boolean)value ); + } else if ( value instanceof String ) { + editor.putString( key, (String)value ); + } else if ( value instanceof Integer ) { + editor.putInt( key, (Integer)value ); + } else if ( value instanceof Long ) { + editor.putLong( key, (Long)value ); + } else { + Log.d( TAG, "unexpected class: %s", value.getClass().getName() ); + Assert.failDbg(); + } + } + editor.commit(); + } + } }