-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
62 lines (48 loc) · 1.94 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.content.xchat_app;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import java.util.ArrayList;
import entity.User;
public class MainActivity extends AppCompatActivity {
private RecyclerView chatRV;
private EditText editSendMsg;
private ImageView btnSendMsg;
private ArrayList<Message> messages;
private MessageAdapter messageAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
User user = (User) intent.getSerializableExtra("user");
setContentView(R.layout.activity_main);
chatRV = findViewById(R.id.rv_chats);
editSendMsg = findViewById(R.id.edit_send_msg);
btnSendMsg = findViewById(R.id.send_logo);
messages = new ArrayList<Message>();
messageAdapter = new MessageAdapter(messages, this);
LinearLayoutManager manager = new LinearLayoutManager(this);
chatRV.setLayoutManager(manager);
chatRV.setAdapter(messageAdapter);
btnSendMsg.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
if(editSendMsg.getText().toString().isEmpty()){
Toast.makeText(MainActivity.this, "Please insert message", Toast.LENGTH_SHORT).show();
return;
}
messages.add(new Message( editSendMsg.getText().toString(), "currentUser"));
messageAdapter.notifyDataSetChanged();
editSendMsg.setText("");
}
});
}
}