37 /** |
37 /** |
38 * Shows the list of players in the lobby and allows some interactions with them |
38 * Shows the list of players in the lobby and allows some interactions with them |
39 * over the context menu. |
39 * over the context menu. |
40 */ |
40 */ |
41 public class LobbyPlayerlistFragment extends ListFragment { |
41 public class LobbyPlayerlistFragment extends ListFragment { |
42 private Netplay netplay; |
42 private Netplay netplay; |
43 private LobbyPlayerlistAdapter adapter; |
43 private LobbyPlayerlistAdapter adapter; |
44 |
|
45 @Override |
|
46 public void onCreate(Bundle savedInstanceState) { |
|
47 super.onCreate(savedInstanceState); |
|
48 netplay = Netplay.getAppInstance(getActivity().getApplicationContext()); |
|
49 adapter = new LobbyPlayerlistAdapter(); |
|
50 adapter.setSource(netplay.lobbyPlayerlist); |
|
51 setListAdapter(adapter); |
|
52 } |
|
53 |
44 |
54 @Override |
45 @Override |
55 public void onDestroy() { |
46 public void onCreate(Bundle savedInstanceState) { |
56 super.onDestroy(); |
47 super.onCreate(savedInstanceState); |
57 adapter.invalidate(); |
48 netplay = Netplay.getAppInstance(getActivity().getApplicationContext()); |
58 } |
49 adapter = new LobbyPlayerlistAdapter(); |
59 |
50 adapter.setSource(netplay.lobbyPlayerlist); |
60 @Override |
51 setListAdapter(adapter); |
61 public void onActivityCreated(Bundle savedInstanceState) { |
52 } |
62 super.onActivityCreated(savedInstanceState); |
|
63 registerForContextMenu(getListView()); |
|
64 } |
|
65 |
53 |
66 @Override |
54 @Override |
67 public void onCreateContextMenu(ContextMenu menu, View v, |
55 public void onDestroy() { |
68 ContextMenuInfo menuInfo) { |
56 super.onDestroy(); |
69 super.onCreateContextMenu(menu, v, menuInfo); |
57 adapter.invalidate(); |
70 AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo; |
58 } |
71 MenuInflater inflater = getActivity().getMenuInflater(); |
59 |
72 inflater.inflate(R.menu.lobby_playerlist_context, menu); |
60 @Override |
73 menu.setHeaderIcon(R.drawable.human); |
61 public void onActivityCreated(Bundle savedInstanceState) { |
74 menu.setHeaderTitle(adapter.getItem(info.position).name); |
62 super.onActivityCreated(savedInstanceState); |
75 } |
63 registerForContextMenu(getListView()); |
76 |
64 } |
77 @Override |
65 |
78 public boolean onContextItemSelected(MenuItem item) { |
66 @Override |
79 AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo(); |
67 public void onCreateContextMenu(ContextMenu menu, View v, |
80 Player player = adapter.getItem(info.position); |
68 ContextMenuInfo menuInfo) { |
81 switch(item.getItemId()) { |
69 super.onCreateContextMenu(menu, v, menuInfo); |
82 case R.id.player_info: |
70 AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo; |
83 netplay.sendPlayerInfoQuery(player.name); |
71 MenuInflater inflater = getActivity().getMenuInflater(); |
84 return true; |
72 inflater.inflate(R.menu.lobby_playerlist_context, menu); |
85 case R.id.player_follow: |
73 menu.setHeaderIcon(R.drawable.human); |
86 netplay.sendFollowPlayer(player.name); |
74 menu.setHeaderTitle(adapter.getItem(info.position).name); |
87 return true; |
75 } |
88 default: |
76 |
89 return super.onContextItemSelected(item); |
77 @Override |
90 } |
78 public boolean onContextItemSelected(MenuItem item) { |
91 } |
79 AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo(); |
92 |
80 Player player = adapter.getItem(info.position); |
93 @Override |
81 switch(item.getItemId()) { |
94 public View onCreateView(LayoutInflater inflater, ViewGroup container, |
82 case R.id.player_info: |
95 Bundle savedInstanceState) { |
83 netplay.sendPlayerInfoQuery(player.name); |
96 return inflater.inflate(R.layout.fragment_playerlist, container, false); |
84 return true; |
97 } |
85 case R.id.player_follow: |
|
86 netplay.sendFollowPlayer(player.name); |
|
87 return true; |
|
88 default: |
|
89 return super.onContextItemSelected(item); |
|
90 } |
|
91 } |
|
92 |
|
93 @Override |
|
94 public View onCreateView(LayoutInflater inflater, ViewGroup container, |
|
95 Bundle savedInstanceState) { |
|
96 return inflater.inflate(R.layout.fragment_playerlist, container, false); |
|
97 } |
98 } |
98 } |