First cut at support for Android versioning and data migrations

This commit is contained in:
Aaron Culliney 2015-12-12 12:09:14 -08:00
parent d819220a07
commit a761c11382
2 changed files with 12 additions and 6 deletions

View File

@ -17,6 +17,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
@ -155,8 +156,12 @@ public class Apple2Activity extends Activity {
String dataDir = Apple2DisksMenu.getDataDir(this);
nativeOnCreate(dataDir, sampleRate, monoBufferSize, stereoBufferSize);
final boolean firstTime = !Apple2Preferences.FIRST_TIME_CONFIGURED.booleanValue(this);
Apple2Preferences.FIRST_TIME_CONFIGURED.saveBoolean(this, true);
final boolean firstTime = (Apple2Preferences.EMULATOR_VERSION.intValue(this) != BuildConfig.VERSION_CODE);
if (firstTime) {
// allow for primitive migrations as needed
Apple2Preferences.EMULATOR_VERSION.saveInt(this, BuildConfig.VERSION_CODE);
Log.v(TAG, "Triggering migration to Apple2ix version : "+BuildConfig.VERSION_NAME);
}
showSplashScreen(!firstTime);
Apple2CrashHandler.getInstance().checkForCrashes(this);

View File

@ -18,18 +18,19 @@ import android.util.Log;
import java.io.File;
import org.deadc0de.apple2ix.basic.BuildConfig;
import org.deadc0de.apple2ix.basic.R;
public enum Apple2Preferences {
FIRST_TIME_CONFIGURED {
EMULATOR_VERSION {
@Override
public void load(Apple2Activity activity) {
/* ... */
}
@Override
public void saveBoolean(Apple2Activity activity, boolean ignored) {
activity.getPreferences(Context.MODE_PRIVATE).edit().putBoolean(toString(), true).apply();
public void saveInt(Apple2Activity activity, int version) {
activity.getPreferences(Context.MODE_PRIVATE).edit().putInt(toString(), version).apply();
}
},
CURRENT_DISK_PATH {
@ -955,7 +956,7 @@ public enum Apple2Preferences {
public static void resetPreferences(Apple2Activity activity) {
activity.getPreferences(Context.MODE_PRIVATE).edit().clear().commit();
FIRST_TIME_CONFIGURED.saveBoolean(activity, true);
EMULATOR_VERSION.saveInt(activity, BuildConfig.VERSION_CODE);
KeypadPreset.IJKM_SPACE.apply(activity);
loadPreferences(activity);
}