Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #26 from ttt246/feature/asset_popup_dialog_17
Browse files Browse the repository at this point in the history
feature(#22): update chat ui
  • Loading branch information
Thomas Richardson authored Jun 12, 2023
2 parents d07bb57 + d29c9ae commit 4620c6e
Show file tree
Hide file tree
Showing 37 changed files with 446 additions and 306 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ android {

buildTypes {
debug {
buildConfigField "String", "BASE_URL", "\"https://smartphone.herokuapp.com/\""
buildConfigField "String", "BASE_URL", "\"https://ttt246-brain.hf.space/\""
}
release {
// Use your desired server address for the release version
buildConfigField "String", "BASE_URL", "\"https://chatgptphone.herokuapp.com/\""
buildConfigField "String", "BASE_URL", "\"https://ttt246-brain.hf.space/\""

minifyEnabled true
shrinkResources true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.annotation.SuppressLint
import android.app.ActionBar.LayoutParams
import android.content.*
import android.graphics.Bitmap
import android.graphics.BitmapFactory
Expand All @@ -24,7 +23,6 @@ import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.animation.LinearInterpolator
import android.view.animation.RotateAnimation
import android.view.animation.TranslateAnimation
import android.widget.*
import androidx.annotation.RequiresApi
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -35,8 +33,8 @@ import com.matthaigh27.chatgptwrapper.R
import com.matthaigh27.chatgptwrapper.adapters.ChatAdapter
import com.matthaigh27.chatgptwrapper.database.MyDatabase
import com.matthaigh27.chatgptwrapper.database.entity.ImageEntity
import com.matthaigh27.chatgptwrapper.widgets.ImagePickerWidget
import com.matthaigh27.chatgptwrapper.widgets.ImagePickerWidget.OnPositiveButtonClickListener
import com.matthaigh27.chatgptwrapper.widgets.ChatToolsWidget
import com.matthaigh27.chatgptwrapper.widgets.ChatToolsWidget.OnPositiveButtonClickListener
import com.matthaigh27.chatgptwrapper.models.*
import com.matthaigh27.chatgptwrapper.models.common.HelpCommandModel
import com.matthaigh27.chatgptwrapper.models.common.HelpPromptModel
Expand Down Expand Up @@ -94,7 +92,7 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
* 'image_uplaod' when user is going to upload image
* 'image_picker' when user is going to pick image for prompting
*/
private lateinit var mImagePickerWidget: ImagePickerWidget
private lateinit var mChatToolsWidget: ChatToolsWidget
private var mImagePickerType: String = ""

/** HttpClient for restful apis */
Expand Down Expand Up @@ -207,7 +205,6 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
return@setOnKeyListener false
}

rootView.findViewById<View>(R.id.btn_send_message).setOnClickListener(this)
rootView.findViewById<View>(R.id.btn_image_upload).setOnClickListener(this)
rootView.findViewById<View>(R.id.btn_image_picker).setOnClickListener(this)

Expand Down Expand Up @@ -256,7 +253,6 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
private fun setDisableActivity(enable: Boolean) {
runOnUIThread {
mEtMessage.isEnabled = enable
rootView.findViewById<View>(R.id.btn_send_message).isEnabled = enable
rootView.findViewById<View>(R.id.btn_image_upload).isEnabled = enable
rootView.findViewById<View>(R.id.btn_image_picker).isEnabled = enable
}
Expand Down Expand Up @@ -507,10 +503,6 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {

override fun onClick(view: View) {
when (view.id) {
R.id.btn_send_message -> {
addMessage(mEtMessage.text.toString(), true)
}

R.id.btn_image_upload -> {
mImagePickerType = PICKERTYPE_IMAGE_UPLOAD
if(rootView.findViewById<View>(R.id.ll_toolbar).visibility == View.VISIBLE)
Expand Down Expand Up @@ -577,7 +569,7 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
* A picked image converts into bytearray data and upload to firebase storage.
*/
private fun initImagePickerWidget() {
mImagePickerWidget = ImagePickerWidget(mContext!!)
mChatToolsWidget = ChatToolsWidget(mContext!!)

val myImplementation = object : OnPositiveButtonClickListener {
override fun onPositiveBtnClick(isCamera: Boolean?) {
Expand Down Expand Up @@ -616,10 +608,10 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
}
}

mImagePickerWidget.setOnClickListener(myImplementation)
mChatToolsWidget.setOnClickListener(myImplementation)

val slidingWidget = rootView.findViewById<LinearLayout>(R.id.ll_toolbar)
slidingWidget.addView(mImagePickerWidget)
slidingWidget.addView(mChatToolsWidget)
}

private fun uploadSearchImage(imageByteArray: ByteArray) {
Expand Down Expand Up @@ -844,20 +836,18 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {

private fun showSlidingWidget() {
val slidingWidget = rootView.findViewById<View>(R.id.ll_toolbar)

val dy = slidingWidget.measuredHeight.toFloat()
slidingWidget.visibility = View.VISIBLE

val anim = TranslateAnimation(0f, 0f, dy, 0f).apply {
duration = 150 // Set the animation duration, e.g., 300ms
val anim = AlphaAnimation(0f, 1f).apply {
duration = 200 // Set the animation duration, e.g., 300ms
interpolator = AccelerateDecelerateInterpolator()
setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation?) {
override fun onAnimationStart(animation: Animation?) {}

override fun onAnimationEnd(animation: Animation?) {
slidingWidget.visibility = View.VISIBLE
}

override fun onAnimationEnd(animation: Animation?) {}

override fun onAnimationRepeat(animation: Animation?) {}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.matthaigh27.chatgptwrapper.widgets

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.matthaigh27.chatgptwrapper.R
import com.matthaigh27.chatgptwrapper.R.styleable.ChatToolLayout

class ChatToolItem(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {
private lateinit var mContext:Context
private lateinit var mIvToolIcon: ImageView
private lateinit var mTvToolName: TextView
private lateinit var mClToolIcon: ConstraintLayout

init {
initView(context, attrs)
}

private fun initView(context: Context, attrs: AttributeSet?) {
LayoutInflater.from(context).inflate(R.layout.item_chat_tool, this, true)

val layoutParams = LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT
)
val itemMargin = context.resources.getDimensionPixelSize(R.dimen.item_chat_tool_margin)
layoutParams.setMargins(itemMargin, itemMargin, itemMargin, itemMargin)
this.layoutParams = layoutParams

mContext = context
mIvToolIcon = findViewById(R.id.iv_chat_tool)
mClToolIcon = findViewById(R.id.cl_chat_tool)
mTvToolName = findViewById(R.id.tv_chat_tool_description)

}

fun setTool(drawableId: Int, size: Int, name: String) {
mIvToolIcon.setImageResource(drawableId)
mClToolIcon.layoutParams = LayoutParams(size, size)
mTvToolName.text = name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.matthaigh27.chatgptwrapper.widgets

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnClickListener
import android.view.ViewGroup
import android.widget.GridLayout
import android.widget.LinearLayout
import com.matthaigh27.chatgptwrapper.R


class ChatToolsWidget(context: Context) : LinearLayout(context), OnClickListener {

private lateinit var mClickListener: OnPositiveButtonClickListener
private lateinit var mGlTools: GridLayout
private var isInitFlag = true

val TOOL_ICONS = arrayOf(
R.drawable.ic_camera,
R.drawable.ic_gallery,
)

val TOOL_NAMES = arrayOf(
"Camera",
"Gallery"
)

val TOOL_COUNT = 2

init {
initView()
}

fun setOnClickListener(listener: OnPositiveButtonClickListener) {
mClickListener = listener
}

private fun initView() {
LayoutInflater.from(context).inflate(R.layout.view_chat_tools, this, true)

layoutParams = LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT
)

mGlTools = findViewById(R.id.gl_tools)

this.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
if (!isInitFlag) return@addOnLayoutChangeListener
isInitFlag = false

val width: Int = this.width

for (i in 0 until TOOL_COUNT) {
val cameraTool = ChatToolItem(context)
val itemMargin =
context.resources.getDimensionPixelSize(R.dimen.item_chat_tool_margin)
cameraTool.setTool(TOOL_ICONS[i], width / 4 - itemMargin * 2, TOOL_NAMES[i])
mGlTools.addView(cameraTool)

cameraTool.setTag(TOOL_NAMES[i])
cameraTool.setOnClickListener(this@ChatToolsWidget)
}
}
}

override fun onClick(view: View?) {
when (view?.tag) {
"Camera" -> {
mClickListener.onPositiveBtnClick(true)
}

"Gallery" -> {
mClickListener.onPositiveBtnClick(false)
}
}
}

/**
* callback function invoked when filepickerdialog buttons are pressed
*/
interface OnPositiveButtonClickListener {
fun onPositiveBtnClick(isCamera: Boolean?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HelpCommandEditText(context: Context) : EditText(context) {
context.resources.getDimensionPixelSize(R.dimen.view_help_prompt_edittext_fontsize)
.toFloat()
)
setTextColor(context.getColor(R.color.primary))
setTextColor(context.getColor(R.color.view_help_prompt_common_textcolor))
setHintTextColor(context.getColor(R.color.view_help_prompt_edittext_hint_color))
background = context.getDrawable(R.drawable.background_view_help_prompt_edittext)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
Expand Down Expand Up @@ -36,7 +37,7 @@ class HelpPromptWidget(context: Context, model: HelpPromptModel) : ConstraintLay
}

private fun initView() {
inflate(context, R.layout.view_help_prompt, this)
LayoutInflater.from(context).inflate(R.layout.view_help_prompt, this, true)

layoutParams = LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:width="@dimen/sms_button_stroke_width"
android:color="@color/sms_button_bgcolor" />
<corners android:radius="@dimen/sms_button_radius" />
</shape>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/view_help_prompt_edittext_bgcolor" />
<stroke
android:width="@dimen/view_help_prompt_edittext_stroke_width"
android:color="@color/view_help_prompt_edittext_stroke_color" />
<corners android:radius="@dimen/view_help_prompt_edittext_round_size" />
</shape>
</shape>
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/common_rounded_button_bgcolor" />
<corners android:radius="@dimen/control_button_common_radius" />
<corners android:radius="@dimen/control_common_button_radius" />
</shape>
6 changes: 3 additions & 3 deletions app/src/main/res/drawable/background_content_top.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/chat_content_top_bgcolor" />
<solid android:color="@color/chat_main_content_top_bgcolor" />
<corners
android:bottomLeftRadius="@dimen/chat_content_top_radius"
android:bottomRightRadius="@dimen/chat_content_top_radius" />
android:bottomLeftRadius="@dimen/chat_main_content_top_radius"
android:bottomRightRadius="@dimen/chat_main_content_top_radius" />
</shape>

This file was deleted.

Loading

0 comments on commit 4620c6e

Please sign in to comment.