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

Commit

Permalink
feature(#28): Update parsing module of Api Response
Browse files Browse the repository at this point in the history
  • Loading branch information
peterluo3131 committed Jun 13, 2023
1 parent 4620c6e commit 5d34a64
Show file tree
Hide file tree
Showing 41 changed files with 117 additions and 138 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.matthaigh27.chatgptwrapper"
minSdk 28
targetSdk 33
versionCode 7
versionName "1.5"
versionCode 1
versionName "1.6"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.Design.NoActionBar">
<activity
android:name=".activites.HomeActivity"
android:name=".ui.activites.HomeActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.matthaigh27.chatgptwrapper.database
package com.matthaigh27.chatgptwrapper.data.local

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.matthaigh27.chatgptwrapper.database.dao.ContactDao
import com.matthaigh27.chatgptwrapper.database.dao.ImageDao
import com.matthaigh27.chatgptwrapper.database.entity.ContactEntity
import com.matthaigh27.chatgptwrapper.database.entity.ImageEntity
import com.matthaigh27.chatgptwrapper.data.local.dao.ContactDao
import com.matthaigh27.chatgptwrapper.data.local.dao.ImageDao
import com.matthaigh27.chatgptwrapper.data.local.entity.ContactEntity
import com.matthaigh27.chatgptwrapper.data.local.entity.ImageEntity

@Database(entities = [ImageEntity::class, ContactEntity::class], version = 1, exportSchema = false)
abstract class MyDatabase : RoomDatabase() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.matthaigh27.chatgptwrapper.database.dao
package com.matthaigh27.chatgptwrapper.data.local.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.matthaigh27.chatgptwrapper.database.entity.ContactEntity
import com.matthaigh27.chatgptwrapper.data.local.entity.ContactEntity

@Dao
interface ContactDao {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.matthaigh27.chatgptwrapper.database.dao
package com.matthaigh27.chatgptwrapper.data.local.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.matthaigh27.chatgptwrapper.database.entity.ImageEntity
import com.matthaigh27.chatgptwrapper.data.local.entity.ImageEntity

@Dao
interface ImageDao {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.database.entity
package com.matthaigh27.chatgptwrapper.data.local.entity

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.database.entity
package com.matthaigh27.chatgptwrapper.data.local.entity

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.matthaigh27.chatgptwrapper.models.viewmodels
package com.matthaigh27.chatgptwrapper.data.models.common

import androidx.lifecycle.ViewModel

/**
* ChatModel for Chat RecyclerView
*/
class ChatMessageModel: ViewModel() {
class ChatMessageModel {
var message: String = ""
var isMe: Boolean = true
var image: ByteArray? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.models.common
package com.matthaigh27.chatgptwrapper.data.models.common

class ContactModel {
var id: String = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.models.common
package com.matthaigh27.chatgptwrapper.data.models.common

class HelpCommandModel {
var mainCommandName: String = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.models.common
package com.matthaigh27.chatgptwrapper.data.models.common

import com.google.gson.Gson
import com.google.gson.GsonBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.models.common
package com.matthaigh27.chatgptwrapper.data.models.common

class ImagePromptModel {
var id: String = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.models.requestmodels
package com.matthaigh27.chatgptwrapper.data.models.requestmodels

import com.matthaigh27.chatgptwrapper.MyApplication
import org.json.JSONException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.matthaigh27.chatgptwrapper.models.requestmodels
package com.matthaigh27.chatgptwrapper.data.models.requestmodels

import com.matthaigh27.chatgptwrapper.MyApplication
import com.matthaigh27.chatgptwrapper.models.common.ContactModel
import com.matthaigh27.chatgptwrapper.data.models.common.ContactModel
import com.matthaigh27.chatgptwrapper.utils.Utils
import org.json.JSONArray
import org.json.JSONException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.matthaigh27.chatgptwrapper.services.api
package com.matthaigh27.chatgptwrapper.data.remote

import android.util.Log
import com.matthaigh27.chatgptwrapper.BuildConfig
import com.matthaigh27.chatgptwrapper.models.common.ContactModel
import com.matthaigh27.chatgptwrapper.models.requestmodels.RequestBodyModel
import com.matthaigh27.chatgptwrapper.models.requestmodels.RequestTrainContactModel
import com.matthaigh27.chatgptwrapper.data.models.common.ContactModel
import com.matthaigh27.chatgptwrapper.data.models.requestmodels.RequestBodyModel
import com.matthaigh27.chatgptwrapper.data.models.requestmodels.RequestTrainContactModel
import com.matthaigh27.chatgptwrapper.utils.Constants
import com.matthaigh27.chatgptwrapper.utils.Constants.GET
import com.matthaigh27.chatgptwrapper.utils.Constants.POST
Expand All @@ -20,7 +20,7 @@ import org.json.JSONObject
import java.io.IOException
import java.util.concurrent.TimeUnit

class HttpClient {
class ApiClient {
/* Server URL and Api Endpoints */
val SERVER_URL = BuildConfig.BASE_URL
val SEND_NOTIFICATION_URL = SERVER_URL + "sendNotification"
Expand All @@ -29,9 +29,9 @@ class HttpClient {
val GET_ALL_HELP_COMMANDS = SERVER_URL + "commands"
val TRAIN_CONTACTS = SERVER_URL + "train/contacts"

var mCallback: HttpRisingInterface
var mCallback: ApiResponse

constructor(callback: HttpRisingInterface) {
constructor(callback: ApiResponse) {
mCallback = callback
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.matthaigh27.chatgptwrapper.data.remote;

interface ApiResponse {
fun onSuccessResult(msg: String)

fun onFailureResult(msg: String)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.activites
package com.matthaigh27.chatgptwrapper.ui.activites

import android.Manifest
import android.annotation.SuppressLint
Expand All @@ -10,8 +10,8 @@ import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.tabs.TabLayout.TabGravity
import com.matthaigh27.chatgptwrapper.R
import com.matthaigh27.chatgptwrapper.dialogs.CommonConfirmDialog
import com.matthaigh27.chatgptwrapper.fragments.ChatFragment
import com.matthaigh27.chatgptwrapper.ui.dialogs.CommonConfirmDialog
import com.matthaigh27.chatgptwrapper.ui.fragments.ChatFragment
import java.io.File


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.adapters
package com.matthaigh27.chatgptwrapper.ui.adapters

import android.annotation.SuppressLint
import android.app.Dialog
Expand All @@ -8,26 +8,23 @@ import android.graphics.BitmapFactory
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.matthaigh27.chatgptwrapper.R
import com.matthaigh27.chatgptwrapper.models.common.ContactModel
import com.matthaigh27.chatgptwrapper.models.common.HelpPromptModel
import com.matthaigh27.chatgptwrapper.models.viewmodels.ChatMessageModel
import com.matthaigh27.chatgptwrapper.data.models.common.HelpPromptModel
import com.matthaigh27.chatgptwrapper.data.models.common.ChatMessageModel
import com.matthaigh27.chatgptwrapper.utils.Constants.MSG_WIDGET_TYPE_HELP_PRMOPT
import com.matthaigh27.chatgptwrapper.utils.Constants.MSG_WIDGET_TYPE_SEARCH_CONTACT
import com.matthaigh27.chatgptwrapper.utils.Constants.MSG_WIDGET_TYPE_SMS
import com.matthaigh27.chatgptwrapper.utils.ImageHelper
import com.matthaigh27.chatgptwrapper.utils.Utils
import com.matthaigh27.chatgptwrapper.widgets.ContactDetailItem
import com.matthaigh27.chatgptwrapper.widgets.ContactDetailWidget
import com.matthaigh27.chatgptwrapper.widgets.HelpPromptWidget
import com.matthaigh27.chatgptwrapper.widgets.SearchContactWidget
import com.matthaigh27.chatgptwrapper.widgets.SmsEditorWidget
import com.matthaigh27.chatgptwrapper.ui.widgets.ContactDetailItem
import com.matthaigh27.chatgptwrapper.ui.widgets.HelpPromptWidget
import com.matthaigh27.chatgptwrapper.ui.widgets.SearchContactWidget
import com.matthaigh27.chatgptwrapper.ui.widgets.SmsEditorWidget
import org.json.JSONArray

class ChatAdapter(list: ArrayList<ChatMessageModel>, context: Context) :
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.dialogs
package com.matthaigh27.chatgptwrapper.ui.dialogs

import android.app.Dialog
import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.fragments
package com.matthaigh27.chatgptwrapper.ui.fragments

import android.os.Bundle
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -30,20 +30,20 @@ import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.storage.FirebaseStorage
import com.matthaigh27.chatgptwrapper.MyApplication
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.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
import com.matthaigh27.chatgptwrapper.models.viewmodels.ChatMessageModel
import com.matthaigh27.chatgptwrapper.services.api.HttpClient
import com.matthaigh27.chatgptwrapper.services.api.HttpRisingInterface
import com.matthaigh27.chatgptwrapper.ui.adapters.ChatAdapter
import com.matthaigh27.chatgptwrapper.data.local.MyDatabase
import com.matthaigh27.chatgptwrapper.data.local.entity.ImageEntity
import com.matthaigh27.chatgptwrapper.ui.widgets.ChatToolsWidget
import com.matthaigh27.chatgptwrapper.ui.widgets.ChatToolsWidget.OnPositiveButtonClickListener
import com.matthaigh27.chatgptwrapper.data.models.*
import com.matthaigh27.chatgptwrapper.data.models.common.HelpCommandModel
import com.matthaigh27.chatgptwrapper.data.models.common.HelpPromptModel
import com.matthaigh27.chatgptwrapper.data.models.common.ChatMessageModel
import com.matthaigh27.chatgptwrapper.data.remote.ApiClient
import com.matthaigh27.chatgptwrapper.data.remote.ApiResponse
import com.matthaigh27.chatgptwrapper.utils.Constants.*
import com.matthaigh27.chatgptwrapper.utils.Utils
import com.matthaigh27.chatgptwrapper.widgets.ContactDetailItem
import com.matthaigh27.chatgptwrapper.ui.widgets.ContactDetailItem
import com.qw.photo.CoCo
import com.qw.photo.callback.CoCoAdapter
import com.qw.photo.callback.CoCoCallBack
Expand All @@ -60,7 +60,7 @@ import java.io.*
import java.util.*
import kotlin.collections.ArrayList

class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
class ChatFragment : Fragment(), OnClickListener, ApiResponse {
private lateinit var rootView: View
private var mContext: Context? = null

Expand Down Expand Up @@ -95,8 +95,8 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
private lateinit var mChatToolsWidget: ChatToolsWidget
private var mImagePickerType: String = ""

/** HttpClient for restful apis */
private lateinit var httpClient: HttpClient
/** apiClient for restful apis */
private lateinit var apiClient: ApiClient

/** list of help prompt commands */
private var mHelpPromptList: ArrayList<HelpPromptModel>? = null
Expand Down Expand Up @@ -132,14 +132,14 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
initView()
initDatabase()

trainImages()
// trainImages()
getAllPromptCommands()
}


private fun getAllPromptCommands() {
showLoading(true, "Loading Help Prompt Data")
httpClient.getALlHelpPromptCommands()
apiClient.getALlHelpPromptCommands()
}


Expand All @@ -151,7 +151,7 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
private fun initValues() {
mContext = context

httpClient = HttpClient(this)
apiClient = ApiClient(this)

rotate.duration = 3000
rotate.repeatCount = Animation.INFINITE
Expand Down Expand Up @@ -494,9 +494,9 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {

showLoading(visible = true, text = LOADING_ASKING_TO_GPT)
if (msg.image != null) {
httpClient.callImageRelatedness(msg.imageName)
apiClient.callImageRelatedness(msg.imageName)
} else {
httpClient.callSendNotification(message)
apiClient.callSendNotification(message)
}
}
}
Expand Down Expand Up @@ -652,7 +652,7 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
Log.d(TAG, "Success upload to firebase storage")

showLoading(false)
httpClient.callImageUpload("$uuid")
apiClient.callImageUpload("$uuid")
}
}

Expand Down Expand Up @@ -807,7 +807,7 @@ class ChatFragment : Fragment(), OnClickListener, HttpRisingInterface {
val contacts = Utils.instance.getContacts(mContext!!)
CoroutineScope(Dispatchers.Main).launch {
val changedContacts = Utils.instance.getChangedContacts(contacts, mRoomDataHandler)
httpClient.trainContacts(changedContacts)
apiClient.trainContacts(changedContacts)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.widgets
package com.matthaigh27.chatgptwrapper.ui.widgets

import android.content.Context
import android.util.AttributeSet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.widgets
package com.matthaigh27.chatgptwrapper.ui.widgets

import android.content.Context
import android.view.LayoutInflater
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.widgets
package com.matthaigh27.chatgptwrapper.ui.widgets

import android.content.ContentUris
import android.content.Context
Expand All @@ -14,7 +14,7 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.matthaigh27.chatgptwrapper.R
import com.matthaigh27.chatgptwrapper.models.common.ContactModel
import com.matthaigh27.chatgptwrapper.data.models.common.ContactModel

class ContactDetailItem(
context: Context, attrs: AttributeSet? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matthaigh27.chatgptwrapper.widgets
package com.matthaigh27.chatgptwrapper.ui.widgets

import android.content.ContentUris
import android.content.Context
Expand All @@ -14,7 +14,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.forEach
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.matthaigh27.chatgptwrapper.R
import com.matthaigh27.chatgptwrapper.models.common.ContactModel
import com.matthaigh27.chatgptwrapper.data.models.common.ContactModel
import com.matthaigh27.chatgptwrapper.utils.Utils

class ContactDetailWidget(
Expand Down
Loading

0 comments on commit 5d34a64

Please sign in to comment.