17 public static final String ARGUMENT_INROOM = "inRoom"; |
17 public static final String ARGUMENT_INROOM = "inRoom"; |
18 |
18 |
19 private ChatlogAdapter adapter; |
19 private ChatlogAdapter adapter; |
20 private Netplay netconn; |
20 private Netplay netconn; |
21 private MessageLog messageLog; |
21 private MessageLog messageLog; |
|
22 private boolean inRoom; |
|
23 |
|
24 public void setInRoom(boolean inRoom) { |
|
25 this.inRoom = inRoom; |
|
26 } |
22 |
27 |
23 @Override |
28 @Override |
24 public void onCreate(Bundle savedInstanceState) { |
29 public void onCreate(Bundle savedInstanceState) { |
25 super.onCreate(savedInstanceState); |
30 super.onCreate(savedInstanceState); |
26 |
|
27 Bundle bundle = getArguments(); |
|
28 netconn = Netplay.getAppInstance(getActivity().getApplicationContext()); |
31 netconn = Netplay.getAppInstance(getActivity().getApplicationContext()); |
29 adapter = new ChatlogAdapter(getActivity()); |
32 adapter = new ChatlogAdapter(getActivity()); |
30 messageLog = bundle.getBoolean(ARGUMENT_INROOM) ? netconn.roomChatlog : netconn.lobbyChatlog; |
33 } |
|
34 |
|
35 @Override |
|
36 public void onStart() { |
|
37 super.onStart(); |
|
38 messageLog = inRoom ? netconn.roomChatlog : netconn.lobbyChatlog; |
31 adapter.setLog(messageLog.getLog()); |
39 adapter.setLog(messageLog.getLog()); |
32 messageLog.registerObserver(adapter); |
40 messageLog.registerObserver(adapter); |
33 } |
41 } |
34 |
42 |
35 @Override |
43 @Override |
36 public void onStart() { |
44 public void onStop() { |
37 super.onStart(); |
45 super.onStop(); |
|
46 messageLog.unregisterObserver(adapter); |
38 } |
47 } |
39 |
48 |
40 @Override |
49 @Override |
41 public View onCreateView(LayoutInflater inflater, ViewGroup container, |
50 public View onCreateView(LayoutInflater inflater, ViewGroup container, |
42 Bundle savedInstanceState) { |
51 Bundle savedInstanceState) { |
52 editText.setOnEditorActionListener(new ChatSendListener()); |
61 editText.setOnEditorActionListener(new ChatSendListener()); |
53 |
62 |
54 return view; |
63 return view; |
55 } |
64 } |
56 |
65 |
57 @Override |
|
58 public void onDestroy() { |
|
59 super.onDestroy(); |
|
60 messageLog.unregisterObserver(adapter); |
|
61 } |
|
62 |
|
63 private final class ChatSendListener implements OnEditorActionListener { |
66 private final class ChatSendListener implements OnEditorActionListener { |
64 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
67 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
65 String text = v.getText().toString(); |
68 String text = v.getText().toString(); |
66 if(text.length()>0) { |
69 if(text.length()>0) { |
67 v.setText(""); |
70 v.setText(""); |