fix delete dicts warning to catch case of nuking all the lists for a

language at once.  To simplify (coding and user experience), don't
bother with case where user will have to switch to another list before
opening a game.  May want to reconsider this.
This commit is contained in:
Eric House 2014-06-27 08:29:42 -07:00
parent 38b37643f4
commit 5c5ddd5ecd
5 changed files with 585 additions and 588 deletions

File diff suppressed because it is too large Load diff

View file

@ -234,16 +234,9 @@
wordlist delete confiration dialog in the case where the
wordlist to be deleted is the last in its language. The name
of the language is substituted for %1$s. -->
<string name="confirm_deleteonly_dict_fmt">%1$s is the only %2$s
wordlist installed. One or more games will be unopenable
without it.</string>
<!-- Additional text appended to text confirm_delete_dictf in the
wordlist delete confiration dialog in the case where the
wordlist to be deleted is NOT the last in its language. The
name of the language is substituted for %1$s. -->
<string name="confirm_deletemore_dict_fmt">\u0020One game (at least)
is using it, but there is another %1$s wordlist installed that can
replace it.</string>
<string name="confirm_deleteonly_dicts_fmt">Deleting %1$s will
leave you without any %2$s wordlists. One or more games will be
unopenable (until you download a replacement list.)</string>
<!--
############################################################

View file

@ -202,16 +202,9 @@
wordlist delete confiration dialog in the case where the
wordlist to be deleted is the last in its language. The name
of the language is substituted for %1$s. -->
<string name="confirm_deleteonly_dict_fmt">%1$s si eht ylno %2$s
tsildrow dellatsni. Eno ro erom semag lliw eb elbaneponu
tuohtiw ti.</string>
<!-- Additional text appended to text confirm_delete_dictf in the
wordlist delete confiration dialog in the case where the
wordlist to be deleted is NOT the last in its language. The
name of the language is substituted for %1$s. -->
<string name="confirm_deletemore_dict_fmt">\u0020Eno emag ta( )tsael
si gnisu ,ti tub ereht si rehtona %1$s tsildrow dellatsni taht nac
ecalper ti.</string>
<string name="confirm_deleteonly_dicts_fmt">Gniteled %1$s lliw
evael uoy tuohtiw yna %2$s stsildrow. Eno ro erom semag lliw eb
elbaneponu litnu( uoy daolnwod a tnemecalper tsil.)</string>
<!--
############################################################
# :Dialogs:

View file

@ -202,16 +202,9 @@
wordlist delete confiration dialog in the case where the
wordlist to be deleted is the last in its language. The name
of the language is substituted for %1$s. -->
<string name="confirm_deleteonly_dict_fmt">%1$s IS THE ONLY %2$s
WORDLIST INSTALLED. ONE OR MORE GAMES WILL BE UNOPENABLE
WITHOUT IT.</string>
<!-- Additional text appended to text confirm_delete_dictf in the
wordlist delete confiration dialog in the case where the
wordlist to be deleted is NOT the last in its language. The
name of the language is substituted for %1$s. -->
<string name="confirm_deletemore_dict_fmt">\u0020ONE GAME (AT LEAST)
IS USING IT, BUT THERE IS ANOTHER %1$s WORDLIST INSTALLED THAT CAN
REPLACE IT.</string>
<string name="confirm_deleteonly_dicts_fmt">DELETING %1$s WILL
LEAVE YOU WITHOUT ANY %2$s WORDLISTS. ONE OR MORE GAMES WILL BE
UNOPENABLE (UNTIL YOU DOWNLOAD A REPLACEMENT LIST.)</string>
<!--
############################################################
# :Dialogs:

View file

@ -725,37 +725,61 @@ public class DictsDelegate extends ListDelegateBase
String msg = getString( R.string.confirm_delete_dict_fmt,
getJoinedNames( items ) );
// 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.
// Confirm. And for each dict, warn if (after ALL are deleted) any
// game will no longer be openable without downloading. For now
// anyway skip warning for the case where user will have to switch to
// a different same-lang wordlist to open a game.
class LangDelData {
public LangDelData( int langCode ) {
delDicts = new HashSet<String>();
langName = DictLangCache.getLangName( m_activity, langCode );
nDicts = DictLangCache.getDALsHaveLang( m_activity, langCode ).length;
}
public String dictsStr()
{
if ( null == m_asArray ) {
String[] arr = delDicts.toArray(new String[delDicts.size()]);
m_asArray = TextUtils.join( ", ", arr );
}
return m_asArray;
}
Set<String> delDicts;
private String m_asArray;
String langName;
int nDicts;
}
Map<Integer, LangDelData> dels = new HashMap<Integer, LangDelData>();
Set<Integer> skipLangs = new HashSet<Integer>();
for ( XWListItem item : items ) {
String dict = item.getText();
if ( 1 < DictLangCache.getDictCount( m_activity, dict ) ) {
// there's another; do nothing
int langCode = DictLangCache.getDictLangCode( m_activity, dict );
if ( skipLangs.contains( langCode ) ) {
continue;
}
int nUsingLang = DBUtils.countGamesUsingLang( m_activity, langCode );
if ( 0 == nUsingLang ) {
// remember, since countGamesUsingLang is expensive
skipLangs.add( langCode );
} else {
String newMsg = null;
int langcode = DictLangCache.getDictLangCode( m_activity, dict );
String langName = DictLangCache.getLangName( m_activity, langcode );
DictAndLoc[] langDals = DictLangCache.getDALsHaveLang( m_activity,
langcode );
int nUsingLang = DBUtils.countGamesUsingLang( m_activity, langcode );
LangDelData data = dels.get( langCode );
if ( null == data ) {
data = new LangDelData( langCode );
dels.put( langCode, data );
}
data.delDicts.add( dict );
}
}
if ( 1 == langDals.length ) { // last in this language?
if ( 0 < nUsingLang ) {
newMsg = getString( R.string.confirm_deleteonly_dict_fmt,
dict, langName );
}
} else if ( 0 < DBUtils.countGamesUsingDict( m_activity, dict ) ) {
newMsg = getString( R.string.confirm_deletemore_dict_fmt,
langName );
}
if ( null != newMsg ) {
msg += "\n\n" + newMsg;
}
for ( Iterator<LangDelData> iter = dels.values().iterator(); iter.hasNext(); ) {
LangDelData data = iter.next();
int nLeftAfter = data.nDicts - data.delDicts.size();
if ( 0 == nLeftAfter ) { // last in this language?
String newMsg = getString( R.string.confirm_deleteonly_dicts_fmt,
data.dictsStr(), data.langName );
msg += "\n\n" + newMsg;
}
}