mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
implement delete and make default menuitems
This commit is contained in:
parent
a0b1cddf7a
commit
886f9100e1
2 changed files with 98 additions and 62 deletions
|
@ -225,13 +225,13 @@
|
||||||
wordlist is substituted for %s. Sometimes one of the two
|
wordlist is substituted for %s. Sometimes one of the two
|
||||||
strings below is appended. -->
|
strings below is appended. -->
|
||||||
<string name="confirm_delete_dictf">Are you sure you want to
|
<string name="confirm_delete_dictf">Are you sure you want to
|
||||||
delete %s?</string>
|
delete the wordlist[s] %s?</string>
|
||||||
|
|
||||||
<!-- Additional text appended to text confirm_delete_dictf in the
|
<!-- Additional text appended to text confirm_delete_dictf in the
|
||||||
wordlist delete confiration dialog in the case where the
|
wordlist delete confiration dialog in the case where the
|
||||||
wordlist to be deleted is the last in its language. The name
|
wordlist to be deleted is the last in its language. The name
|
||||||
of the language is substituted for %s. -->
|
of the language is substituted for %s. -->
|
||||||
<string name="confirm_deleteonly_dictf">\u0020It is the only %s
|
<string name="confirm_deleteonly_dictf">%1$s is the only %2$s
|
||||||
wordlist installed. One or more games will be unopenable
|
wordlist installed. One or more games will be unopenable
|
||||||
without it.</string>
|
without it.</string>
|
||||||
<!-- Additional text appended to text confirm_delete_dictf in the
|
<!-- Additional text appended to text confirm_delete_dictf in the
|
||||||
|
@ -252,9 +252,9 @@
|
||||||
<!-- Used as the text fo the confirming/querying dialog that goes
|
<!-- Used as the text fo the confirming/querying dialog that goes
|
||||||
up when the dicts_item_select menuitem is chosen. The
|
up when the dicts_item_select menuitem is chosen. The
|
||||||
possible answers are the three button text strings below. -->
|
possible answers are the three button text strings below. -->
|
||||||
<string name="set_default_messagef">For what players should this
|
<string name="set_default_messagef">For what players should the
|
||||||
wordlist be the default for new games? (The language %s will be
|
wordlist %1$s be the default for new games? (The language %2$s will be
|
||||||
the default for both.)</string>
|
the default for both.)</string>
|
||||||
|
|
||||||
<!-- These three strings are the text for three buttons giving
|
<!-- These three strings are the text for three buttons giving
|
||||||
choices in respose to the dialog launched in response to the
|
choices in respose to the dialog launched in response to the
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
package org.eehouse.android.xw4;
|
package org.eehouse.android.xw4;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
@ -60,10 +61,9 @@ import org.eehouse.android.xw4.jni.GameSummary;
|
||||||
import org.eehouse.android.xw4.DictUtils.DictLoc;
|
import org.eehouse.android.xw4.DictUtils.DictLoc;
|
||||||
|
|
||||||
public class DictsActivity extends XWExpandableListActivity
|
public class DictsActivity extends XWExpandableListActivity
|
||||||
implements View.OnClickListener,
|
implements View.OnClickListener, AdapterView.OnItemLongClickListener,
|
||||||
AdapterView.OnItemLongClickListener,
|
SelectableItem, MountEventReceiver.SDCardNotifiee,
|
||||||
XWListItem.DeleteCallback, SelectableItem,
|
DlgDelegate.DlgClickNotify,
|
||||||
MountEventReceiver.SDCardNotifiee, DlgDelegate.DlgClickNotify,
|
|
||||||
DictImportActivity.DownloadFinishedListener {
|
DictImportActivity.DownloadFinishedListener {
|
||||||
|
|
||||||
private static interface SafePopup {
|
private static interface SafePopup {
|
||||||
|
@ -75,7 +75,6 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
private static final String DICT_LANG_EXTRA = "use_lang";
|
private static final String DICT_LANG_EXTRA = "use_lang";
|
||||||
private static final String DICT_NAME_EXTRA = "use_dict";
|
private static final String DICT_NAME_EXTRA = "use_dict";
|
||||||
private static final String PACKED_POSITION = "packed_position";
|
private static final String PACKED_POSITION = "packed_position";
|
||||||
private static final String DELETE_DICT = "delete_dict";
|
|
||||||
private static final String NAME = "name";
|
private static final String NAME = "name";
|
||||||
private static final String LANG = "lang";
|
private static final String LANG = "lang";
|
||||||
private static final String MOVEFROMLOC = "movefromloc";
|
private static final String MOVEFROMLOC = "movefromloc";
|
||||||
|
@ -96,7 +95,6 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
private int m_lang = 0;
|
private int m_lang = 0;
|
||||||
private String[] m_langs;
|
private String[] m_langs;
|
||||||
private String m_name = null;
|
private String m_name = null;
|
||||||
private String m_deleteDict = null;
|
|
||||||
private String m_download;
|
private String m_download;
|
||||||
private ExpandableListView m_expView;
|
private ExpandableListView m_expView;
|
||||||
private String[] m_locNames;
|
private String[] m_locNames;
|
||||||
|
@ -163,9 +161,6 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
DictLoc loc = dal.loc;
|
DictLoc loc = dal.loc;
|
||||||
view.setComment( m_locNames[loc.ordinal()] );
|
view.setComment( m_locNames[loc.ordinal()] );
|
||||||
view.cache( loc );
|
view.cache( loc );
|
||||||
if ( DictLoc.BUILT_IN != loc ) {
|
|
||||||
view.setDeleteCallback( DictsActivity.this );
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
view.setText( m_download );
|
view.setText( m_download );
|
||||||
}
|
}
|
||||||
|
@ -243,11 +238,8 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
|
|
||||||
protected XWListItem getSelChildView()
|
protected XWListItem getSelChildView()
|
||||||
{
|
{
|
||||||
int groupPosition =
|
Assert.assertTrue( 1 == m_selDicts.size() );
|
||||||
ExpandableListView.getPackedPositionGroup( m_packedPosition );
|
return m_selDicts.iterator().next();
|
||||||
int childPosition =
|
|
||||||
ExpandableListView.getPackedPositionChild( m_packedPosition );
|
|
||||||
return (XWListItem)getChildView( groupPosition, childPosition );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToCache( int group, int child, XWListItem view )
|
private void addToCache( int group, int child, XWListItem view )
|
||||||
|
@ -320,22 +312,22 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SET_DEFAULT:
|
case SET_DEFAULT:
|
||||||
|
final XWListItem row = m_selDicts.iterator().next();
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
if ( DialogInterface.BUTTON_NEGATIVE == item
|
if ( DialogInterface.BUTTON_NEGATIVE == item
|
||||||
|| DialogInterface.BUTTON_POSITIVE == item ) {
|
|| DialogInterface.BUTTON_POSITIVE == item ) {
|
||||||
setDefault( R.string.key_default_dict );
|
setDefault( row, R.string.key_default_dict );
|
||||||
}
|
}
|
||||||
if ( DialogInterface.BUTTON_NEGATIVE == item
|
if ( DialogInterface.BUTTON_NEGATIVE == item
|
||||||
|| DialogInterface.BUTTON_NEUTRAL == item ) {
|
|| DialogInterface.BUTTON_NEUTRAL == item ) {
|
||||||
setDefault( R.string.key_default_robodict );
|
setDefault( row, R.string.key_default_robodict );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
XWListItem rowView = m_adapter.getSelChildView();
|
String name = row.getText();
|
||||||
String lang =
|
String lang = DictLangCache.getLangName( this, name);
|
||||||
DictLangCache.getLangName( this, rowView.getText() );
|
message = getString( R.string.set_default_messagef, name, lang );
|
||||||
message = getString( R.string.set_default_messagef, lang );
|
|
||||||
dialog = new AlertDialog.Builder( this )
|
dialog = new AlertDialog.Builder( this )
|
||||||
.setTitle( R.string.query_title )
|
.setTitle( R.string.query_title )
|
||||||
.setMessage( message )
|
.setMessage( message )
|
||||||
|
@ -462,7 +454,6 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
outState.putLong( PACKED_POSITION, m_packedPosition );
|
outState.putLong( PACKED_POSITION, m_packedPosition );
|
||||||
outState.putString( NAME, m_name );
|
outState.putString( NAME, m_name );
|
||||||
outState.putInt( LANG, m_lang );
|
outState.putInt( LANG, m_lang );
|
||||||
outState.putString( DELETE_DICT, m_deleteDict );
|
|
||||||
if ( null != m_moveFromLoc ) {
|
if ( null != m_moveFromLoc ) {
|
||||||
outState.putInt( MOVEFROMLOC, m_moveFromLoc.ordinal() );
|
outState.putInt( MOVEFROMLOC, m_moveFromLoc.ordinal() );
|
||||||
}
|
}
|
||||||
|
@ -474,7 +465,6 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
m_packedPosition = savedInstanceState.getLong( PACKED_POSITION );
|
m_packedPosition = savedInstanceState.getLong( PACKED_POSITION );
|
||||||
m_name = savedInstanceState.getString( NAME );
|
m_name = savedInstanceState.getString( NAME );
|
||||||
m_lang = savedInstanceState.getInt( LANG );
|
m_lang = savedInstanceState.getInt( LANG );
|
||||||
m_deleteDict = savedInstanceState.getString( DELETE_DICT );
|
|
||||||
|
|
||||||
int tmp = savedInstanceState.getInt( MOVEFROMLOC, -1 );
|
int tmp = savedInstanceState.getInt( MOVEFROMLOC, -1 );
|
||||||
if ( -1 != tmp ) {
|
if ( -1 != tmp ) {
|
||||||
|
@ -521,6 +511,15 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu( Menu menu )
|
public boolean onPrepareOptionsMenu( Menu menu )
|
||||||
{
|
{
|
||||||
|
int nSel = m_selDicts.size();
|
||||||
|
Utils.setItemVisible( menu, R.id.dicts_download, 0 == nSel );
|
||||||
|
Utils.setItemVisible( menu, R.id.dicts_select, 1 == nSel );
|
||||||
|
|
||||||
|
boolean allVolatile = selItemsVolatile();
|
||||||
|
Utils.setItemVisible( menu, R.id.dicts_move,
|
||||||
|
allVolatile && DictUtils.haveWriteableSD() );
|
||||||
|
Utils.setItemVisible( menu, R.id.dicts_delete, allVolatile );
|
||||||
|
|
||||||
return super.onPrepareOptionsMenu( menu );
|
return super.onPrepareOptionsMenu( menu );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,12 +529,17 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
|
|
||||||
switch ( item.getItemId() ) {
|
switch ( item.getItemId() ) {
|
||||||
case R.id.dicts_download:
|
case R.id.dicts_download:
|
||||||
|
startDownload( 0, null );
|
||||||
|
break;
|
||||||
case R.id.dicts_delete:
|
case R.id.dicts_delete:
|
||||||
|
deleteSelected();
|
||||||
|
break;
|
||||||
case R.id.dicts_move:
|
case R.id.dicts_move:
|
||||||
|
break;
|
||||||
case R.id.dicts_select:
|
case R.id.dicts_select:
|
||||||
|
showDialog( SET_DEFAULT );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
handled = false;
|
handled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,9 +620,8 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDefault( int keyId )
|
private void setDefault( XWListItem view, int keyId )
|
||||||
{
|
{
|
||||||
XWListItem view = m_adapter.getSelChildView();
|
|
||||||
SharedPreferences sp
|
SharedPreferences sp
|
||||||
= PreferenceManager.getDefaultSharedPreferences( this );
|
= PreferenceManager.getDefaultSharedPreferences( this );
|
||||||
SharedPreferences.Editor editor = sp.edit();
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
|
@ -647,14 +650,29 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XWListItem.DeleteCallback interface
|
private boolean selItemsVolatile()
|
||||||
public void deleteCalled( XWListItem item )
|
|
||||||
{
|
{
|
||||||
String dict = item.getText();
|
boolean result = 0 < m_selDicts.size();
|
||||||
String msg = getString( R.string.confirm_delete_dictf, dict );
|
for ( Iterator<XWListItem> iter = m_selDicts.iterator();
|
||||||
|
result && iter.hasNext(); ) {
|
||||||
|
DictLoc loc = (DictLoc)iter.next().getCached();
|
||||||
|
if ( loc == DictLoc.BUILT_IN ) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
m_deleteDict = dict;
|
private void deleteSelected()
|
||||||
m_moveFromLoc = (DictLoc)item.getCached();
|
{
|
||||||
|
XWListItem[] items = getSelItems();
|
||||||
|
String[] names = new String[items.length];
|
||||||
|
int ii = 0;
|
||||||
|
for ( XWListItem item : items ) {
|
||||||
|
names[ii++] = item.getText();
|
||||||
|
}
|
||||||
|
String msg = getString( R.string.confirm_delete_dictf,
|
||||||
|
TextUtils.join( ", ", names ) );
|
||||||
|
|
||||||
// When and what to warn about. First off, if there's another
|
// When and what to warn about. First off, if there's another
|
||||||
// identical dict, simply confirm. Or if nobody's using this
|
// identical dict, simply confirm. Or if nobody's using this
|
||||||
|
@ -663,30 +681,35 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
// want different warnings depending on whether it's the last
|
// want different warnings depending on whether it's the last
|
||||||
// available dict in its language.
|
// available dict in its language.
|
||||||
|
|
||||||
if ( 1 < DictLangCache.getDictCount( this, dict ) ) {
|
for ( String dict : names ) {
|
||||||
// there's another; do nothing
|
if ( 1 < DictLangCache.getDictCount( this, dict ) ) {
|
||||||
} else {
|
// there's another; do nothing
|
||||||
int fmtid = 0;
|
} else {
|
||||||
int langcode = DictLangCache.getDictLangCode( this, dict );
|
String newMsg = null;
|
||||||
DictAndLoc[] langDals = DictLangCache.getDALsHaveLang( this,
|
int langcode = DictLangCache.getDictLangCode( this, dict );
|
||||||
langcode );
|
String langName = DictLangCache.getLangName( this, langcode );
|
||||||
int nUsingLang = DBUtils.countGamesUsingLang( this, langcode );
|
DictAndLoc[] langDals = DictLangCache.getDALsHaveLang( this,
|
||||||
|
langcode );
|
||||||
|
int nUsingLang = DBUtils.countGamesUsingLang( this, langcode );
|
||||||
|
|
||||||
if ( 1 == langDals.length ) { // last in this language?
|
if ( 1 == langDals.length ) { // last in this language?
|
||||||
if ( 0 < nUsingLang ) {
|
if ( 0 < nUsingLang ) {
|
||||||
fmtid = R.string.confirm_deleteonly_dictf;
|
newMsg = getString( R.string.confirm_deleteonly_dictf,
|
||||||
|
dict, langName );
|
||||||
|
}
|
||||||
|
} else if ( 0 < DBUtils.countGamesUsingDict( this, dict ) ) {
|
||||||
|
newMsg = getString( R.string.confirm_deletemore_dictf,
|
||||||
|
langName );
|
||||||
|
}
|
||||||
|
if ( null != newMsg ) {
|
||||||
|
msg += "\n\n" + newMsg;
|
||||||
}
|
}
|
||||||
} else if ( 0 < DBUtils.countGamesUsingDict( this, dict ) ) {
|
|
||||||
fmtid = R.string.confirm_deletemore_dictf;
|
|
||||||
}
|
|
||||||
if ( 0 != fmtid ) {
|
|
||||||
msg += getString( fmtid, DictLangCache.
|
|
||||||
getLangName( this, langcode ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showConfirmThen( msg, R.string.button_delete, DELETE_DICT_ACTION );
|
showConfirmThen( msg, R.string.button_delete, DELETE_DICT_ACTION,
|
||||||
}
|
(Object)items );
|
||||||
|
} // deleteSelected
|
||||||
|
|
||||||
// MountEventReceiver.SDCardNotifiee interface
|
// MountEventReceiver.SDCardNotifiee interface
|
||||||
public void cardMounted( boolean nowMounted )
|
public void cardMounted( boolean nowMounted )
|
||||||
|
@ -708,7 +731,13 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
switch( id ) {
|
switch( id ) {
|
||||||
case DELETE_DICT_ACTION:
|
case DELETE_DICT_ACTION:
|
||||||
if ( DialogInterface.BUTTON_POSITIVE == which ) {
|
if ( DialogInterface.BUTTON_POSITIVE == which ) {
|
||||||
deleteDict( m_deleteDict, m_moveFromLoc );
|
XWListItem[] items = (XWListItem[])params[0];
|
||||||
|
for ( XWListItem item : items ) {
|
||||||
|
String name = item.getText();
|
||||||
|
DictLoc loc = (DictLoc)item.getCached();
|
||||||
|
deleteDict( name, loc );
|
||||||
|
}
|
||||||
|
clearSelections();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -773,20 +802,27 @@ public class DictsActivity extends XWExpandableListActivity
|
||||||
private void clearSelections()
|
private void clearSelections()
|
||||||
{
|
{
|
||||||
if ( 0 < m_selDicts.size() ) {
|
if ( 0 < m_selDicts.size() ) {
|
||||||
XWListItem[] items = new XWListItem[m_selDicts.size()];
|
XWListItem[] items = getSelItems();
|
||||||
int indx = 0;
|
|
||||||
for ( Iterator<XWListItem> iter = m_selDicts.iterator();
|
|
||||||
iter.hasNext(); ) {
|
|
||||||
items[indx++] = iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_selDicts.clear();
|
m_selDicts.clear();
|
||||||
|
|
||||||
for ( XWListItem item : items ) {
|
for ( XWListItem item : items ) {
|
||||||
item.setSelected( false );
|
item.setSelected( false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private XWListItem[] getSelItems()
|
||||||
|
{
|
||||||
|
XWListItem[] items = new XWListItem[m_selDicts.size()];
|
||||||
|
int indx = 0;
|
||||||
|
for ( Iterator<XWListItem> iter = m_selDicts.iterator();
|
||||||
|
iter.hasNext(); ) {
|
||||||
|
items[indx++] = iter.next();
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
private void setTitleBar()
|
private void setTitleBar()
|
||||||
{
|
{
|
||||||
int nSels = m_selDicts.size();
|
int nSels = m_selDicts.size();
|
||||||
|
|
Loading…
Reference in a new issue