Commit e36ca70b authored by Mahima Induvara's avatar Mahima Induvara

UI Modified!

parent 673d890c
package chatbot package chatbot
import android.graphics.Color
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.example.archemistrylab.R import com.example.archemistrylab.R
import kotlinx.android.synthetic.main.listitem_chat.view.* import kotlinx.android.synthetic.main.listitem_chat.view.*
class AdapterChatBot : RecyclerView.Adapter<AdapterChatBot.MyViewHolder>() { class AdapterChatBot : RecyclerView.Adapter<AdapterChatBot.MyViewHolder>() {
private val list = ArrayList<ChatModel>() private val list = ArrayList<ChatModel>()
...@@ -17,13 +19,17 @@ class AdapterChatBot : RecyclerView.Adapter<AdapterChatBot.MyViewHolder>() { ...@@ -17,13 +19,17 @@ class AdapterChatBot : RecyclerView.Adapter<AdapterChatBot.MyViewHolder>() {
) { ) {
fun bind(chat: ChatModel) = with(itemView) { fun bind(chat: ChatModel) = with(itemView) {
if(!chat.isBot) { if(!chat.isBot) {
txtChat.setBackgroundColor(Color.WHITE)
txtChat.setTextColor(Color.BLACK)
txtChat.text = chat.chat txtChat.text = chat.chat
val textView1 = findViewById(R.id.txtChat) as TextView
val textView2 = findViewById(R.id.user_message) as TextView
textView1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_man,0,0,0)
textView2.setVisibility(View.GONE)
}else{ }else{
txtChat.setBackgroundColor(Color.YELLOW) val textView1 = findViewById(R.id.txtChat) as TextView
txtChat.setTextColor(Color.BLACK) val textView2 = findViewById(R.id.user_message) as TextView
txtChat.text = chat.chat textView2.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_bot,0,0,0)
textView1.setVisibility(View.GONE)
user_message.text = chat.chat
} }
} }
} }
......
package chatbot package chatbot
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.speech.RecognizerIntent
import android.widget.Button
import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.example.archemistrylab.R import com.example.archemistrylab.R
import com.google.android.material.floatingactionbutton.FloatingActionButton
import kotlinx.android.synthetic.main.activity_chatbot_main.* import kotlinx.android.synthetic.main.activity_chatbot_main.*
import org.w3c.dom.Text
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
import java.util.*
import kotlin.collections.ArrayList
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
lateinit var speechbtn: FloatingActionButton
lateinit var chat:TextView
private val adapterChatBot = AdapterChatBot() private val adapterChatBot = AdapterChatBot()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_chatbot_main) setContentView(R.layout.activity_chatbot_main)
val retrofit = Retrofit.Builder() val retrofit = Retrofit.Builder()
.baseUrl("http://192.168.8.101:5000") .baseUrl("http://192.168.1.101:5000/")
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.build() .build()
...@@ -29,6 +39,16 @@ class MainActivity : AppCompatActivity() { ...@@ -29,6 +39,16 @@ class MainActivity : AppCompatActivity() {
rvChatList.layoutManager = LinearLayoutManager(this) rvChatList.layoutManager = LinearLayoutManager(this)
rvChatList.adapter = adapterChatBot rvChatList.adapter = adapterChatBot
speechbtn=findViewById(R.id.speechbtn)
chat=findViewById(R.id.etChat)
speechbtn.setOnClickListener{
val intent =Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,Locale.getDefault())
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,"Say!")
startActivityForResult(intent,100)
}
btnSend.setOnClickListener { btnSend.setOnClickListener {
if(etChat.text.isNullOrEmpty()){ if(etChat.text.isNullOrEmpty()){
Toast.makeText(this@MainActivity, "Please enter a text", Toast.LENGTH_LONG).show() Toast.makeText(this@MainActivity, "Please enter a text", Toast.LENGTH_LONG).show()
...@@ -43,6 +63,15 @@ class MainActivity : AppCompatActivity() { ...@@ -43,6 +63,15 @@ class MainActivity : AppCompatActivity() {
} }
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode == 100 || data!=null){
val res : ArrayList<String> = data!!.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS) as ArrayList<String>
chat.text=res[0]
}
}
private val callBack = object : Callback<ChatResponse>{ private val callBack = object : Callback<ChatResponse>{
override fun onResponse(call: Call<ChatResponse>, response: Response<ChatResponse>) { override fun onResponse(call: Call<ChatResponse>, response: Response<ChatResponse>) {
if(response.isSuccessful && response.body()!= null){ if(response.isSuccessful && response.body()!= null){
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="0dp"
android:topRightRadius="20dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="chatbot.MainActivity"> tools:context="chatbot.MainActivity">
<LinearLayout
android:id="@+id/ll_layout_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#E4E4E4"
android:orientation="horizontal">
<EditText
android:id="@+id/etChat"
android:inputType="textShortMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight=".5"
android:background="@drawable/round_button"
android:backgroundTint="@android:color/white"
android:hint="Type a message..."
android:padding="10dp"
android:singleLine="true" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/speechbtn"
android:layout_width="56dp"
android:layout_height="56dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.791"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.988"
app:srcCompat="@drawable/ic_baseline_mic_24" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.98"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.988"
app:srcCompat="@drawable/ic_baseline_send_24" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvChatList" android:id="@+id/rvChatList"
android:layout_width="401dp" android:layout_width="match_parent"
android:layout_height="665dp" android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="@+id/etChat" android:layout_above="@id/ll_layout_bar"
app:layout_constraintEnd_toEndOf="parent" android:layout_below="@+id/dark_divider"
app:layout_constraintHorizontal_bias="1.0" tools:itemCount="20"
app:layout_constraintStart_toStartOf="parent" tools:listitem="@layout/listitem_chat" />
app:layout_constraintTop_toTopOf="parent" <View
app:layout_constraintVertical_bias="0.0" /> android:layout_width="match_parent"
android:layout_height="10dp"
<EditText android:background="#42A5F5"
android:id="@+id/etChat" android:id="@+id/dark_divider"/>
android:layout_width="245dp"
android:layout_height="60dp"
android:layout_marginStart="16dp" </RelativeLayout>
android:layout_marginEnd="8dp" \ No newline at end of file
android:ems="10"
android:hint="Chat with bot"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btnSend"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton2"
android:layout_width="56dp"
android:layout_height="56dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.791"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.988"
app:srcCompat="@drawable/ic_baseline_mic_24" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.98"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.988"
app:srcCompat="@drawable/ic_baseline_send_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="60dp" android:layout_height="wrap_content">
android:layout_gravity="end"
android:layout_margin="5dp"
android:elevation="8dp"
>
<LinearLayout android:layout_height="wrap_content" <TextView
android:layout_width="wrap_content" android:id="@+id/user_message"
android:orientation="horizontal" > android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_margin="4dp"
android:background="@drawable/send_round_box"
android:backgroundTint="#26A69A"
android:padding="14dp"
android:text=""
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView <TextView
android:visibility="visible"
android:id="@+id/txtChat" android:id="@+id/txtChat"
android:layout_width="match_parent" android:layout_width="200dp"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_margin="3dp" android:layout_alignParentStart="true"
android:gravity="center" android:layout_margin="4dp"
android:padding="3dp" android:background="@drawable/receive_round_box"
android:backgroundTint="#FF7043"
android:padding="14dp"
android:text="" android:text=""
android:textSize="18sp" /> android:textColor="@android:color/black"
android:textSize="14sp" />
<ImageView </RelativeLayout>
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_margin="10dp"
android:src="@drawable/ic_bot" />
</LinearLayout>
</androidx.cardview.widget.CardView>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment