Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f49f3c6

Browse files
committed
Better UI for chatbot
1 parent a143bd4 commit f49f3c6

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

app/src/main/java/com/example/nobulijava/activity/UserChatBotActivity.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@
3535
public class UserChatBotActivity extends AppCompatActivity implements BotReply {
3636

3737
RecyclerView chatView;
38-
MessageAdapter messageAdapter;
39-
List<MessageObj> messageList = new ArrayList<>();
4038
EditText editMessage;
4139
ImageButton btnSend;
4240

41+
MessageAdapter messageAdapter;
42+
List<MessageObj> messageList = new ArrayList<>();
43+
4344
//dialogFlow
4445
private SessionsClient sessionsClient;
4546
private SessionName sessionName;
@@ -53,8 +54,6 @@ protected void onCreate(Bundle savedInstanceState) {
5354

5455
getSupportActionBar().setTitle("Nobuli Chatbot");
5556

56-
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
57-
5857
chatView = findViewById(R.id.chatRecyclerView);
5958
editMessage = findViewById(R.id.messageBoxEditText);
6059
btnSend = findViewById(R.id.sendButton);
@@ -82,18 +81,6 @@ public void onClick(View view) {
8281
setUpBot();
8382
}
8483

85-
// @Override
86-
// public boolean onOptionsItemSelected(MenuItem item) {
87-
// switch (item.getItemId()) {
88-
// case android.R.id.home:
89-
// NavUtils.navigateUpFromSameTask(this);
90-
// return true;
91-
// default:
92-
// return super.onOptionsItemSelected(item);
93-
// }
94-
// }
95-
96-
9784
private void setUpBot() {
9885
try {
9986
InputStream stream = this.getResources().openRawResource(R.raw.credential);
@@ -126,7 +113,6 @@ public void callback(DetectIntentResponse returnResponse) {
126113
if (!botReply.isEmpty()) {
127114
messageList.add(new MessageObj(botReply, true));
128115
messageAdapter.notifyDataSetChanged();
129-
System.out.println("fuck");
130116
Objects.requireNonNull(chatView.getLayoutManager()).scrollToPosition(messageList.size() - 1);
131117
} else {
132118
Toast.makeText(this, "something went wrong", Toast.LENGTH_SHORT).show();

app/src/main/res/layout/template_message.xml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,35 @@
33
android:layout_width="match_parent"
44
android:layout_height="wrap_content"
55
android:orientation="vertical"
6-
android:padding="10dp">
6+
android:paddingTop="5dp"
7+
android:paddingBottom="5dp"
8+
android:paddingStart="10dp"
9+
android:paddingEnd="10dp">
710

811
<TextView
912
android:id="@+id/sendMessageTextView"
10-
android:layout_width="match_parent"
13+
android:layout_width="wrap_content"
1114
android:layout_height="wrap_content"
12-
android:layout_marginStart="30dp"
15+
android:layout_gravity="end"
1316
android:layout_marginBottom="5dp"
1417
android:background="@drawable/bg_message_send"
18+
android:maxWidth="320dp"
19+
android:text="Hi, this is a sample message."
1520
android:minHeight="50dp"
16-
android:padding="5dp"
21+
android:padding="10dp"
1722
android:textColor="@android:color/white"
1823
android:textSize="20sp" />
1924

2025
<TextView
2126
android:id="@+id/receiveMessageTextView"
22-
android:layout_width="match_parent"
27+
android:layout_width="wrap_content"
2328
android:layout_height="wrap_content"
24-
android:layout_marginEnd="30dp"
25-
android:layout_marginBottom="5dp"
29+
android:layout_gravity="start"
30+
android:text="Hi, this is a sample reply."
2631
android:background="@drawable/bg_message_receive"
32+
android:maxWidth="320dp"
2733
android:minHeight="50dp"
28-
android:padding="5dp"
34+
android:padding="10dp"
2935
android:textColor="@android:color/black"
3036
android:textSize="20sp">
3137

0 commit comments

Comments
 (0)