From edcd29c88d7f4a0314ad6c912227f75a6fc406b3 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 4 May 2014 15:41:02 -0700 Subject: [PATCH] in order that non-English versions not go long after installation without translations, try immediately after any install or upgrade to get translations from server. (Triggered from the Application rather than an Activity, so initializing the preferences DB had to be moved there too.) Should probably post a notification after installing localizations, ideally with a message in the language, offering to restart with all new strings. --- .../android/xw4/GamesListDelegate.java | 2 -- .../android/xw4/UpdateCheckReceiver.java | 1 + .../src/org/eehouse/android/xw4/XWApp.java | 12 +++++++++ .../src/org/eehouse/android/xw4/XWPrefs.java | 27 ++++++++++++++++++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index 7b0ad2604..143847803 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -33,7 +33,6 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Message; -import android.preference.PreferenceManager; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -365,7 +364,6 @@ public class GamesListDelegate extends DelegateBase FirstRunDialog.show( m_activity ); s_firstShown = true; } - PreferenceManager.setDefaultValues( m_activity, R.xml.xwprefs, isUpgrade ); m_adapter = makeNewAdapter(); listview.setOnItemLongClickListener( this ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/UpdateCheckReceiver.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/UpdateCheckReceiver.java index 89bc2d154..3c318c3ec 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/UpdateCheckReceiver.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/UpdateCheckReceiver.java @@ -318,6 +318,7 @@ public class UpdateCheckReceiver extends BroadcastReceiver { { if ( null != json ) { makeNotificationsIf( json ); + XWPrefs.setHaveCheckedUpgrades( m_context, true ); } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java index 9b59ff888..bd583e5f9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java @@ -24,6 +24,7 @@ import android.app.Application; import android.content.Context; import android.graphics.Color; import android.os.Build; +import android.preference.PreferenceManager; import java.util.UUID; @@ -62,6 +63,17 @@ public class XWApp extends Application { ConnStatusHandler.loadState( this ); RelayReceiver.RestartTimer( this ); + + boolean mustCheck = Utils.firstBootThisVersion( this ); + PreferenceManager.setDefaultValues( this, R.xml.xwprefs, mustCheck ); + if ( mustCheck ) { + XWPrefs.setHaveCheckedUpgrades( this, false ); + } else { + mustCheck = ! XWPrefs.getHaveCheckedUpgrades( this ); + } + if ( mustCheck ) { + UpdateCheckReceiver.checkVersions( this, false ); + } UpdateCheckReceiver.restartTimer( this ); BTService.startService( this ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java index aa00f0e32..8ac95ef38 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java @@ -31,6 +31,9 @@ import junit.framework.Assert; public class XWPrefs { + // No reason to put this in xml if they're private to this file! + private static final String key_checked_upgrades = "key_checked_upgrades"; + public static boolean getSMSEnabled( Context context ) { return getPrefsBoolean( context, R.string.key_enable_sms, false ); @@ -141,6 +144,12 @@ public class XWPrefs { boolean defaultValue ) { String key = context.getString( keyID ); + return getPrefsBoolean( context, key, defaultValue ); + } + + private static boolean getPrefsBoolean( Context context, String key, + boolean defaultValue ) + { SharedPreferences sp = PreferenceManager .getDefaultSharedPreferences( context ); return sp.getBoolean( key, defaultValue ); @@ -148,11 +157,17 @@ public class XWPrefs { public static void setPrefsBoolean( Context context, int keyID, boolean newValue ) + { + String key = context.getString( keyID ); + setPrefsBoolean( context, key, newValue ); + } + + private static void setPrefsBoolean( Context context, String key, + boolean newValue ) { SharedPreferences sp = PreferenceManager .getDefaultSharedPreferences( context ); SharedPreferences.Editor editor = sp.edit(); - String key = context.getString( keyID ); editor.putBoolean( key, newValue ); editor.commit(); } @@ -439,4 +454,14 @@ public class XWPrefs { { return getPrefsBoolean( context, R.string.key_xlations_enabled, false ); } + + public static void setHaveCheckedUpgrades( Context context, boolean haveChecked ) + { + setPrefsBoolean( context, key_checked_upgrades, haveChecked ); + } + + public static boolean getHaveCheckedUpgrades( Context context ) + { + return getPrefsBoolean( context, key_checked_upgrades, false ); + } }