mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
fix inability to tell whether a dict being deleted is in use: add to
summaries DB list of dicts in the game and a method that queries that. Pick delete-confirmation message based on the language of dict, whether there are others in the same language, and whether games are using that language or that dict.
This commit is contained in:
parent
528db479b5
commit
fda3207b78
6 changed files with 83 additions and 12 deletions
|
@ -215,9 +215,9 @@
|
|||
<string name="confirm_deleteonly_dictf">\u0020It is the only %s
|
||||
wordlist installed. One or more games will be unopenable
|
||||
without it.</string>
|
||||
<!-- <string name="confirm_deletemore_dictf">\u0020One game (at least) -->
|
||||
<!-- is using it (but there is another %s wordlist installed that -->
|
||||
<!-- can replace it.)</string> -->
|
||||
<string name="confirm_deletemore_dictf">\u0020One game (at least)
|
||||
is using it, but there is another %s wordlist installed that can
|
||||
replace it.</string>
|
||||
|
||||
<string name="hints_allowed">Allow hints</string>
|
||||
<string name="hints_allowed_sum">Enable the hint feature</string>
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue