mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
move test for whether this is first boot on new version into Utils,
and add test for whether it's new boot ever (to be used with sms on another branch.)
This commit is contained in:
parent
14a1e22c5e
commit
5efe959584
4 changed files with 69 additions and 51 deletions
|
@ -268,7 +268,7 @@ public class DlgDelegate {
|
|||
public void onClick( DialogInterface dlg,
|
||||
int which )
|
||||
{
|
||||
FirstRunDialog.show( m_activity, true );
|
||||
FirstRunDialog.show( m_activity );
|
||||
}
|
||||
} )
|
||||
.create();
|
||||
|
|
|
@ -20,11 +20,8 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.webkit.WebView;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -36,45 +33,7 @@ import java.io.Reader;
|
|||
*/
|
||||
|
||||
public class FirstRunDialog {
|
||||
private static final String HIDDEN_PREFS = "xwprefs_hidden";
|
||||
private static final String SHOWN_VERSION_KEY = "SHOWN_VERSION_KEY";
|
||||
|
||||
static boolean show( Context context, boolean skipCheck )
|
||||
{
|
||||
int thisVersion = 0;
|
||||
int shownVersion = 0;
|
||||
|
||||
if ( !skipCheck ) {
|
||||
try {
|
||||
thisVersion = context.getPackageManager()
|
||||
.getPackageInfo(context.getPackageName(), 0)
|
||||
.versionCode;
|
||||
DbgUtils.logf( "versionCode: %d", thisVersion );
|
||||
} catch ( Exception e ) {
|
||||
}
|
||||
}
|
||||
|
||||
SharedPreferences prefs = null;
|
||||
if ( thisVersion > 0 ) {
|
||||
prefs = context.getSharedPreferences( HIDDEN_PREFS,
|
||||
Context.MODE_PRIVATE );
|
||||
shownVersion = prefs.getInt( SHOWN_VERSION_KEY, 0 );
|
||||
}
|
||||
|
||||
boolean isUpgrade = shownVersion < thisVersion;
|
||||
if ( skipCheck || isUpgrade ) {
|
||||
showDialog( context );
|
||||
|
||||
if ( !skipCheck ) {
|
||||
Editor editor = prefs.edit();
|
||||
editor.putInt( SHOWN_VERSION_KEY, thisVersion );
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
return isUpgrade;
|
||||
}
|
||||
|
||||
private static void showDialog( Context context )
|
||||
public static void show( Context context )
|
||||
{
|
||||
String page = null;
|
||||
InputStream inputStream = null;
|
||||
|
|
|
@ -70,6 +70,8 @@ public class GamesList extends XWListActivity
|
|||
private static final int SYNC_MENU_ACTION = 5;
|
||||
private static final int NEW_FROM_ACTION = 6;
|
||||
|
||||
private static boolean s_firstShown = false;
|
||||
|
||||
private GameListAdapter m_adapter;
|
||||
private String m_missingDict;
|
||||
private Handler m_handler;
|
||||
|
@ -256,7 +258,11 @@ public class GamesList extends XWListActivity
|
|||
registerForContextMenu( getListView() );
|
||||
DBUtils.setDBChangeListener( this );
|
||||
|
||||
boolean isUpgrade = FirstRunDialog.show( this, false );
|
||||
boolean isUpgrade = Utils.firstBootThisVersion( this );
|
||||
if ( isUpgrade && !s_firstShown ) {
|
||||
FirstRunDialog.show( this );
|
||||
s_firstShown = true;
|
||||
}
|
||||
PreferenceManager.setDefaultValues( this, R.xml.xwprefs, isUpgrade );
|
||||
|
||||
// setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
|
||||
|
|
|
@ -22,25 +22,47 @@ package org.eehouse.android.xw4;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Toast;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.SharedPreferences;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.jni.*;
|
||||
|
||||
public class Utils {
|
||||
static final String DB_PATH = "XW_GAMES";
|
||||
private static final String DB_PATH = "XW_GAMES";
|
||||
private static final String HIDDEN_PREFS = "xwprefs_hidden";
|
||||
private static final String SHOWN_VERSION_KEY = "SHOWN_VERSION_KEY";
|
||||
|
||||
private static Boolean s_isFirstBootThisVersion = null;
|
||||
private static Boolean s_isFirstBootEver = null;
|
||||
|
||||
private Utils() {}
|
||||
|
||||
public static boolean firstBootEver( Context context )
|
||||
{
|
||||
if ( null == s_isFirstBootEver ) {
|
||||
setFirstBootStatics( context );
|
||||
}
|
||||
return s_isFirstBootEver;
|
||||
}
|
||||
|
||||
public static boolean firstBootThisVersion( Context context )
|
||||
{
|
||||
if ( null == s_isFirstBootThisVersion ) {
|
||||
setFirstBootStatics( context );
|
||||
}
|
||||
return s_isFirstBootThisVersion;
|
||||
}
|
||||
|
||||
public static void notImpl( Context context )
|
||||
{
|
||||
CharSequence text = "Feature coming soon";
|
||||
|
@ -173,4 +195,35 @@ public class Utils {
|
|||
String fmt = context.getString( id );
|
||||
return String.format( fmt, args );
|
||||
}
|
||||
|
||||
private static void setFirstBootStatics( Context context )
|
||||
{
|
||||
int thisVersion = 0;
|
||||
int prevVersion = 0;
|
||||
|
||||
try {
|
||||
thisVersion = context.getPackageManager()
|
||||
.getPackageInfo(context.getPackageName(), 0)
|
||||
.versionCode;
|
||||
} catch ( Exception e ) {
|
||||
}
|
||||
|
||||
SharedPreferences prefs = null;
|
||||
if ( 0 < thisVersion ) {
|
||||
prefs = context.getSharedPreferences( HIDDEN_PREFS,
|
||||
Context.MODE_PRIVATE );
|
||||
prevVersion = prefs.getInt( SHOWN_VERSION_KEY, -1 );
|
||||
}
|
||||
boolean newVersion = prevVersion != thisVersion;
|
||||
|
||||
s_isFirstBootThisVersion = new Boolean( newVersion );
|
||||
s_isFirstBootEver = new Boolean( -1 == prevVersion );
|
||||
|
||||
if ( newVersion ) {
|
||||
Editor editor = prefs.edit();
|
||||
editor.putInt( SHOWN_VERSION_KEY, thisVersion );
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue