From b5ff337381aa9b7fe40af29c162e23a061ba9bb5 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 12 Feb 2019 07:51:21 -0800 Subject: [PATCH] don't move selected games via context menu Both ways of invoking move-to-group were working on the set of selected games. Instead pass what's meant to be operated on as a parameter. --- .../android/xw4/GamesListDelegate.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index 0837dcb37..f5dd3a2bc 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -103,8 +103,8 @@ public class GamesListDelegate extends ListDelegateBase private static class MySIS implements Serializable { public MySIS(){ - selGames = new HashSet(); - selGroupIDs = new HashSet(); + selGames = new HashSet<>(); + selGroupIDs = new HashSet<>(); } int groupSelItem; boolean nextIsSolo; @@ -781,6 +781,7 @@ public class GamesListDelegate extends ListDelegateBase break; case CHANGE_GROUP: + final long[] games = (long[])params[0]; dialog = makeAlertBuilder() .setTitle( R.string.change_group ) .setSingleChoiceItems( m_adapter.groupNames(), @@ -800,7 +801,7 @@ public class GamesListDelegate extends ListDelegateBase long gid = m_adapter .getGroupIDFor( m_mySIS .groupSelItem ); - moveSelGamesTo( gid ); + moveSelGamesTo( games, gid ); } } ) .setNeutralButton( R.string.button_newgroup, @@ -1070,15 +1071,18 @@ public class GamesListDelegate extends ListDelegateBase // } } - private void moveSelGamesTo( long gid ) + private void moveSelGamesTo( long[] games, long gid ) { - for ( long rowid : m_mySIS.selGames ) { + boolean destOpen = DBUtils.getGroups( m_activity ).get( gid ).m_expanded; + for ( long rowid : games ) { DBUtils.moveGame( m_activity, rowid, gid ); + if ( !destOpen ) { + m_mySIS.selGames.remove( rowid ); + } } // Invalidate if there could have been change - if ( ! DBUtils.getGroups( m_activity ).get( gid ).m_expanded ) { - m_mySIS.selGames.clear(); + if ( ! destOpen ) { invalidateOptionsMenuIf(); setTitle(); } @@ -1808,7 +1812,7 @@ public class GamesListDelegate extends ListDelegateBase case R.id.games_game_move: m_mySIS.groupSelItem = -1; - showDialogFragment( DlgID.CHANGE_GROUP ); + showDialogFragment( DlgID.CHANGE_GROUP, selRowIDs ); break; case R.id.games_game_new_from: dropSels = true; // will select the new game instead @@ -2377,7 +2381,9 @@ public class GamesListDelegate extends ListDelegateBase { if ( m_mySIS.moveAfterNewGroup ) { m_mySIS.moveAfterNewGroup = false; - showDialogFragment( DlgID.CHANGE_GROUP ); + Long[] games = m_mySIS.selGames + .toArray( new Long[m_mySIS.selGames.size()] ); + showDialogFragment( DlgID.CHANGE_GROUP, (Object)games ); } }