mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
new table for generic key/value pairs, and fix crash on new install by
not requiring localization db to exist during db creation.
This commit is contained in:
parent
96c7f301d0
commit
b636fe263b
2 changed files with 80 additions and 12 deletions
|
@ -29,6 +29,8 @@ import android.text.TextUtils;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
public class DBHelper extends SQLiteOpenHelper {
|
||||
|
||||
public static final String TABLE_NAME_SUM = "summaries";
|
||||
|
@ -38,8 +40,9 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
public static final String TABLE_NAME_GROUPS = "groups";
|
||||
public static final String TABLE_NAME_STUDYLIST = "study";
|
||||
public static final String TABLE_NAME_LOC = "loc";
|
||||
public static final String TABLE_NAME_PAIRS = "pairs";
|
||||
private static final String DB_NAME = "xwdb";
|
||||
private static final int DB_VERSION = 21;
|
||||
private static final int DB_VERSION = 22;
|
||||
|
||||
public static final String GAME_NAME = "GAME_NAME";
|
||||
public static final String VISID = "VISID";
|
||||
|
@ -94,6 +97,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
public static final String LANGUAGE = "LANGUAGE";
|
||||
|
||||
public static final String KEY = "KEY";
|
||||
public static final String VALUE = "VALUE";
|
||||
public static final String LOCALE = "LOCALE";
|
||||
public static final String BLESSED = "BLESSED";
|
||||
public static final String XLATION = "XLATION";
|
||||
|
@ -179,6 +183,12 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
,{ XLATION, "TEXT" }
|
||||
};
|
||||
|
||||
private static final String[][] s_pairsSchema = {
|
||||
{ KEY, "TEXT" }
|
||||
,{ VALUE, "TEXT" }
|
||||
,{ "UNIQUE", "(" + KEY + ")" }
|
||||
};
|
||||
|
||||
public DBHelper( Context context )
|
||||
{
|
||||
super( context, DB_NAME, null, DB_VERSION );
|
||||
|
@ -201,6 +211,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
createGroupsTable( db, false );
|
||||
createStudyTable( db );
|
||||
createLocTable( db );
|
||||
createPairsTable( db );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -257,6 +268,8 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
case 20:
|
||||
createLocTable( db );
|
||||
case 21:
|
||||
createPairsTable( db );
|
||||
break;
|
||||
default:
|
||||
db.execSQL( "DROP TABLE " + TABLE_NAME_SUM + ";" );
|
||||
|
@ -268,6 +281,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
new TableAndVersion( TABLE_NAME_GROUPS, 14 ),
|
||||
new TableAndVersion( TABLE_NAME_STUDYLIST, 18 ),
|
||||
new TableAndVersion( TABLE_NAME_LOC, 20 ),
|
||||
new TableAndVersion( TABLE_NAME_PAIRS, 21 ),
|
||||
};
|
||||
for ( TableAndVersion entry : tav ) {
|
||||
if ( oldVersion >= 1 + entry.addedVersion ) {
|
||||
|
@ -320,7 +334,8 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
// Create an empty group name
|
||||
ContentValues values = new ContentValues();
|
||||
if ( isUpgrade ) {
|
||||
values.put( GROUPNAME, m_context.getString(R.string.group_cur_games) );
|
||||
values.put( GROUPNAME, LocUtils.getString( m_context, false,
|
||||
R.string.group_cur_games) );
|
||||
values.put( EXPANDED, 1 );
|
||||
long curGroup = db.insert( TABLE_NAME_GROUPS, null, values );
|
||||
|
||||
|
@ -331,7 +346,8 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
values = new ContentValues();
|
||||
values.put( GROUPNAME, m_context.getString(R.string.group_new_games) );
|
||||
values.put( GROUPNAME, LocUtils.getString( m_context, false,
|
||||
R.string.group_new_games) );
|
||||
values.put( EXPANDED, 1 );
|
||||
long newGroup = db.insert( TABLE_NAME_GROUPS, null, values );
|
||||
XWPrefs.setDefaultNewGameGroup( m_context, newGroup );
|
||||
|
@ -347,10 +363,16 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
createTable( db, TABLE_NAME_LOC, s_locSchema );
|
||||
}
|
||||
|
||||
private void createPairsTable( SQLiteDatabase db )
|
||||
{
|
||||
createTable( db, TABLE_NAME_PAIRS, s_pairsSchema );
|
||||
}
|
||||
|
||||
// Move all existing games to the row previously named "cur games'
|
||||
private void moveToCurGames( SQLiteDatabase db )
|
||||
{
|
||||
String name = m_context.getString( R.string.group_cur_games );
|
||||
String name = LocUtils.getString( m_context, false,
|
||||
R.string.group_cur_games );
|
||||
String[] columns = { "rowid" };
|
||||
String selection = String.format( "%s = '%s'", GROUPNAME, name );
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_GROUPS, columns,
|
||||
|
|
|
@ -42,6 +42,9 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.DBUtils;
|
||||
|
@ -53,11 +56,16 @@ import org.eehouse.android.xw4.XWPrefs;
|
|||
public class LocUtils {
|
||||
// Keep this in sync with gen_loc_ids.py and what's used in the menu.xml
|
||||
// files to mark me-localized strings.
|
||||
private static final int FMT_LEN = 4;
|
||||
private static final String k_LOCALE = "locale";
|
||||
private static final String k_XLATPROTO = "proto";
|
||||
private static final int XLATE_CUR_VERSION = 1;
|
||||
private static final String k_XLATEVERS = "xlatevers";
|
||||
|
||||
private static HashMap<String, String>s_xlations = null;
|
||||
private static HashMap<Integer, String> s_idsToKeys = null;
|
||||
private static Boolean s_enabled = null;
|
||||
private static Boolean UPPER_CASE = true;
|
||||
private static final int FMT_LEN = 4;
|
||||
|
||||
public interface LocIface {
|
||||
void setText( CharSequence text );
|
||||
|
@ -115,7 +123,7 @@ public class LocUtils {
|
|||
public static String xlateString( Context context, String str )
|
||||
{
|
||||
if ( LocIDs.getS_MAP( context ).containsKey( str ) ) {
|
||||
String xlation = getXlation( context, str );
|
||||
String xlation = getXlation( context, true, str );
|
||||
if ( null != xlation ) {
|
||||
str = xlation;
|
||||
}
|
||||
|
@ -148,12 +156,17 @@ public class LocUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static String getString( Context context, int id )
|
||||
public static String getString( Context context, int id )
|
||||
{
|
||||
return getString( context, true, id );
|
||||
}
|
||||
|
||||
public static String getString( Context context, boolean canUseDB, int id )
|
||||
{
|
||||
String result = null;
|
||||
String key = keyForID( context, id );
|
||||
if ( null != key ) {
|
||||
result = getXlation( context, key );
|
||||
result = getXlation( context, canUseDB, key );
|
||||
}
|
||||
|
||||
if ( null == result ) {
|
||||
|
@ -179,10 +192,16 @@ public class LocUtils {
|
|||
s_xlations.put( key, txt );
|
||||
}
|
||||
|
||||
public static String getXlation( Context context, String key )
|
||||
public static String getXlation( Context context, boolean canUseDB,
|
||||
String key )
|
||||
{
|
||||
loadXlations( context );
|
||||
String result = s_xlations.get( key );
|
||||
if ( canUseDB ) {
|
||||
loadXlations( context );
|
||||
}
|
||||
String result = null;
|
||||
if ( null != s_xlations ) {
|
||||
result = s_xlations.get( key );
|
||||
}
|
||||
if ( UPPER_CASE && null == result ) {
|
||||
result = toUpperCase( key );
|
||||
}
|
||||
|
@ -194,6 +213,27 @@ public class LocUtils {
|
|||
DBUtils.saveXlations( context, "te_ST", s_xlations );
|
||||
}
|
||||
|
||||
public static JSONObject makeForXlationUpdate( Context context )
|
||||
{
|
||||
JSONObject result = null;
|
||||
String locale = XWPrefs.getLocale( context );
|
||||
if ( null != locale && 0 < locale.length() ) {
|
||||
try {
|
||||
String version = DBUtils.getStringFor( context, k_XLATEVERS, "0" );
|
||||
result = new JSONObject()
|
||||
.put( k_XLATPROTO, XLATE_CUR_VERSION )
|
||||
.put( k_LOCALE, locale )
|
||||
.put( k_XLATEVERS, version );
|
||||
} catch ( org.json.JSONException jse ) {
|
||||
DbgUtils.loge( jse );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void addXlation( Context context, String jsonData )
|
||||
{
|
||||
}
|
||||
|
||||
protected static LocSearcher.Pair[] makePairs( Context context )
|
||||
{
|
||||
|
@ -208,7 +248,7 @@ public class LocUtils {
|
|||
String key = iter.next();
|
||||
String english = context.getString( map.get( key ) );
|
||||
Assert.assertTrue( english.equals( key ) );
|
||||
String xlation = getXlation( context, key );
|
||||
String xlation = getXlation( context, true, key );
|
||||
result[ii] = new LocSearcher.Pair( key, english, xlation );
|
||||
}
|
||||
return result;
|
||||
|
@ -361,6 +401,12 @@ public class LocUtils {
|
|||
return setTitle( str );
|
||||
}
|
||||
|
||||
public AlertDialog.Builder setMessage( int textId )
|
||||
{
|
||||
String str = getString( m_context, textId );
|
||||
return setMessage( str );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog.Builder setPositiveButton( int textId,
|
||||
OnClickListener listener )
|
||||
|
|
Loading…
Reference in a new issue