Commit
·
3f5eb73
1
Parent(s):
4e573d8
feature: update setting page to manage server url
Browse files- Android/app/build.gradle +0 -1
- Android/app/src/main/java/com/matthaigh27/chatgptwrapper/data/models/setting/SettingModel.kt +1 -0
- Android/app/src/main/java/com/matthaigh27/chatgptwrapper/data/remote/ApiClient.kt +41 -18
- Android/app/src/main/java/com/matthaigh27/chatgptwrapper/data/repository/RemoteRepository.kt +4 -1
- Android/app/src/main/java/com/matthaigh27/chatgptwrapper/ui/setting/view/SettingActivity.kt +5 -6
- Android/app/src/main/java/com/matthaigh27/chatgptwrapper/utils/helpers/chat/SettingHelper.kt +2 -0
- Android/app/src/main/res/layout/activity_setting.xml +12 -0
- Android/app/src/main/res/values/strings.xml +1 -0
Android/app/build.gradle
CHANGED
@@ -68,7 +68,6 @@ dependencies {
|
|
68 |
testImplementation 'org.testng:testng:6.9.6'
|
69 |
|
70 |
// Testing-only dependencies
|
71 |
-
androidTestImplementation "androidx.test:core:$rootProject.coreVersion"
|
72 |
androidTestImplementation "androidx.test.ext:junit:$rootProject.extJUnitVersion"
|
73 |
androidTestImplementation "androidx.test:runner:$rootProject.runnerVersion"
|
74 |
|
|
|
68 |
testImplementation 'org.testng:testng:6.9.6'
|
69 |
|
70 |
// Testing-only dependencies
|
|
|
71 |
androidTestImplementation "androidx.test.ext:junit:$rootProject.extJUnitVersion"
|
72 |
androidTestImplementation "androidx.test:runner:$rootProject.runnerVersion"
|
73 |
|
Android/app/src/main/java/com/matthaigh27/chatgptwrapper/data/models/setting/SettingModel.kt
CHANGED
@@ -5,6 +5,7 @@ import com.matthaigh27.chatgptwrapper.data.models.chat.HelpPromptModel
|
|
5 |
import com.matthaigh27.chatgptwrapper.data.remote.requests.common.OpenAISetting
|
6 |
|
7 |
data class SettingModel(
|
|
|
8 |
val openaiKey: String,
|
9 |
val pineconeEnv: String,
|
10 |
val pineconeKey: String,
|
|
|
5 |
import com.matthaigh27.chatgptwrapper.data.remote.requests.common.OpenAISetting
|
6 |
|
7 |
data class SettingModel(
|
8 |
+
val serverUrl: String,
|
9 |
val openaiKey: String,
|
10 |
val pineconeEnv: String,
|
11 |
val pineconeKey: String,
|
Android/app/src/main/java/com/matthaigh27/chatgptwrapper/data/remote/ApiClient.kt
CHANGED
@@ -1,31 +1,54 @@
|
|
1 |
package com.matthaigh27.chatgptwrapper.data.remote
|
2 |
|
3 |
-
import com.matthaigh27.chatgptwrapper.
|
4 |
import okhttp3.OkHttpClient
|
5 |
import retrofit2.Retrofit
|
6 |
import retrofit2.converter.gson.GsonConverterFactory
|
7 |
import java.util.concurrent.TimeUnit
|
8 |
|
9 |
-
|
|
|
|
|
|
|
10 |
val TIME_OUT_CALL = 60L
|
11 |
val TIME_OUT_CONNECT = 60L
|
12 |
val TIME_OUT_READ = 60L
|
13 |
val TIME_OUT_WRITE = 60L
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
.
|
27 |
-
.
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
}
|
|
|
1 |
package com.matthaigh27.chatgptwrapper.data.remote
|
2 |
|
3 |
+
import com.matthaigh27.chatgptwrapper.data.repository.SharedPreferencesRepository
|
4 |
import okhttp3.OkHttpClient
|
5 |
import retrofit2.Retrofit
|
6 |
import retrofit2.converter.gson.GsonConverterFactory
|
7 |
import java.util.concurrent.TimeUnit
|
8 |
|
9 |
+
class ApiClient {
|
10 |
+
/**
|
11 |
+
* This variables are used to set time for http communication.
|
12 |
+
*/
|
13 |
val TIME_OUT_CALL = 60L
|
14 |
val TIME_OUT_CONNECT = 60L
|
15 |
val TIME_OUT_READ = 60L
|
16 |
val TIME_OUT_WRITE = 60L
|
17 |
|
18 |
+
var apiService: ApiService
|
19 |
+
|
20 |
+
private var serverUrl: String
|
21 |
+
private var client: OkHttpClient
|
22 |
+
private var retrofit: Retrofit
|
23 |
+
|
24 |
+
init {
|
25 |
+
/**
|
26 |
+
* The server url is set to url that a user stored before.
|
27 |
+
* If the user run this app at first, server url is set to default url.
|
28 |
+
*/
|
29 |
+
val keys = SharedPreferencesRepository.getConfig()
|
30 |
+
serverUrl = keys.serverUrl
|
31 |
+
|
32 |
+
client = OkHttpClient
|
33 |
+
.Builder()
|
34 |
+
.callTimeout(TIME_OUT_CALL, TimeUnit.SECONDS)
|
35 |
+
.connectTimeout(TIME_OUT_CONNECT, TimeUnit.SECONDS)
|
36 |
+
.readTimeout(TIME_OUT_READ, TimeUnit.SECONDS)
|
37 |
+
.writeTimeout(TIME_OUT_WRITE, TimeUnit.SECONDS)
|
38 |
+
.build()
|
39 |
+
|
40 |
+
retrofit = Retrofit
|
41 |
+
.Builder()
|
42 |
+
.baseUrl(serverUrl)
|
43 |
+
.addConverterFactory(GsonConverterFactory.create())
|
44 |
+
.client(client)
|
45 |
+
.build()
|
46 |
+
|
47 |
+
apiService = retrofit.create(ApiService::class.java)
|
48 |
+
}
|
49 |
+
|
50 |
+
|
51 |
+
companion object {
|
52 |
+
val instance = ApiClient()
|
53 |
+
}
|
54 |
}
|
Android/app/src/main/java/com/matthaigh27/chatgptwrapper/data/repository/RemoteRepository.kt
CHANGED
@@ -30,8 +30,11 @@ import kotlin.coroutines.suspendCoroutine
|
|
30 |
|
31 |
|
32 |
object RemoteRepository {
|
33 |
-
private val apiService = ApiClient.apiService
|
34 |
|
|
|
|
|
|
|
35 |
fun getKeys(): Keys{
|
36 |
RoomRepository
|
37 |
val settingModel = SharedPreferencesRepository.getConfig()
|
|
|
30 |
|
31 |
|
32 |
object RemoteRepository {
|
33 |
+
private val apiService = ApiClient.instance.apiService
|
34 |
|
35 |
+
/**
|
36 |
+
* This function is used to get keys to manage backend.
|
37 |
+
*/
|
38 |
fun getKeys(): Keys{
|
39 |
RoomRepository
|
40 |
val settingModel = SharedPreferencesRepository.getConfig()
|
Android/app/src/main/java/com/matthaigh27/chatgptwrapper/ui/setting/view/SettingActivity.kt
CHANGED
@@ -20,6 +20,7 @@ class SettingActivity : BaseActivity() {
|
|
20 |
private val CONFIRM_MESSAGE = "Are you sure you want to set?"
|
21 |
|
22 |
private lateinit var txtPineconeKey: TextInputLayout
|
|
|
23 |
private lateinit var txtPineconeEnv: TextInputLayout
|
24 |
private lateinit var txtFirebaseKey: TextInputLayout
|
25 |
private lateinit var txtTemperature: TextInputLayout
|
@@ -37,6 +38,7 @@ class SettingActivity : BaseActivity() {
|
|
37 |
|
38 |
private fun init() {
|
39 |
txtPineconeKey = findViewById(R.id.txt_pinecone_key)
|
|
|
40 |
txtPineconeEnv = findViewById(R.id.txt_pinecone_env)
|
41 |
txtFirebaseKey = findViewById(R.id.txt_firebase_key)
|
42 |
txtTemperature = findViewById(R.id.txt_temperature)
|
@@ -63,6 +65,7 @@ class SettingActivity : BaseActivity() {
|
|
63 |
is ApiResource.Success -> {
|
64 |
resource.data?.let { data ->
|
65 |
txtPineconeKey.editText?.setText(data.pineconeKey)
|
|
|
66 |
txtPineconeEnv.editText?.setText(data.pineconeEnv)
|
67 |
txtFirebaseKey.editText?.setText(data.firebaseKey)
|
68 |
txtTemperature.editText?.setText(data.setting.temperature.toString())
|
@@ -100,17 +103,13 @@ class SettingActivity : BaseActivity() {
|
|
100 |
val firebaseKey = txtFirebaseKey.editText?.text.toString()
|
101 |
val temperature = txtTemperature.editText?.text.toString().toFloat()
|
102 |
val openaiKey = txtOpenAIKey.editText?.text.toString()
|
103 |
-
|
104 |
-
if (pineconeEnv == "" || pineconeKey == "" || firebaseKey == "" || openaiKey == ""){
|
105 |
-
showToast("Please fill out all the inputs")
|
106 |
-
return
|
107 |
-
}
|
108 |
-
|
109 |
|
110 |
val confirmDialog = ConfirmDialog(this)
|
111 |
confirmDialog.setOnClickListener(object : ConfirmDialog.OnDialogButtonClickListener {
|
112 |
override fun onPositiveButtonClick() {
|
113 |
val setting = SettingModel(
|
|
|
114 |
openaiKey = openaiKey,
|
115 |
pineconeEnv = pineconeEnv,
|
116 |
pineconeKey = pineconeKey,
|
|
|
20 |
private val CONFIRM_MESSAGE = "Are you sure you want to set?"
|
21 |
|
22 |
private lateinit var txtPineconeKey: TextInputLayout
|
23 |
+
private lateinit var txtServerUrl: TextInputLayout
|
24 |
private lateinit var txtPineconeEnv: TextInputLayout
|
25 |
private lateinit var txtFirebaseKey: TextInputLayout
|
26 |
private lateinit var txtTemperature: TextInputLayout
|
|
|
38 |
|
39 |
private fun init() {
|
40 |
txtPineconeKey = findViewById(R.id.txt_pinecone_key)
|
41 |
+
txtServerUrl = findViewById(R.id.txt_server_url)
|
42 |
txtPineconeEnv = findViewById(R.id.txt_pinecone_env)
|
43 |
txtFirebaseKey = findViewById(R.id.txt_firebase_key)
|
44 |
txtTemperature = findViewById(R.id.txt_temperature)
|
|
|
65 |
is ApiResource.Success -> {
|
66 |
resource.data?.let { data ->
|
67 |
txtPineconeKey.editText?.setText(data.pineconeKey)
|
68 |
+
txtServerUrl.editText?.setText(data.serverUrl)
|
69 |
txtPineconeEnv.editText?.setText(data.pineconeEnv)
|
70 |
txtFirebaseKey.editText?.setText(data.firebaseKey)
|
71 |
txtTemperature.editText?.setText(data.setting.temperature.toString())
|
|
|
103 |
val firebaseKey = txtFirebaseKey.editText?.text.toString()
|
104 |
val temperature = txtTemperature.editText?.text.toString().toFloat()
|
105 |
val openaiKey = txtOpenAIKey.editText?.text.toString()
|
106 |
+
val serverUrl: String = txtServerUrl.editText?.text.toString()
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
val confirmDialog = ConfirmDialog(this)
|
109 |
confirmDialog.setOnClickListener(object : ConfirmDialog.OnDialogButtonClickListener {
|
110 |
override fun onPositiveButtonClick() {
|
111 |
val setting = SettingModel(
|
112 |
+
serverUrl = serverUrl,
|
113 |
openaiKey = openaiKey,
|
114 |
pineconeEnv = pineconeEnv,
|
115 |
pineconeKey = pineconeKey,
|
Android/app/src/main/java/com/matthaigh27/chatgptwrapper/utils/helpers/chat/SettingHelper.kt
CHANGED
@@ -2,10 +2,12 @@ package com.matthaigh27.chatgptwrapper.utils.helpers.chat
|
|
2 |
|
3 |
import com.matthaigh27.chatgptwrapper.data.models.setting.SettingModel
|
4 |
import com.matthaigh27.chatgptwrapper.data.remote.requests.common.OpenAISetting
|
|
|
5 |
|
6 |
object SettingHelper {
|
7 |
fun emptySettingModel(): SettingModel{
|
8 |
return SettingModel(
|
|
|
9 |
openaiKey = "",
|
10 |
pineconeEnv = "",
|
11 |
pineconeKey = "",
|
|
|
2 |
|
3 |
import com.matthaigh27.chatgptwrapper.data.models.setting.SettingModel
|
4 |
import com.matthaigh27.chatgptwrapper.data.remote.requests.common.OpenAISetting
|
5 |
+
import com.matthaigh27.chatgptwrapper.utils.constants.CommonConstants.API_BASE_URL
|
6 |
|
7 |
object SettingHelper {
|
8 |
fun emptySettingModel(): SettingModel{
|
9 |
return SettingModel(
|
10 |
+
serverUrl = API_BASE_URL,
|
11 |
openaiKey = "",
|
12 |
pineconeEnv = "",
|
13 |
pineconeKey = "",
|
Android/app/src/main/res/layout/activity_setting.xml
CHANGED
@@ -64,6 +64,18 @@
|
|
64 |
|
65 |
</com.google.android.material.textfield.TextInputLayout>
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
<com.google.android.material.textfield.TextInputLayout
|
68 |
android:id="@+id/txt_openai_key"
|
69 |
style="@style/CommonEditText"
|
|
|
64 |
|
65 |
</com.google.android.material.textfield.TextInputLayout>
|
66 |
|
67 |
+
<com.google.android.material.textfield.TextInputLayout
|
68 |
+
android:id="@+id/txt_server_url"
|
69 |
+
style="@style/CommonEditText"
|
70 |
+
android:layout_marginBottom="@dimen/spacing_tiny"
|
71 |
+
android:hint="@string/label_setting_server_url">
|
72 |
+
|
73 |
+
<com.google.android.material.textfield.TextInputEditText
|
74 |
+
android:layout_width="match_parent"
|
75 |
+
android:layout_height="wrap_content" />
|
76 |
+
|
77 |
+
</com.google.android.material.textfield.TextInputLayout>
|
78 |
+
|
79 |
<com.google.android.material.textfield.TextInputLayout
|
80 |
android:id="@+id/txt_openai_key"
|
81 |
style="@style/CommonEditText"
|
Android/app/src/main/res/values/strings.xml
CHANGED
@@ -19,6 +19,7 @@
|
|
19 |
<string name="title_chat_widget_set_alarm">Set an alarm</string>
|
20 |
|
21 |
<string name="label_setting_uuid">uuid</string>
|
|
|
22 |
<string name="label_setting_openai_key">OpenAI Key</string>
|
23 |
<string name="label_setting_pinecone_key">Pinecone Key</string>
|
24 |
<string name="label_setting_pinecone_env">Pinecone Env</string>
|
|
|
19 |
<string name="title_chat_widget_set_alarm">Set an alarm</string>
|
20 |
|
21 |
<string name="label_setting_uuid">uuid</string>
|
22 |
+
<string name="label_setting_server_url">Server Url</string>
|
23 |
<string name="label_setting_openai_key">OpenAI Key</string>
|
24 |
<string name="label_setting_pinecone_key">Pinecone Key</string>
|
25 |
<string name="label_setting_pinecone_env">Pinecone Env</string>
|