33 |
33 |
34 /** |
34 /** |
35 * Displays the list of all rooms in the lobby |
35 * Displays the list of all rooms in the lobby |
36 */ |
36 */ |
37 public class RoomlistFragment extends ListFragment implements OnItemClickListener { |
37 public class RoomlistFragment extends ListFragment implements OnItemClickListener { |
38 private static final int AUTO_REFRESH_INTERVAL_MS = 15000; |
38 private static final int AUTO_REFRESH_INTERVAL_MS = 15000; |
39 |
|
40 private Netplay netplay; |
|
41 private RoomlistAdapter adapter; |
|
42 private CountDownTimer autoRefreshTimer = new CountDownTimer(Long.MAX_VALUE, AUTO_REFRESH_INTERVAL_MS) { |
|
43 @Override |
|
44 public void onTick(long millisUntilFinished) { |
|
45 netplay.sendRoomlistRequest(); |
|
46 } |
|
47 |
|
48 @Override |
|
49 public void onFinish() { } |
|
50 }; |
|
51 |
39 |
52 @Override |
40 private Netplay netplay; |
53 public void onCreate(Bundle savedInstanceState) { |
41 private RoomlistAdapter adapter; |
54 super.onCreate(savedInstanceState); |
42 private CountDownTimer autoRefreshTimer = new CountDownTimer(Long.MAX_VALUE, AUTO_REFRESH_INTERVAL_MS) { |
55 netplay = Netplay.getAppInstance(getActivity().getApplicationContext()); |
43 @Override |
56 adapter = new RoomlistAdapter(getActivity()); |
44 public void onTick(long millisUntilFinished) { |
57 adapter.setSource(netplay.roomList); |
45 netplay.sendRoomlistRequest(); |
58 setListAdapter(adapter); |
46 } |
59 } |
|
60 |
47 |
61 @Override |
48 @Override |
62 public View onCreateView(LayoutInflater inflater, ViewGroup container, |
49 public void onFinish() { } |
63 Bundle savedInstanceState) { |
50 }; |
64 return inflater.inflate(R.layout.fragment_roomlist, container, false); |
51 |
65 } |
52 @Override |
66 |
53 public void onCreate(Bundle savedInstanceState) { |
67 @Override |
54 super.onCreate(savedInstanceState); |
68 public void onActivityCreated(Bundle savedInstanceState) { |
55 netplay = Netplay.getAppInstance(getActivity().getApplicationContext()); |
69 super.onActivityCreated(savedInstanceState); |
56 adapter = new RoomlistAdapter(getActivity()); |
70 getListView().setOnItemClickListener(this); |
57 adapter.setSource(netplay.roomList); |
71 } |
58 setListAdapter(adapter); |
72 |
59 } |
73 @Override |
60 |
74 public void onResume() { |
61 @Override |
75 super.onResume(); |
62 public View onCreateView(LayoutInflater inflater, ViewGroup container, |
76 autoRefreshTimer.start(); |
63 Bundle savedInstanceState) { |
77 } |
64 return inflater.inflate(R.layout.fragment_roomlist, container, false); |
78 |
65 } |
79 @Override |
66 |
80 public void onPause() { |
67 @Override |
81 super.onPause(); |
68 public void onActivityCreated(Bundle savedInstanceState) { |
82 autoRefreshTimer.cancel(); |
69 super.onActivityCreated(savedInstanceState); |
83 } |
70 getListView().setOnItemClickListener(this); |
84 |
71 } |
85 @Override |
72 |
86 public void onDestroy() { |
73 @Override |
87 super.onDestroy(); |
74 public void onResume() { |
88 adapter.invalidate(); |
75 super.onResume(); |
89 } |
76 autoRefreshTimer.start(); |
90 |
77 } |
91 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
78 |
92 netplay.sendJoinRoom(adapter.getItem(position).room.name); |
79 @Override |
93 } |
80 public void onPause() { |
|
81 super.onPause(); |
|
82 autoRefreshTimer.cancel(); |
|
83 } |
|
84 |
|
85 @Override |
|
86 public void onDestroy() { |
|
87 super.onDestroy(); |
|
88 adapter.invalidate(); |
|
89 } |
|
90 |
|
91 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
|
92 netplay.sendJoinRoom(adapter.getItem(position).room.name); |
|
93 } |
94 } |
94 } |