mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
implement context menus for group items too, and add select/deselect
items for both -- for groups because there's no other way to select now. Still not sure how to educate users about the change or to provide a choice (if it's worth doing).
This commit is contained in:
parent
6aa994e2c6
commit
f29d302f06
10 changed files with 458 additions and 344 deletions
|
@ -8,4 +8,4 @@ studylist.xml
|
|||
loc_menu.xml
|
||||
empty.xml
|
||||
loc_item_menu.xml
|
||||
games_list_ctxt_menu.xml
|
||||
games_list_group_menu.xml
|
||||
|
|
File diff suppressed because it is too large
Load diff
25
xwords4/android/XWords4/res/menu/games_list_group_menu.xml
Normal file
25
xwords4/android/XWords4/res/menu/games_list_group_menu.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/games_group_moveup"
|
||||
android:title="@string/list_group_moveup"
|
||||
/>
|
||||
<item android:id="@+id/games_group_movedown"
|
||||
android:title="@string/list_group_movedown"
|
||||
/>
|
||||
<item android:id="@+id/games_group_delete"
|
||||
android:title="@string/list_group_delete"
|
||||
/>
|
||||
<item android:id="@+id/games_group_default"
|
||||
android:title="@string/list_group_default"
|
||||
/>
|
||||
<item android:id="@+id/games_group_rename"
|
||||
android:title="@string/list_group_rename"
|
||||
/>
|
||||
<item android:id="@+id/games_game_select"
|
||||
android:title="@string/list_item_select"
|
||||
/>
|
||||
<item android:id="@+id/games_game_deselect"
|
||||
android:title="@string/list_item_deselect"
|
||||
/>
|
||||
</menu>
|
|
@ -22,5 +22,10 @@
|
|||
<item android:id="@+id/games_game_copy"
|
||||
android:title="@string/list_item_copy"
|
||||
/>
|
||||
|
||||
<item android:id="@+id/games_game_select"
|
||||
android:title="@string/list_item_select"
|
||||
/>
|
||||
<item android:id="@+id/games_game_deselect"
|
||||
android:title="@string/list_item_deselect"
|
||||
/>
|
||||
</menu>
|
|
@ -2620,4 +2620,7 @@
|
|||
<string name="rel_invite_title">Relay invite title</string>
|
||||
<string name="fetching_from_relay">Fetching games from relay</string>
|
||||
<string name="processing_games">Processing games</string>
|
||||
|
||||
<string name="list_item_select">Select</string>
|
||||
<string name="list_item_deselect">De-select</string>
|
||||
</resources>
|
||||
|
|
|
@ -2239,4 +2239,6 @@
|
|||
<string name="rel_invite_title">Yaler etivni eltit</string>
|
||||
<string name="fetching_from_relay">Gnihctef semag morf yaler</string>
|
||||
<string name="processing_games">Gnissecorp semag</string>
|
||||
<string name="list_item_select">Tceles</string>
|
||||
<string name="list_item_deselect">Tceles-ed</string>
|
||||
</resources>
|
||||
|
|
|
@ -2239,4 +2239,6 @@
|
|||
<string name="rel_invite_title">RELAY INVITE TITLE</string>
|
||||
<string name="fetching_from_relay">FETCHING GAMES FROM RELAY</string>
|
||||
<string name="processing_games">PROCESSING GAMES</string>
|
||||
<string name="list_item_select">SELECT</string>
|
||||
<string name="list_item_deselect">DE-SELECT</string>
|
||||
</resources>
|
||||
|
|
|
@ -139,8 +139,11 @@ public class GameListGroup extends ExpiringLinearLayout
|
|||
//////////////////////////////////////////////////
|
||||
public boolean onLongClick( View view )
|
||||
{
|
||||
longClicked();
|
||||
return true;
|
||||
boolean handled = ! XWApp.CONTEXT_MENUS_ENABLED;
|
||||
if ( handled ) {
|
||||
longClicked();
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
|
|
@ -592,7 +592,6 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
private Button[] m_newGameButtons;
|
||||
private boolean m_haveShownGetDict;
|
||||
private Intent m_rematchIntent;
|
||||
private boolean m_longClickMenusEnabled = true;
|
||||
|
||||
public GamesListDelegate( ListDelegator delegator, Bundle sis )
|
||||
{
|
||||
|
@ -1056,7 +1055,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
// OnItemLongClickListener interface
|
||||
public boolean onItemLongClick( AdapterView<?> parent, View view,
|
||||
int position, long id ) {
|
||||
boolean success = ! m_longClickMenusEnabled
|
||||
boolean success = ! XWApp.CONTEXT_MENUS_ENABLED
|
||||
&& view instanceof SelectableItem.LongClickHandler;
|
||||
if ( success ) {
|
||||
((SelectableItem.LongClickHandler)view).longClicked();
|
||||
|
@ -1489,46 +1488,9 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
showToast( R.string.db_store_done );
|
||||
break;
|
||||
|
||||
// Group menus
|
||||
case R.id.games_group_delete:
|
||||
long dftGroup = XWPrefs.getDefaultNewGameGroup( m_activity );
|
||||
if ( m_selGroupIDs.contains( dftGroup ) ) {
|
||||
msg = getString( R.string.cannot_delete_default_group_fmt,
|
||||
m_adapter.groupName( dftGroup ) );
|
||||
showOKOnlyDialog( msg );
|
||||
} else {
|
||||
long[] groupIDs = getSelGroupIDs();
|
||||
Assert.assertTrue( 0 < groupIDs.length );
|
||||
msg = getQuantityString( R.plurals.groups_confirm_del_fmt,
|
||||
groupIDs.length, groupIDs.length );
|
||||
|
||||
int nGames = 0;
|
||||
for ( long tmp : groupIDs ) {
|
||||
nGames += m_adapter.getChildrenCount( tmp );
|
||||
}
|
||||
if ( 0 < nGames ) {
|
||||
msg += getQuantityString( R.plurals.groups_confirm_del_games_fmt,
|
||||
nGames, nGames );
|
||||
}
|
||||
showConfirmThen( msg, Action.DELETE_GROUPS, groupIDs );
|
||||
}
|
||||
break;
|
||||
case R.id.games_group_default:
|
||||
XWPrefs.setDefaultNewGameGroup( m_activity, groupID );
|
||||
break;
|
||||
case R.id.games_group_rename:
|
||||
m_groupid = groupID;
|
||||
showDialog( DlgID.RENAME_GROUP );
|
||||
break;
|
||||
case R.id.games_group_moveup:
|
||||
moveGroup( groupID, true );
|
||||
break;
|
||||
case R.id.games_group_movedown:
|
||||
moveGroup( groupID, false );
|
||||
break;
|
||||
|
||||
default:
|
||||
handled = handleSelGamesItem( itemID, selRowIDs );
|
||||
handled = handleSelGamesItem( itemID, selRowIDs )
|
||||
|| handleSelGroupsItem( itemID, getSelGroupIDs() );
|
||||
}
|
||||
|
||||
if ( changeContent ) {
|
||||
|
@ -1542,19 +1504,59 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
ContextMenuInfo menuInfo )
|
||||
{
|
||||
super.onCreateContextMenu( menu, view, menuInfo );
|
||||
m_activity.getMenuInflater()
|
||||
.inflate( R.menu.games_list_ctxt_menu, menu );
|
||||
|
||||
int id = 0;
|
||||
boolean selected = false;
|
||||
AdapterView.AdapterContextMenuInfo info
|
||||
= (AdapterView.AdapterContextMenuInfo)menuInfo;
|
||||
View targetView = info.targetView;
|
||||
DbgUtils.logf( "onCreateContextMenu(t=%s)",
|
||||
targetView.getClass().getName() );
|
||||
if ( targetView instanceof GameListItem ) {
|
||||
id = R.menu.games_list_item_menu;
|
||||
|
||||
long rowID = ((GameListItem)targetView).getRowID();
|
||||
selected = m_selGames.contains( rowID );
|
||||
} else if ( targetView instanceof GameListGroup ) {
|
||||
id = R.menu.games_list_group_menu;
|
||||
|
||||
long groupID = ((GameListGroup)targetView).getGroupID();
|
||||
selected = m_selGroupIDs.contains( groupID );
|
||||
} else {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
if ( 0 != id ) {
|
||||
m_activity.getMenuInflater().inflate( id, menu );
|
||||
|
||||
int hideId = selected
|
||||
? R.id.games_game_select : R.id.games_game_deselect;
|
||||
Utils.setItemVisible( menu, hideId, false );
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onContextItemSelected( MenuItem item )
|
||||
{
|
||||
boolean handled = true;
|
||||
AdapterView.AdapterContextMenuInfo info
|
||||
= (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
|
||||
GameListItem child = (GameListItem)info.targetView;
|
||||
View targetView = info.targetView;
|
||||
|
||||
long[] rowIDs = { child.getRowID() };
|
||||
return handleSelGamesItem( item.getItemId(), rowIDs )
|
||||
|| super.onContextItemSelected( item );
|
||||
int itemID = item.getItemId();
|
||||
if ( ! handleToggleItem( itemID, targetView ) ) {
|
||||
long[] selIds = new long[1];
|
||||
if ( targetView instanceof GameListItem ) {
|
||||
selIds[0] = ((GameListItem)targetView).getRowID();
|
||||
handled = handleSelGamesItem( itemID, selIds );
|
||||
} else if ( targetView instanceof GameListGroup ) {
|
||||
selIds[0] = ((GameListGroup)targetView).getGroupID();
|
||||
handled = handleSelGroupsItem( itemID, selIds );
|
||||
} else {
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
|
||||
return handled || super.onContextItemSelected( item );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -1602,6 +1604,24 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
private boolean handleToggleItem( int itemID, View target )
|
||||
{
|
||||
boolean handled;
|
||||
switch( itemID ) {
|
||||
case R.id.games_game_select:
|
||||
case R.id.games_game_deselect:
|
||||
SelectableItem.LongClickHandler toggled
|
||||
= (SelectableItem.LongClickHandler)target;
|
||||
toggled.longClicked();
|
||||
handled = true;
|
||||
break;
|
||||
default:
|
||||
handled = false;
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
private boolean handleSelGamesItem( int itemID, final long[] selRowIDs )
|
||||
{
|
||||
boolean handled = true;
|
||||
|
@ -1672,6 +1692,54 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
return handled;
|
||||
}
|
||||
|
||||
private boolean handleSelGroupsItem( int itemID, long[] groupIDs )
|
||||
{
|
||||
boolean handled = true;
|
||||
String msg;
|
||||
Assert.assertTrue( 0 < groupIDs.length );
|
||||
long groupID = groupIDs[0];
|
||||
switch( itemID ) {
|
||||
case R.id.games_group_delete:
|
||||
long dftGroup = XWPrefs.getDefaultNewGameGroup( m_activity );
|
||||
if ( m_selGroupIDs.contains( dftGroup ) ) {
|
||||
msg = getString( R.string.cannot_delete_default_group_fmt,
|
||||
m_adapter.groupName( dftGroup ) );
|
||||
showOKOnlyDialog( msg );
|
||||
} else {
|
||||
Assert.assertTrue( 0 < groupIDs.length );
|
||||
msg = getQuantityString( R.plurals.groups_confirm_del_fmt,
|
||||
groupIDs.length, groupIDs.length );
|
||||
|
||||
int nGames = 0;
|
||||
for ( long tmp : groupIDs ) {
|
||||
nGames += m_adapter.getChildrenCount( tmp );
|
||||
}
|
||||
if ( 0 < nGames ) {
|
||||
msg += getQuantityString( R.plurals.groups_confirm_del_games_fmt,
|
||||
nGames, nGames );
|
||||
}
|
||||
showConfirmThen( msg, Action.DELETE_GROUPS, groupIDs );
|
||||
}
|
||||
break;
|
||||
case R.id.games_group_default:
|
||||
XWPrefs.setDefaultNewGameGroup( m_activity, groupID );
|
||||
break;
|
||||
case R.id.games_group_rename:
|
||||
m_groupid = groupID;
|
||||
showDialog( DlgID.RENAME_GROUP );
|
||||
break;
|
||||
case R.id.games_group_moveup:
|
||||
moveGroup( groupID, true );
|
||||
break;
|
||||
case R.id.games_group_movedown:
|
||||
moveGroup( groupID, false );
|
||||
break;
|
||||
default:
|
||||
handled = false;
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
private void setupButtons()
|
||||
{
|
||||
boolean hidden = XWPrefs.getHideNewgameButtons( m_activity );
|
||||
|
|
|
@ -45,6 +45,7 @@ public class XWApp extends Application {
|
|||
public static final boolean UDP_ENABLED = true;
|
||||
public static final boolean SMS_INVITE_ENABLED = true;
|
||||
public static final boolean LOCUTILS_ENABLED = false;
|
||||
public static final boolean CONTEXT_MENUS_ENABLED = true;
|
||||
|
||||
public static final String SMS_PUBLIC_HEADER = "-XW4";
|
||||
public static final int MAX_TRAY_TILES = 7; // comtypes.h
|
||||
|
|
Loading…
Reference in a new issue