mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
remember prev dict choice and use for longtap
Often I want to view a different wordlist from what's in use in the game. So make the in-board long-tap shortcut to a wordlist remember what the short-tap gesture chose most recently and use that instead of assuming the game's list is what's wanted. Remember the choice on a per-language rather than per-game basis.
This commit is contained in:
parent
e1712f4560
commit
677abe6fb8
2 changed files with 38 additions and 13 deletions
|
@ -1009,10 +1009,15 @@ public class BoardDelegate extends DelegateBase
|
|||
View button = m_toolbar.getButtonFor( Buttons.BUTTON_BROWSE_DICT );
|
||||
if ( Action.BUTTON_BROWSEALL_ACTION == action &&
|
||||
DictsDelegate.handleDictsPopup( getDelegator(), button,
|
||||
curDict, m_gi.dictLang ) ){
|
||||
break;
|
||||
curDict, m_gi.dictLang ) ) {
|
||||
// do nothing
|
||||
} else {
|
||||
String selDict = DictsDelegate.prevSelFor( m_activity, m_gi.dictLang );
|
||||
if ( null == selDict ) {
|
||||
selDict = curDict;
|
||||
}
|
||||
DictBrowseDelegate.launch( getDelegator(), selDict );
|
||||
}
|
||||
DictBrowseDelegate.launch( getDelegator(), curDict );
|
||||
break;
|
||||
case PREV_HINT_ACTION:
|
||||
cmd = JNICmd.CMD_PREV_HINT;
|
||||
|
|
|
@ -119,43 +119,52 @@ public class DictsDelegate extends ListDelegateBase
|
|||
|
||||
private static class SafePopupImpl implements SafePopup {
|
||||
public void doPopup( final Delegator dlgtor, View button,
|
||||
String curDict, int lang ) {
|
||||
String curDict, final int lang ) {
|
||||
|
||||
final HashMap<MenuItem, DictAndLoc> itemData
|
||||
= new HashMap<>();
|
||||
final Context context = dlgtor.getActivity();
|
||||
|
||||
MenuItem.OnMenuItemClickListener listener =
|
||||
new MenuItem.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick( MenuItem item )
|
||||
{
|
||||
DictAndLoc dal = itemData.get( item );
|
||||
|
||||
String prevKey = keyForLang( lang );
|
||||
DBUtils.setStringFor( context, prevKey, dal.name );
|
||||
DictBrowseDelegate.launch( dlgtor, dal.name,
|
||||
dal.loc );
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Context context = dlgtor.getActivity();
|
||||
String prevSel = prevSelFor( context, lang );
|
||||
PopupMenu popup = new PopupMenu( context, button );
|
||||
Menu menu = popup.getMenu();
|
||||
|
||||
// Add at top but save until have dal info
|
||||
MenuItem curItem =
|
||||
menu.add( LocUtils.getString( context,
|
||||
R.string.cur_menu_marker_fmt,
|
||||
curDict ) );
|
||||
|
||||
MenuItem curItem = addItem( menu,
|
||||
LocUtils.getString( context,
|
||||
R.string.cur_menu_marker_fmt,
|
||||
curDict ) );
|
||||
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( context, lang );
|
||||
for ( DictAndLoc dal : dals ) {
|
||||
MenuItem item = dal.name.equals(curDict)
|
||||
? curItem : menu.add( dal.name );
|
||||
boolean isCur = dal.name.equals(curDict);
|
||||
MenuItem item = isCur ? curItem : addItem( menu, dal.name );
|
||||
item.setOnMenuItemClickListener( listener );
|
||||
itemData.put( item, dal );
|
||||
item.setChecked( dal.name.equals(prevSel) );
|
||||
}
|
||||
menu.setGroupCheckable( FAKE_GROUP, true, true );
|
||||
|
||||
popup.show();
|
||||
}
|
||||
|
||||
private static final int FAKE_GROUP = 101;
|
||||
private MenuItem addItem(Menu menu, String name)
|
||||
{
|
||||
return menu.add( FAKE_GROUP, Menu.NONE, Menu.NONE, name );
|
||||
}
|
||||
}
|
||||
|
||||
private static class DictInfo implements Comparable, Serializable {
|
||||
|
@ -1120,6 +1129,17 @@ public class DictsDelegate extends ListDelegateBase
|
|||
return canHandle;
|
||||
}
|
||||
|
||||
private static String keyForLang(int lang)
|
||||
{
|
||||
return String.format( "%s:lang=%d", TAG, lang );
|
||||
}
|
||||
|
||||
static String prevSelFor( Context context, int lang )
|
||||
{
|
||||
String key = keyForLang( lang );
|
||||
return DBUtils.getStringFor( context, key, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DictsDelegate curThis()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue