diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index dc3d9e51a..517f9c336 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -215,9 +215,9 @@ \u0020It is the only %s wordlist installed. One or more games will be unopenable without it. - - - + \u0020One game (at least) + is using it, but there is another %s wordlist installed that can + replace it. Allow hints Enable the hint feature diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java index f6fbbee82..7e835f829 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java @@ -29,7 +29,7 @@ public class DBHelper extends SQLiteOpenHelper { public static final String TABLE_NAME_SUM = "summaries"; public static final String TABLE_NAME_OBITS = "obits"; private static final String DB_NAME = "xwdb"; - private static final int DB_VERSION = 9; + private static final int DB_VERSION = 10; public static final String GAME_NAME = "GAME_NAME"; public static final String NUM_MOVES = "NUM_MOVES"; @@ -48,6 +48,7 @@ public class DBHelper extends SQLiteOpenHelper { // format public static final String GAMEID = "GAMEID"; public static final String DICTLANG = "DICTLANG"; + public static final String DICTLIST = "DICTLIST"; public static final String HASMSGS = "HASMSGS"; public static final String CONTRACTED = "CONTRACTED"; public static final String SNAPSHOT = "SNAPSHOT"; @@ -87,6 +88,7 @@ public class DBHelper extends SQLiteOpenHelper { + RELAYID + " TEXT," + SEED + " INTEGER," + DICTLANG + " INTEGER," + + DICTLIST + " TEXT," + SMSPHONE + " TEXT," + SCORES + " TEXT," @@ -142,6 +144,9 @@ public class DBHelper extends SQLiteOpenHelper { db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM + " ADD COLUMN " + CONTRACTED + " INTEGER;" ); case 9: + db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM + + " ADD COLUMN " + DICTLIST + " TEXT;" ); + case 10: // nothing yet break; default: diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index af6736c28..b56bb3704 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -38,6 +38,8 @@ import org.eehouse.android.xw4.jni.*; public class DBUtils { + private static final String DICTS_SEP = ","; + private static final String ROW_ID = "rowid"; private static final String ROW_ID_FMT = "rowid=%d"; @@ -226,6 +228,7 @@ public class DBUtils { summary.summarizePlayers() ); values.put( DBHelper.DICTLANG, summary.dictLang ); values.put( DBHelper.GAME_OVER, summary.gameOver ); + values.put( DBHelper.DICTLIST, summary.dictNames(DICTS_SEP) ); if ( null != summary.scores ) { StringBuffer sb = new StringBuffer(); @@ -273,6 +276,28 @@ public class DBUtils { return result; } + public static int countGamesUsingDict( Context context, String dict ) + { + int result = 0; + initDB( context ); + synchronized( s_dbHelper ) { + SQLiteDatabase db = s_dbHelper.getReadableDatabase(); + String pattern = String.format( "%%%s%s%s%%", + DICTS_SEP, dict, DICTS_SEP ); + String selection = String.format( "%s LIKE '%s'", + DBHelper.DICTLIST, pattern ); + // null for columns will return whole rows: bad. But + // might as well make it an int for speed + String[] columns = { DBHelper.DICTLANG }; + Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns, + selection, null, null, null, null ); + result = cursor.getCount(); + cursor.close(); + db.close(); + } + return result; + } + private static void setInt( long rowid, String column, int value ) { synchronized( s_dbHelper ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java index b62ecef96..1a29eac2e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictLangCache.java @@ -30,6 +30,7 @@ import java.util.HashSet; import java.util.Set; import java.util.Arrays; import java.util.Comparator; +import junit.framework.Assert; import org.eehouse.android.xw4.DictUtils.DictAndLoc; import org.eehouse.android.xw4.jni.JNIUtilsImpl; @@ -331,6 +332,18 @@ public class DictLangCache { return s_langNames; } + public static int getDictCount( Context context, String name ) + { + int result = 0; + for ( DictAndLoc dal : DictUtils.dictList( context ) ) { + if ( name.equals( dal.name ) ) { + ++result; + } + } + Assert.assertTrue( result > 0 ); + return result; + } + private static DictInfo getInfo( Context context, String name ) { DictInfo result = null; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 41e26a24e..fd4c6c59a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -524,21 +524,39 @@ public class DictsActivity extends ExpandableListActivity public void deleteCalled( XWListItem item ) { String dict = item.getText(); - int code = DictLangCache.getDictLangCode( this, dict ); - int nGames = DBUtils.countGamesUsingLang( this, code ); String msg = String.format( getString( R.string.confirm_delete_dictf ), dict ); m_deleteDict = dict; m_moveFromLoc = (DictUtils.DictLoc)item.getCached(); - if ( nGames > 0 ) { - DictAndLoc[] dal = DictLangCache.getDALsHaveLang( this, code ); - if ( 1 == dal.length ) { - Assert.assertTrue( dict.equals(dal[0].name) ); - String fmt = getString( R.string.confirm_deleteonly_dictf ); + // When and what to warn about. First off, if there's another + // identical dict, simply confirm. Or if nobody's using this + // dict *and* it's not the last of a language that somebody's + // using, simply confirm. If somebody is using it, then we + // want different warnings depending on whether it's the last + // available dict in its language. + + if ( 1 < DictLangCache.getDictCount( this, dict ) ) { + // there's another; do nothing + } else { + int fmtid = 0; + int langcode = DictLangCache.getDictLangCode( this, dict ); + DictAndLoc[] langDals = DictLangCache.getDALsHaveLang( this, + langcode ); + int nUsingLang = DBUtils.countGamesUsingLang( this, langcode ); + + if ( 1 == langDals.length ) { // last in this language? + if ( 0 < nUsingLang ) { + fmtid = R.string.confirm_deleteonly_dictf; + } + } else if ( 0 < DBUtils.countGamesUsingDict( this, dict ) ) { + fmtid = R.string.confirm_deletemore_dictf; + } + if ( 0 != fmtid ) { + String fmt = getString( fmtid ); msg += String.format( fmt, DictLangCache. - getLangName( this, code ) ); + getLangName( this, langcode ) ); } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java index 0244bc355..e1abd23c6 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java @@ -258,4 +258,14 @@ public class GameSummary { return indx == turn && isLocal(indx); } + public String dictNames( String separator ) + { + String list = null; + if ( null != m_gi ) { + String[] names = m_gi.dictNames(); + list = TextUtils.join( separator, names ); + } + return String.format( "%s%s%s", separator, list, separator ); + } + }