diff --git a/xwords4/android/XWords4-dbg/res/layout/.gitignore b/xwords4/android/XWords4-dbg/res/layout/.gitignore index eda17ce81..878acc0fd 100644 --- a/xwords4/android/XWords4-dbg/res/layout/.gitignore +++ b/xwords4/android/XWords4-dbg/res/layout/.gitignore @@ -25,8 +25,6 @@ prefs_w_buttons.xml relay_game_config.xml rename_game.xml select_dialog_item.xml -btinviter_item.xml -btinviter.xml confirm_sms.xml game_list_group.xml smsinviter_item.xml @@ -49,3 +47,5 @@ fragact.xml main.xml dualcontainer.xml dict_browser_list.xml +inviter_item.xml +inviter.xml diff --git a/xwords4/android/XWords4/archive/R.java b/xwords4/android/XWords4/archive/R.java index e6b7777ee..01b693267 100644 --- a/xwords4/android/XWords4/archive/R.java +++ b/xwords4/android/XWords4/archive/R.java @@ -88,8 +88,8 @@ public final class R { } public static final class id { public static final int about_xlator=0x7f0c0001; - public static final int add_player=0x7f0c0037; - public static final int advertise_new_room_check=0x7f0c003e; + public static final int add_player=0x7f0c0031; + public static final int advertise_new_room_check=0x7f0c0038; public static final int blessed_label=0x7f0c005e; public static final int board_menu_chat=0x7f0c00a5; public static final int board_menu_dict=0x7f0c00a2; @@ -117,60 +117,60 @@ public final class R { public static final int board_menu_undo_last=0x7f0c0090; public static final int board_root=0x7f0c0002; public static final int board_view=0x7f0c0003; - public static final int boardsize_spinner=0x7f0c004a; + public static final int boardsize_spinner=0x7f0c0044; public static final int button_add=0x7f0c0078; - public static final int button_clear=0x7f0c000b; + public static final int button_clear=0x7f0c0054; public static final int button_done=0x7f0c0069; - public static final int button_invite=0x7f0c000c; - public static final int button_newgame_multi=0x7f0c004c; - public static final int button_newgame_solo=0x7f0c004b; - public static final int button_rescan=0x7f0c000a; + public static final int button_invite=0x7f0c0055; + public static final int button_newgame_multi=0x7f0c0046; + public static final int button_newgame_solo=0x7f0c0045; + public static final int button_rescan=0x7f0c0053; public static final int button_study=0x7f0c0068; - public static final int change_connection=0x7f0c0042; + public static final int change_connection=0x7f0c003c; public static final int chat_button=0x7f0c0084; - public static final int chat_edit=0x7f0c0011; - public static final int chat_history=0x7f0c0010; + public static final int chat_edit=0x7f0c000b; + public static final int chat_history=0x7f0c000a; public static final int chat_menu_clear=0x7f0c00a8; public static final int chat_menu_send=0x7f0c00a7; - public static final int chat_row_name=0x7f0c0013; - public static final int chat_row_text=0x7f0c0014; - public static final int chat_send=0x7f0c0012; + public static final int chat_row_name=0x7f0c000d; + public static final int chat_row_text=0x7f0c000e; + public static final int chat_send=0x7f0c000c; public static final int checkbox=0x7f0c0058; - public static final int color_display_sample=0x7f0c0015; - public static final int color_edit_sample=0x7f0c0016; - public static final int confirm_sms_reasons=0x7f0c001d; - public static final int conn_types=0x7f0c001e; - public static final int connect_set_relay=0x7f0c003a; - public static final int conns_label=0x7f0c0039; - public static final int default_check=0x7f0c001f; + public static final int color_display_sample=0x7f0c000f; + public static final int color_edit_sample=0x7f0c0010; + public static final int confirm_sms_reasons=0x7f0c0017; + public static final int conn_types=0x7f0c0018; + public static final int connect_set_relay=0x7f0c0034; + public static final int conns_label=0x7f0c0033; + public static final int default_check=0x7f0c0019; public static final int del=0x7f0c005b; - public static final int desc=0x7f0c0022; + public static final int desc=0x7f0c001c; public static final int details=0x7f0c0079; public static final int dict_label=0x7f0c0070; - public static final int dict_spinner=0x7f0c0034; + public static final int dict_spinner=0x7f0c002e; public static final int dictlist_button=0x7f0c0087; public static final int dicts_delete=0x7f0c00ab; public static final int dicts_deselect_all=0x7f0c00aa; public static final int dicts_download=0x7f0c00a9; public static final int dicts_move=0x7f0c00ac; public static final int dicts_select=0x7f0c00ad; - public static final int divider=0x7f0c002a; + public static final int divider=0x7f0c0024; public static final int download_button=0x7f0c007a; - public static final int dwnld_message=0x7f0c0056; + public static final int dwnld_message=0x7f0c0050; public static final int edit=0x7f0c006a; - public static final int edit_blue=0x7f0c001c; - public static final int edit_green=0x7f0c001a; - public static final int edit_red=0x7f0c0018; + public static final int edit_blue=0x7f0c0016; + public static final int edit_green=0x7f0c0014; + public static final int edit_red=0x7f0c0012; public static final int english_label=0x7f0c005c; public static final int english_view=0x7f0c005d; public static final int exchange_buttons=0x7f0c0004; public static final int exchange_cancel=0x7f0c0006; public static final int exchange_commit=0x7f0c0005; - public static final int expander=0x7f0c002d; + public static final int expander=0x7f0c0027; public static final int filters=0x7f0c0063; public static final int flip_button=0x7f0c0089; - public static final int game_locked_check=0x7f0c002f; - public static final int game_name=0x7f0c004d; + public static final int game_locked_check=0x7f0c0029; + public static final int game_name=0x7f0c0047; public static final int gamel_menu_checkmoves=0x7f0c0098; public static final int games_game_config=0x7f0c00b0; public static final int games_game_copy=0x7f0c00b5; @@ -206,18 +206,18 @@ public final class R { public static final int group_done=0x7f0c008a; public static final int group_exchange=0x7f0c009d; public static final int group_hint=0x7f0c009e; - public static final int hideable=0x7f0c0052; - public static final int hints_allowed=0x7f0c0043; - public static final int invite_desc=0x7f0c0009; - public static final int inviter_check=0x7f0c000d; + public static final int hideable=0x7f0c004c; + public static final int hints_allowed=0x7f0c003d; + public static final int invite_desc=0x7f0c0052; + public static final int inviter_check=0x7f0c0056; public static final int item_name=0x7f0c0074; public static final int item_score=0x7f0c0075; - public static final int join_public_room_check=0x7f0c003b; - public static final int juggle_players=0x7f0c0038; - public static final int label=0x7f0c002c; - public static final int lang_separator=0x7f0c0032; - public static final int lang_spinner=0x7f0c0033; - public static final int list_container=0x7f0c0029; + public static final int join_public_room_check=0x7f0c0035; + public static final int juggle_players=0x7f0c0032; + public static final int label=0x7f0c0026; + public static final int lang_separator=0x7f0c002c; + public static final int lang_spinner=0x7f0c002d; + public static final int list_container=0x7f0c0023; public static final int loc_item_check=0x7f0c00cd; public static final int loc_item_clear=0x7f0c00cc; public static final int loc_item_copy_bless=0x7f0c00cf; @@ -226,77 +226,77 @@ public final class R { public static final int loc_search_field=0x7f0c0064; public static final int local_label=0x7f0c0060; public static final int local_player_set=0x7f0c006e; - public static final int main_container=0x7f0c002b; + public static final int main_container=0x7f0c0025; public static final int manual_add_button=0x7f0c007c; - public static final int modtime=0x7f0c0053; + public static final int modtime=0x7f0c004d; public static final int msg=0x7f0c006b; - public static final int msg_marker=0x7f0c0050; + public static final int msg_marker=0x7f0c004a; public static final int name=0x7f0c007d; - public static final int name_edit=0x7f0c0020; + public static final int name_edit=0x7f0c001a; public static final int name_label=0x7f0c007b; public static final int nexthint_button=0x7f0c0083; public static final int not_again_check=0x7f0c006c; - public static final int nperdev_spinner=0x7f0c000e; + public static final int nperdev_spinner=0x7f0c0057; public static final int number=0x7f0c007e; public static final int other_lang=0x7f0c0066; public static final int password_edit=0x7f0c0073; public static final int password_set=0x7f0c0072; - public static final int phonies_spinner=0x7f0c0048; - public static final int pick_faceup=0x7f0c0049; + public static final int phonies_spinner=0x7f0c0042; + public static final int pick_faceup=0x7f0c0043; public static final int pick_lang=0x7f0c007f; public static final int pick_lang_spinner=0x7f0c0080; - public static final int play_button=0x7f0c0030; - public static final int player_list=0x7f0c0036; + public static final int play_button=0x7f0c002a; + public static final int player_list=0x7f0c0030; public static final int player_name_edit=0x7f0c006f; - public static final int players=0x7f0c002e; - public static final int players_label=0x7f0c0035; + public static final int players=0x7f0c0028; + public static final int players_label=0x7f0c002f; public static final int prevhint_button=0x7f0c0082; - public static final int private_rooms_set=0x7f0c003c; - public static final int progress_bar=0x7f0c0057; - public static final int public_rooms_set=0x7f0c003f; - public static final int refresh_button=0x7f0c0041; + public static final int private_rooms_set=0x7f0c0036; + public static final int progress_bar=0x7f0c0051; + public static final int public_rooms_set=0x7f0c0039; + public static final int refresh_button=0x7f0c003b; public static final int remote_check=0x7f0c006d; public static final int revert_all=0x7f0c0077; public static final int revert_colors=0x7f0c0076; public static final int robot_check=0x7f0c0071; - public static final int role=0x7f0c0055; - public static final int room_edit=0x7f0c003d; - public static final int room_spinner=0x7f0c0040; - public static final int screen=0x7f0c0031; - public static final int scroll=0x7f0c000f; - public static final int search=0x7f0c0023; - public static final int search_button=0x7f0c0025; - public static final int seek_blue=0x7f0c001b; - public static final int seek_green=0x7f0c0019; - public static final int seek_red=0x7f0c0017; - public static final int show_remote=0x7f0c0021; + public static final int role=0x7f0c004f; + public static final int room_edit=0x7f0c0037; + public static final int room_spinner=0x7f0c003a; + public static final int screen=0x7f0c002b; + public static final int scroll=0x7f0c0009; + public static final int search=0x7f0c001d; + public static final int search_button=0x7f0c001f; + public static final int seek_blue=0x7f0c0015; + public static final int seek_green=0x7f0c0013; + public static final int seek_red=0x7f0c0011; + public static final int show_remote=0x7f0c001b; public static final int shuffle_button=0x7f0c0085; - public static final int sizes=0x7f0c0026; + public static final int sizes=0x7f0c0020; public static final int slmenu_clear_sel=0x7f0c00d4; public static final int slmenu_copy_sel=0x7f0c00d3; public static final int slmenu_deselect_all=0x7f0c00d2; public static final int slmenu_lookup_sel=0x7f0c00d0; public static final int slmenu_select_all=0x7f0c00d1; - public static final int smart_robot=0x7f0c0047; - public static final int state=0x7f0c0054; + public static final int smart_robot=0x7f0c0041; + public static final int state=0x7f0c004e; public static final int summary=0x7f0c0067; public static final int tbar_parent_hor=0x7f0c0008; public static final int tbar_parent_vert=0x7f0c0007; public static final int text_item=0x7f0c0059; public static final int text_item2=0x7f0c005a; - public static final int thumbnail=0x7f0c0051; - public static final int timer_minutes_edit=0x7f0c0046; - public static final int timer_set=0x7f0c0045; + public static final int thumbnail=0x7f0c004b; + public static final int timer_minutes_edit=0x7f0c0040; + public static final int timer_set=0x7f0c003f; public static final int toolbar=0x7f0c0081; public static final int undo_button=0x7f0c0086; - public static final int use_timer=0x7f0c0044; + public static final int use_timer=0x7f0c003e; public static final int values_button=0x7f0c0088; public static final int version_string=0x7f0c0000; - public static final int view_loaded=0x7f0c004f; - public static final int view_unloaded=0x7f0c004e; - public static final int word_edit=0x7f0c0024; - public static final int wordlen_max=0x7f0c0028; - public static final int wordlen_min=0x7f0c0027; + public static final int view_loaded=0x7f0c0049; + public static final int view_unloaded=0x7f0c0048; + public static final int word_edit=0x7f0c001e; + public static final int wordlen_max=0x7f0c0022; + public static final int wordlen_min=0x7f0c0021; public static final int xlated_view=0x7f0c0062; public static final int xlated_view_blessed=0x7f0c005f; public static final int xlated_view_local=0x7f0c0061; @@ -304,28 +304,28 @@ public final class R { public static final class layout { public static final int about_dlg=0x7f030000; public static final int board=0x7f030001; - public static final int btinviter=0x7f030002; - public static final int btinviter_item=0x7f030003; - public static final int chat=0x7f030004; - public static final int chat_row=0x7f030005; - public static final int color_display=0x7f030006; - public static final int color_edit=0x7f030007; - public static final int confirm_sms=0x7f030008; - public static final int conn_types_display=0x7f030009; - public static final int dflt_name=0x7f03000a; - public static final int dict_browse=0x7f03000b; - public static final int dict_browser=0x7f03000c; - public static final int dict_browser_list=0x7f03000d; - public static final int divider_view=0x7f03000e; - public static final int dualcontainer=0x7f03000f; - public static final int expander_header=0x7f030010; - public static final int force_remote=0x7f030011; - public static final int game_config=0x7f030012; - public static final int game_list=0x7f030013; - public static final int game_list_group=0x7f030014; - public static final int game_list_item=0x7f030015; - public static final int import_dict=0x7f030016; - public static final int import_dict_item=0x7f030017; + public static final int chat=0x7f030002; + public static final int chat_row=0x7f030003; + public static final int color_display=0x7f030004; + public static final int color_edit=0x7f030005; + public static final int confirm_sms=0x7f030006; + public static final int conn_types_display=0x7f030007; + public static final int dflt_name=0x7f030008; + public static final int dict_browse=0x7f030009; + public static final int dict_browser=0x7f03000a; + public static final int dict_browser_list=0x7f03000b; + public static final int divider_view=0x7f03000c; + public static final int dualcontainer=0x7f03000d; + public static final int expander_header=0x7f03000e; + public static final int force_remote=0x7f03000f; + public static final int game_config=0x7f030010; + public static final int game_list=0x7f030011; + public static final int game_list_group=0x7f030012; + public static final int game_list_item=0x7f030013; + public static final int import_dict=0x7f030014; + public static final int import_dict_item=0x7f030015; + public static final int inviter=0x7f030016; + public static final int inviter_item=0x7f030017; public static final int list_group=0x7f030018; public static final int list_item=0x7f030019; public static final int loc_item_edit=0x7f03001a; diff --git a/xwords4/android/XWords4/res/layout/btinviter.xml b/xwords4/android/XWords4/res/layout/inviter.xml similarity index 100% rename from xwords4/android/XWords4/res/layout/btinviter.xml rename to xwords4/android/XWords4/res/layout/inviter.xml diff --git a/xwords4/android/XWords4/res/layout/btinviter_item.xml b/xwords4/android/XWords4/res/layout/inviter_item.xml similarity index 100% rename from xwords4/android/XWords4/res/layout/btinviter_item.xml rename to xwords4/android/XWords4/res/layout/inviter_item.xml diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTInviteDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTInviteDelegate.java index 7190166fc..0acdb5bc9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTInviteDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTInviteDelegate.java @@ -48,10 +48,6 @@ import java.util.Set; public class BTInviteDelegate extends InviteDelegate { private Activity m_activity; - private Set m_checked; - private Map m_counts; - private boolean m_setChecked; - private BTDevsAdapter m_adapter; public static void launchForResult( Activity activity, int nMissing, SentInvitesInfo info, @@ -71,16 +67,13 @@ public class BTInviteDelegate extends InviteDelegate { protected BTInviteDelegate( Delegator delegator, Bundle savedInstanceState ) { - super( delegator, savedInstanceState, R.layout.btinviter ); + super( delegator, savedInstanceState, R.layout.inviter ); m_activity = delegator.getActivity(); } @Override protected void init( Bundle savedInstanceState ) { - m_checked = new HashSet(); - m_counts = new HashMap(); - String msg = getString( R.string.bt_pick_addall_button ); msg = getQuantityString( R.plurals.invite_bt_desc_fmt, m_nMissing, m_nMissing, msg ); @@ -111,10 +104,13 @@ public class BTInviteDelegate extends InviteDelegate { } } - m_setChecked = null != btDevNames - && m_nMissing == btDevNames.length; - m_adapter = new BTDevsAdapter( btDevAddrs, btDevNames ); - setListAdapter( m_adapter ); + // m_setChecked = null != btDevNames + // && m_nMissing == btDevNames.length; + updateListAdapter( R.layout.inviter_item, + btDevNames, btDevAddrs, false ); + // m_adapter = new NameAddrDevsAdapter( BTInviteDelegate.this, + // btDevAddrs, btDevNames ); + // setListAdapter( m_adapter ); m_checked.clear(); tryEnable(); } @@ -139,126 +135,14 @@ public class BTInviteDelegate extends InviteDelegate { } } - protected void clearSelected() + @Override + protected void clearSelected( Integer[] itemIndices ) { String[][] selected = new String[1][]; listSelected( selected, null ); BTService.clearDevices( m_activity, selected[0] ); - } - protected void listSelected( String[][] devsP, int[][] countsP ) - { - int size = m_checked.size(); - int[] counts = null; - String[] devs = new String[size]; - devsP[0] = devs; - if ( null != countsP ) { - counts = new int[size]; - countsP[0] = counts; - } - - int nxt = 0; - for ( Iterator iter = m_checked.iterator(); - iter.hasNext(); ) { - LinearLayout layout = iter.next(); - CheckBox box = (CheckBox)layout.findViewById( R.id.inviter_check ); - String btAddr = (String)box.getTag(); - devs[nxt] = btAddr; - if ( null != counts ) { - counts[nxt] = m_counts.get( btAddr ); - } - ++nxt; - } - } - - protected void tryEnable() - { - String[][] devs = new String[1][]; - int[][] counts = new int[1][]; - listSelected( devs, counts ); - - m_clearButton.setEnabled( 0 < devs[0].length ); - - int count = 0; - for ( int one : counts[0] ) { - count += one; - } - m_okButton.setEnabled( 0 < count && count <= m_nMissing ); - } - - private class BTDevsAdapter extends XWListAdapter { - private String[] m_devAddrs; - private String[] m_devNames; - - public BTDevsAdapter( String[] btAddrs, String[] btNames ) - { - super( null == btAddrs? 0 : btAddrs.length ); - m_devAddrs = btAddrs; - m_devNames = btNames; - } - - public Object getItem( int position ) { return m_devNames[position]; } - - public View getView( int position, View convertView, ViewGroup parent ) { - final String btAddr = m_devAddrs[position]; - final LinearLayout layout = (LinearLayout)inflate( R.layout.btinviter_item ); - CheckBox box = (CheckBox)layout.findViewById( R.id.inviter_check ); - box.setText( m_devNames[position] ); - box.setTag( btAddr ); - - m_counts.put( btAddr, 1 ); - if ( XWPrefs.getCanInviteMulti( m_activity ) && 1 < m_nMissing ) { - Spinner spinner = (Spinner) - layout.findViewById(R.id.nperdev_spinner); - ArrayAdapter adapter = - new ArrayAdapter( m_activity, android.R.layout - .simple_spinner_item ); - for ( int ii = 1; ii <= m_nMissing; ++ii ) { - String str = getQuantityString( R.plurals.nplayers_fmt, ii, ii ); - adapter.add( str ); - } - spinner.setAdapter( adapter ); - spinner.setVisibility( View.VISIBLE ); - spinner.setOnItemSelectedListener( new OnItemSelectedListener() { - public void onItemSelected( AdapterView parent, - View view, int pos, - long id ) - { - m_counts.put( btAddr, 1 + pos ); - tryEnable(); - } - - public void onNothingSelected( AdapterView parent ) {} - } ); - } - - CompoundButton.OnCheckedChangeListener listener = - new CompoundButton.OnCheckedChangeListener() { - public void onCheckedChanged( CompoundButton buttonView, - boolean isChecked ) { - if ( isChecked ) { - m_checked.add( layout ); - } else { - m_checked.remove( layout ); - // User's now making changes; don't check new views - m_setChecked = false; - } - tryEnable(); - } - }; - box.setOnCheckedChangeListener( listener ); - - if ( m_setChecked || m_checked.contains( layout ) ) { - box.setChecked( true ); - } else if ( null != m_lastDev && m_lastDev.equals( btAddr ) ) { - m_lastDev = null; - box.setChecked( true ); - } - return layout; - } - - public String getBTAddr( CheckBox box ) { return (String)box.getTag(); } - public String getBTName( CheckBox box ) { return box.getText().toString(); } + // super.clearSelected( itemIndices ); } // DlgDelegate.DlgClickNotify interface diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java index cd1f44077..009611377 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java @@ -123,7 +123,6 @@ public class BoardDelegate extends DelegateBase private JNIUtils m_jniu; private boolean m_inTrade; // save this in bundle? private BoardUtilCtxt m_utils; - private int m_invitesPending; private boolean m_gameOver = false; // call startActivityForResult synchronously @@ -659,7 +658,8 @@ public class BoardDelegate extends DelegateBase } @Override - protected void onActivityResult( RequestCode requestCode, int resultCode, Intent data ) + protected void onActivityResult( RequestCode requestCode, int resultCode, + Intent data ) { if ( Activity.RESULT_CANCELED != resultCode ) { InviteMeans missingMeans = null; @@ -2422,7 +2422,6 @@ public class BoardDelegate extends DelegateBase } else if ( null != m_missingDevs ) { Assert.assertNotNull( m_missingMeans ); String gameName = GameUtils.getName( m_activity, m_rowid ); - m_invitesPending = m_missingDevs.length; for ( int ii = 0; ii < m_missingDevs.length; ++ii ) { String dev = m_missingDevs[ii]; int nPlayers = m_missingCounts[ii]; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java index 9c8f1f7af..8b3b675b7 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java @@ -80,7 +80,7 @@ public class ConnViaViewLayout extends LinearLayout { for ( CommsConnType typ : supported.getTypes() ) { LinearLayout item = (LinearLayout) - LocUtils.inflate( context, R.layout.btinviter_item ); + LocUtils.inflate( context, R.layout.inviter_item ); CheckBox box = (CheckBox)item.findViewById( R.id.inviter_check ); box.setText( typ.longName( context ) ); box.setChecked( m_curSet.contains( typ ) ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/InviteDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/InviteDelegate.java index 6a870086b..48c1522f5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/InviteDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/InviteDelegate.java @@ -25,9 +25,23 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.LinearLayout; import android.widget.ListView; +import android.widget.Spinner; import android.widget.TextView; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import junit.framework.Assert; abstract class InviteDelegate extends ListDelegateBase implements View.OnClickListener, @@ -40,12 +54,18 @@ abstract class InviteDelegate extends ListDelegateBase protected int m_nMissing; protected String m_lastDev; - protected Button m_okButton; + protected Button m_inviteButton; protected Button m_rescanButton; protected Button m_clearButton; private Activity m_activity; private ListView m_lv; private View m_ev; + private boolean m_showAddrs; + private InviteItemsAdapter m_adapter; + protected Map m_counts; + protected Set m_checked; + private boolean m_setChecked; + private LinearLayout[] m_items; public InviteDelegate( Delegator delegator, Bundle savedInstanceState, int layoutID ) @@ -55,17 +75,28 @@ abstract class InviteDelegate extends ListDelegateBase Intent intent = getIntent(); m_nMissing = intent.getIntExtra( INTENT_KEY_NMISSING, -1 ); m_lastDev = intent.getStringExtra( INTENT_KEY_LASTDEV ); + m_counts = new HashMap(); + m_checked = new HashSet(); + } + + protected void init( int button_invite, int desc_id, String descTxt ) + { + init( button_invite, 0, 0, desc_id, descTxt ); } protected void init( int button_invite, int button_rescan, int button_clear, int desc_id, String descTxt ) { - m_okButton = (Button)findViewById( button_invite ); - m_okButton.setOnClickListener( this ); - m_rescanButton = (Button)findViewById( button_rescan ); - m_rescanButton.setOnClickListener( this ); - m_clearButton = (Button)findViewById( button_clear ); - m_clearButton.setOnClickListener( this ); + m_inviteButton = (Button)findViewById( button_invite ); + m_inviteButton.setOnClickListener( this ); + if ( 0 != button_rescan ) { + m_rescanButton = (Button)findViewById( button_rescan ); + m_rescanButton.setOnClickListener( this ); + } + if ( 0 != button_clear ) { + m_clearButton = (Button)findViewById( button_clear ); + m_clearButton.setOnClickListener( this ); + } TextView descView = (TextView)findViewById( desc_id ); descView.setText( descTxt ); @@ -80,12 +111,20 @@ abstract class InviteDelegate extends ListDelegateBase tryEnable(); } + protected void updateListAdapter( int itemId, String[] names, String[] addrs, + boolean showAddrs ) + { + m_showAddrs = showAddrs; + m_adapter = new InviteItemsAdapter( itemId, names, addrs ); + setListAdapter( m_adapter ); + } + //////////////////////////////////////// // View.OnClickListener //////////////////////////////////////// public void onClick( View view ) { - if ( m_okButton == view ) { + if ( m_inviteButton == view ) { Intent intent = new Intent(); String[][] devs = new String[1][]; int[][] counts = new int[1][]; @@ -97,7 +136,7 @@ abstract class InviteDelegate extends ListDelegateBase } else if ( m_rescanButton == view ) { scan(); } else if ( m_clearButton == view ) { - clearSelected(); + clearSelected( makeCheckedArray() ); } } @@ -119,8 +158,167 @@ abstract class InviteDelegate extends ListDelegateBase ? View.VISIBLE : View.GONE ); } - abstract void tryEnable() ; - abstract void listSelected( String[][] devsP, int[][] countsP ); - abstract void scan(); - abstract void clearSelected(); + protected void listSelected( String[][] devsP, int[][] countsP ) + { + int[] counts = null; + int len = m_checked.size(); + Assert.assertTrue( 0 < len ); + + if ( null != countsP ) { + counts = new int[len]; + countsP[0] = counts; + } + + String[] checked = new String[len]; + Iterator iter = m_checked.iterator(); + for ( int ii = 0; iter.hasNext(); ++ii ) { + int index = iter.next(); + String addr = m_adapter.getAddrs()[index]; + Assert.assertNotNull( addr ); // fired!!! + checked[ii] = addr; + if ( null != counts ) { + counts[ii] = m_counts.get( addr ); + } + } + DbgUtils.logd( getClass(), "listSelected() adding %s", + checked.toString() ); + devsP[0] = checked; + } + + protected void tryEnable() + { + int count = m_checked.size(); + m_inviteButton.setEnabled( count > 0 && count <= m_nMissing ); + if ( null != m_clearButton ) { + m_clearButton.setEnabled( count > 0 ); + } + } + + protected void scan() {} + + protected void clearSelected( Integer[] itemIndices ) + { + for ( Iterator iter = m_checked.iterator(); + iter.hasNext(); ) { + int index = iter.next(); + LinearLayout item = m_items[index]; + CheckBox box = (CheckBox)item.findViewById( R.id.inviter_check ); + if ( null != box ) { + box.setChecked( false ); + } + m_checked.remove( iter ); + } + } + + // callbacks made by InviteItemsAdapter + + protected void onItemChecked( int index, boolean checked ) + { + DbgUtils.logd( getClass(), "onItemChecked(%d, %b)", index, checked ); + if ( checked ) { + m_checked.add( index ); + } else { + m_checked.remove( index ); + } + } + + protected InviteItemsAdapter getAdapter() + { + return m_adapter; + } + + private Integer[] makeCheckedArray() + { + return m_checked.toArray( new Integer[m_checked.size()] ); + } + + private class InviteItemsAdapter extends XWListAdapter { + private String[] m_devAddrs; + private String[] m_devNames; + private int m_itemId; + + public InviteItemsAdapter( int itemID, String[] names, String[] addrs ) + { + super( null == addrs? 0 : addrs.length ); + m_itemId = itemID; + m_devAddrs = addrs; + m_devNames = names; + m_items = new LinearLayout[getCount()]; + } + + public String[] getAddrs() { return m_devAddrs; } + + @Override + public Object getItem( int position ) { return m_devNames[position]; } + + @Override + public View getView( final int position, View convertView, + ViewGroup parent ) + { + final String addr = m_devAddrs[position]; + final LinearLayout layout = (LinearLayout)inflate( m_itemId ); + CheckBox box = (CheckBox)layout.findViewById( R.id.inviter_check ); + box.setText( m_devNames[position] ); + box.setTag( addr ); + + m_counts.put( addr, 1 ); + if ( XWPrefs.getCanInviteMulti( m_activity ) && 1 < m_nMissing ) { + Spinner spinner = (Spinner) + layout.findViewById(R.id.nperdev_spinner); + ArrayAdapter adapter = + new ArrayAdapter( m_activity, android.R.layout + .simple_spinner_item ); + for ( int ii = 1; ii <= m_nMissing; ++ii ) { + String str = getQuantityString( R.plurals.nplayers_fmt, ii, ii ); + adapter.add( str ); + } + spinner.setAdapter( adapter ); + spinner.setVisibility( View.VISIBLE ); + spinner.setOnItemSelectedListener( new OnItemSelectedListener() { + public void onItemSelected( AdapterView parent, + View view, int pos, + long id ) + { + m_counts.put( addr, 1 + pos ); + tryEnable(); + } + + public void onNothingSelected( AdapterView parent ) {} + } ); + } + + CompoundButton.OnCheckedChangeListener listener = + new CompoundButton.OnCheckedChangeListener() { + public void onCheckedChanged( CompoundButton buttonView, + boolean isChecked ) { + if ( !isChecked ) { + m_setChecked = false; + } + // if ( isChecked ) { + // m_checked.add( position ); + // } else { + // m_checked.remove( position ); + // // User's now making changes; don't check new views + // m_setChecked = false; + // } + onItemChecked( position, isChecked ); + + tryEnable(); + } + }; + box.setOnCheckedChangeListener( listener ); + + if ( m_setChecked || m_checked.contains( position ) ) { + box.setChecked( true ); + } else if ( null != m_lastDev && m_lastDev.equals( addr ) ) { + m_lastDev = null; + box.setChecked( true ); + } + m_items[position] = layout; + return layout; + } + + public String getAddr( CheckBox box ) { return (String)box.getTag(); } + public String getName( CheckBox box ) { return box.getText().toString(); } + } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayInviteDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayInviteDelegate.java index d4c86c411..a7b03df89 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayInviteDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayInviteDelegate.java @@ -191,7 +191,8 @@ public class RelayInviteDelegate extends InviteDelegate { // startActivityForResult( intent, GET_CONTACT ); } - protected void clearSelected() + @Override + protected void clearSelected( Integer[] selected ) { makeConfirmThenBuilder( R.string.confirm_clear_relay, Action.CLEAR_ACTION ) .show(); @@ -233,7 +234,7 @@ public class RelayInviteDelegate extends InviteDelegate { nPlayers += rec.m_nPlayers; } } - m_okButton.setEnabled( 0 < nPlayers && nPlayers <= m_nMissing ); + m_inviteButton.setEnabled( 0 < nPlayers && nPlayers <= m_nMissing ); m_clearButton.setEnabled( 0 < nDevs ); } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteDelegate.java index 3e25ba66c..f20185eb2 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteDelegate.java @@ -1,6 +1,6 @@ /* -*- compile-command: "find-and-ant.sh debug install"; -*- */ /* - * Copyright 2012 by Eric House (xwords@eehouse.org). All rights + * Copyright 2012 - 2016 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or @@ -56,7 +56,6 @@ public class SMSInviteDelegate extends InviteDelegate { private static final String SAVE_NUMBER = "SAVE_NUMBER"; private ArrayList m_phoneRecs; - private SMSPhonesAdapter m_adapter; private ImageButton m_addButton; private String m_pendingName; private String m_pendingNumber; @@ -104,10 +103,12 @@ public class SMSInviteDelegate extends InviteDelegate { rebuildList( true ); } + @Override protected void onSaveInstanceState( Bundle outState ) { outState.putString( SAVE_NAME, m_pendingName ); outState.putString( SAVE_NUMBER, m_pendingNumber ); + super.onSaveInstanceState( outState ); } private void getBundledData( Bundle bundle ) @@ -177,9 +178,10 @@ public class SMSInviteDelegate extends InviteDelegate { startActivityForResult( intent, RequestCode.GET_CONTACT ); } - protected void clearSelected() + @Override + protected void clearSelected( Integer[] checked ) { - int count = countChecks(); + int count = checked.length; String msg = getQuantityString( R.plurals.confirm_clear_sms_fmt, count, count ); makeConfirmThenBuilder( msg, Action.CLEAR_ACTION ).show(); @@ -187,7 +189,8 @@ public class SMSInviteDelegate extends InviteDelegate { protected void listSelected( String[][] devsP, int[][] countsP ) { - int count = m_adapter.getCount(); + XWListAdapter adapter = getAdapter(); + int count = adapter.getCount(); String[] result = new String[countChecks()]; int[] counts = new int[result.length]; @@ -197,7 +200,7 @@ public class SMSInviteDelegate extends InviteDelegate { PhoneRec rec = iter.next(); if ( rec.m_isChecked ) { counts[index] = rec.m_nPlayers; - result[index] = ((SMSListItem)m_adapter.getItem(ii)).getNumber(); + result[index] = ((SMSListItem)adapter.getItem(ii)).getNumber(); index++; } } @@ -221,7 +224,7 @@ public class SMSInviteDelegate extends InviteDelegate { nPlayers += rec.m_nPlayers; } } - m_okButton.setEnabled( 0 < nPlayers && nPlayers <= m_nMissing ); + m_inviteButton.setEnabled( 0 < nPlayers && nPlayers <= m_nMissing ); m_clearButton.setEnabled( 0 < nDevs ); } } @@ -320,14 +323,15 @@ public class SMSInviteDelegate extends InviteDelegate { return rec1.m_name.compareTo(rec2.m_name); } }); - m_adapter = new SMSPhonesAdapter(); - setListAdapter( m_adapter ); - if ( checkIfAll && m_phoneRecs.size() <= m_nMissing ) { - Iterator iter = m_phoneRecs.iterator(); - while ( iter.hasNext() ) { - iter.next().m_isChecked = true; - } + String[] phones = new String[m_phoneRecs.size()]; + String[] names = new String[m_phoneRecs.size()]; + for ( int ii = 0; ii < m_phoneRecs.size(); ++ii ) { + PhoneRec rec = m_phoneRecs.get( ii ); + phones[ii] = rec.m_phone; + names[ii] = rec.m_name; } + + updateListAdapter( R.layout.smsinviter_item, phones, names, true ); tryEnable(); } @@ -371,7 +375,8 @@ public class SMSInviteDelegate extends InviteDelegate { private void clearSelectedImpl() { - int count = m_adapter.getCount(); + XWListAdapter adapter = getAdapter(); + int count = adapter.getCount(); for ( int ii = count - 1; ii >= 0; --ii ) { if ( m_phoneRecs.get( ii ).m_isChecked ) { m_phoneRecs.remove( ii ); @@ -409,74 +414,4 @@ public class SMSInviteDelegate extends InviteDelegate { m_name = name; } } - - private class SMSPhonesAdapter extends XWListAdapter { - private SMSListItem[] m_items; - - public SMSPhonesAdapter() - { - super( m_phoneRecs.size() ); - m_items = new SMSListItem[m_phoneRecs.size()]; - } - - public Object getItem( final int position ) - { - // For some reason I can't cache items to be returned. - // Checking/unchecking breaks for some but not all items, - // with some relation to whether they were scrolled into - // view. So build them anew each time (but still cache - // for by-index access.) - - SMSListItem item = - (SMSListItem)inflate( R.layout.smsinviter_item ); - item.setChecked( m_phoneRecs.get(position).m_isChecked ); - - CompoundButton.OnCheckedChangeListener lstnr = - new CompoundButton.OnCheckedChangeListener() { - public void onCheckedChanged( CompoundButton bv, - boolean isChecked ) { - m_phoneRecs.get(position).m_isChecked = isChecked; - tryEnable(); - } - }; - item.setOnCheckedChangeListener( lstnr ); - final PhoneRec rec = m_phoneRecs.get( position ); - item.setContents( rec.m_name, rec.m_phone ); - m_items[position] = item; - - // Set up spinner - Assert.assertTrue( 1 == rec.m_nPlayers ); - if ( XWPrefs.getCanInviteMulti( m_activity ) && 1 < m_nMissing ) { - Spinner spinner = (Spinner) - item.findViewById(R.id.nperdev_spinner); - ArrayAdapter adapter = - new ArrayAdapter( m_activity, android.R.layout - .simple_spinner_item ); - for ( int ii = 1; ii <= m_nMissing; ++ii ) { - String str = getQuantityString( R.plurals.nplayers_fmt, ii, ii ); - adapter.add( str ); - } - spinner.setAdapter( adapter ); - spinner.setVisibility( View.VISIBLE ); - spinner.setOnItemSelectedListener( new OnItemSelectedListener() { - public void onItemSelected( AdapterView parent, - View view, int pos, - long id ) - { - rec.m_nPlayers = 1 + pos; - tryEnable(); - } - - public void onNothingSelected( AdapterView parent ) {} - } ); - } - - return item; - } - - public View getView( final int position, View convertView, - ViewGroup parent ) { - return (View)getItem( position ); - } - } }