diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index 7f9937f31..155274d96 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -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; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java index 1a4b03943..8e07eddc5 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java @@ -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 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() {