@@ -40,12 +40,6 @@ public class ChatFragment extends BaseFragment {
40
40
private final Handler mTypingHandler = new Handler (Looper .getMainLooper ());
41
41
private boolean mTyping = false ;
42
42
43
- @ Override
44
- public void onAttach (@ NonNull Context context ) {
45
- super .onAttach (context );
46
- mAdapter = new ChatAdapter (this .mItems );
47
- }
48
-
49
43
@ Override
50
44
public void onCreate (Bundle savedInstanceState ) {
51
45
super .onCreate (savedInstanceState );
@@ -56,11 +50,12 @@ public void onCreate(Bundle savedInstanceState) {
56
50
mSocket .on (Socket .EVENT_CONNECT , this .onConnect );
57
51
mSocket .on (Socket .EVENT_DISCONNECT , this .onDisconnect );
58
52
mSocket .on (Socket .EVENT_CONNECT_ERROR , this .onConnectError );
59
- mSocket .on ("new message" , onNewMessage );
60
- mSocket .on ("user joined" , onUserJoined );
61
- mSocket .on ("user left" , onUserLeft );
62
- mSocket .on ("typing" , onTyping );
63
- mSocket .on ("stop typing" , onStopTyping );
53
+ mSocket .on ("new message" , this .onNewMessage );
54
+ mSocket .on ("private message" , this .onPrivateMessage );
55
+ mSocket .on ("user joined" , this .onUserJoined );
56
+ mSocket .on ("user left" , this .onUserLeft );
57
+ mSocket .on ("typing" , this .onTyping );
58
+ mSocket .on ("stop typing" , this .onStopTyping );
64
59
if (!mSocket .connected ()) {mSocket .connect ();}
65
60
}
66
61
}
@@ -71,17 +66,24 @@ public void onDestroy() {
71
66
mSocket .off (Socket .EVENT_CONNECT , this .onConnect );
72
67
mSocket .off (Socket .EVENT_DISCONNECT , this .onDisconnect );
73
68
mSocket .off (Socket .EVENT_CONNECT_ERROR , this .onConnectError );
74
- mSocket .off ("new message" , onNewMessage );
75
- mSocket .off ("user joined" , onUserJoined );
76
- mSocket .off ("user left" , onUserLeft );
77
- mSocket .off ("typing" , onTyping );
78
- mSocket .off ("stop typing" , onStopTyping );
69
+ mSocket .off ("new message" , this .onNewMessage );
70
+ mSocket .off ("private message" , this .onPrivateMessage );
71
+ mSocket .off ("user joined" , this .onUserJoined );
72
+ mSocket .off ("user left" , this .onUserLeft );
73
+ mSocket .off ("typing" , this .onTyping );
74
+ mSocket .off ("stop typing" , this .onStopTyping );
79
75
80
76
if (requireActivity () instanceof MainActivity activity ) {
81
77
leaveRoom (activity );
82
78
}
83
79
super .onDestroy ();
84
80
}
81
+
82
+ @ Override
83
+ public void onAttach (@ NonNull Context context ) {
84
+ super .onAttach (context );
85
+ this .mAdapter = new ChatAdapter (context , this .mItems );
86
+ }
85
87
86
88
@ Override
87
89
public View onCreateView (@ NonNull LayoutInflater inflater , ViewGroup parent , Bundle savedInstanceState ) {
@@ -231,6 +233,10 @@ private void scrollToBottom() {
231
233
addMessage (username , message );
232
234
});
233
235
236
+ private final Emitter .Listener onPrivateMessage = args -> requireActivity ().runOnUiThread (() -> {
237
+
238
+ });
239
+
234
240
private final Emitter .Listener onUserJoined = args -> requireActivity ().runOnUiThread (() -> {
235
241
JSONObject data = (JSONObject ) args [0 ];
236
242
String username ;
0 commit comments