Commit e36ca70b authored by Mahima Induvara's avatar Mahima Induvara

UI Modified!

parent 673d890c
package chatbot
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.archemistrylab.R
import kotlinx.android.synthetic.main.listitem_chat.view.*
class AdapterChatBot : RecyclerView.Adapter<AdapterChatBot.MyViewHolder>() {
private val list = ArrayList<ChatModel>()
......@@ -17,13 +19,17 @@ class AdapterChatBot : RecyclerView.Adapter<AdapterChatBot.MyViewHolder>() {
) {
fun bind(chat: ChatModel) = with(itemView) {
if(!chat.isBot) {
txtChat.setBackgroundColor(Color.WHITE)
txtChat.setTextColor(Color.BLACK)
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{
txtChat.setBackgroundColor(Color.YELLOW)
txtChat.setTextColor(Color.BLACK)
txtChat.text = chat.chat
val textView1 = findViewById(R.id.txtChat) as TextView
val textView2 = findViewById(R.id.user_message) as TextView
textView2.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_bot,0,0,0)
textView1.setVisibility(View.GONE)
user_message.text = chat.chat
}
}
}
......
package chatbot
import android.content.Intent
import android.os.Bundle
import android.speech.RecognizerIntent
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.archemistrylab.R
import com.google.android.material.floatingactionbutton.FloatingActionButton
import kotlinx.android.synthetic.main.activity_chatbot_main.*
import org.w3c.dom.Text
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.*
import kotlin.collections.ArrayList
class MainActivity : AppCompatActivity() {
lateinit var speechbtn: FloatingActionButton
lateinit var chat:TextView
private val adapterChatBot = AdapterChatBot()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_chatbot_main)
val retrofit = Retrofit.Builder()
.baseUrl("http://192.168.8.101:5000")
.baseUrl("http://192.168.1.101:5000/")
.addConverterFactory(GsonConverterFactory.create())
.build()
......@@ -29,6 +39,16 @@ class MainActivity : AppCompatActivity() {
rvChatList.layoutManager = LinearLayoutManager(this)
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 {
if(etChat.text.isNullOrEmpty()){
Toast.makeText(this@MainActivity, "Please enter a text", Toast.LENGTH_LONG).show()
......@@ -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>{
override fun onResponse(call: Call<ChatResponse>, response: Response<ChatResponse>) {
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"?>
<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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="chatbot.MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvChatList"
android:layout_width="401dp"
android:layout_height="665dp"
app:layout_constraintBottom_toTopOf="@+id/etChat"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<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:layout_width="245dp"
android:layout_height="60dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
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" />
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/floatingActionButton2"
android:id="@+id/speechbtn"
android:layout_width="56dp"
android:layout_height="56dp"
android:clickable="true"
......@@ -57,5 +53,21 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.988"
app:srcCompat="@drawable/ic_baseline_send_24" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvChatList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/ll_layout_bar"
android:layout_below="@+id/dark_divider"
tools:itemCount="20"
tools:listitem="@layout/listitem_chat" />
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#42A5F5"
android:id="@+id/dark_divider"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</RelativeLayout>
\ No newline at end of file
<?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_height="60dp"
android:layout_gravity="end"
android:layout_margin="5dp"
android:elevation="8dp"
>
android:layout_height="wrap_content">
<LinearLayout android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/user_message"
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
android:visibility="visible"
android:id="@+id/txtChat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="3dp"
android:gravity="center"
android:padding="3dp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_margin="4dp"
android:background="@drawable/receive_round_box"
android:backgroundTint="#FF7043"
android:padding="14dp"
android:text=""
android:textSize="18sp" />
android:textColor="@android:color/black"
android:textSize="14sp" />
<ImageView
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_margin="10dp"
android:src="@drawable/ic_bot" />
</LinearLayout>
</RelativeLayout>
</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