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

Commit

Permalink
feature: update setting page
Browse files Browse the repository at this point in the history
  • Loading branch information
peterluo3131 committed Jul 14, 2023
1 parent 689c7ae commit 3301d8b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ class ApiClient {
val TIME_OUT_READ = 60L
val TIME_OUT_WRITE = 60L

var apiService: ApiService
lateinit var apiService: ApiService

private var serverUrl: String
private var client: OkHttpClient
private var retrofit: Retrofit
private lateinit var serverUrl: String
private lateinit var client: OkHttpClient
private lateinit var retrofit: Retrofit

init {
initClient()
}

fun initClient() {
/**
* The server url is set to url that a user stored before.
* If the user run this app at first, server url is set to default url.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import kotlin.coroutines.suspendCoroutine


object RemoteRepository {
private val apiService = ApiClient.instance.apiService

/**
* This function is used to get keys to manage backend.
*/
Expand All @@ -54,7 +52,7 @@ object RemoteRepository {
onSuccess: OnSuccess<ApiResponse<HelpCommandResult>>,
onFailure: OnFailure<String>
) {
val call = apiService.getAllHelpCommands(BaseApiRequest(getKeys()))
val call = ApiClient.instance.apiService.getAllHelpCommands(BaseApiRequest(getKeys()))

call.enqueue(object : Callback<ApiResponse<HelpCommandResult>> {
override fun onResponse(call: Call<ApiResponse<HelpCommandResult>>, response: Response<ApiResponse<HelpCommandResult>>) {
Expand All @@ -76,7 +74,7 @@ object RemoteRepository {
onSuccess: OnSuccess<ApiResponse<CommonResult>>,
onFailure: OnFailure<String>
) {
val call = apiService.sendNotification(request)
val call = ApiClient.instance.apiService.sendNotification(request)

call.enqueue(object : Callback<ApiResponse<CommonResult>> {
override fun onResponse(call: Call<ApiResponse<CommonResult>>, response: Response<ApiResponse<CommonResult>>) {
Expand All @@ -98,7 +96,7 @@ object RemoteRepository {
onSuccess: OnSuccess<ApiResponse<String>>,
onFailure: OnFailure<String>
) {
val call = apiService.trainContacts(request)
val call = ApiClient.instance.apiService.trainContacts(request)

call.enqueue(object : Callback<ApiResponse<String>> {
override fun onResponse(
Expand All @@ -119,7 +117,7 @@ object RemoteRepository {

suspend fun trainImage(request: TrainImageApiRequest) : ApiResource<ApiResponse<TrainImageResult>> = suspendCoroutine { continuation ->

val call = apiService.trainImage(request)
val call = ApiClient.instance.apiService.trainImage(request)

call.enqueue(object : Callback<ApiResponse<TrainImageResult>> {
override fun onResponse(
Expand All @@ -143,7 +141,7 @@ object RemoteRepository {
onSuccess: OnSuccess<ApiResponse<ImageRelatenessResult>>,
onFailure: OnFailure<String>
) {
val call = apiService.getImageRelatedness(request)
val call = ApiClient.instance.apiService.getImageRelatedness(request)

call.enqueue(object : Callback<ApiResponse<ImageRelatenessResult>> {
override fun onResponse(
Expand All @@ -167,7 +165,7 @@ object RemoteRepository {
onSuccess: OnSuccess<ApiResponse<ArrayList<MailModel>>>,
onFailure: OnFailure<String>
) {
val call = apiService.readEmails(request)
val call = ApiClient.instance.apiService.readEmails(request)

call.enqueue(object : Callback<ApiResponse<ArrayList<MailModel>>> {
override fun onResponse(
Expand All @@ -191,7 +189,7 @@ object RemoteRepository {
onSuccess: OnSuccess<ApiResponse<String>>,
onFailure: OnFailure<String>
) {
val call = apiService.sendEmail(request)
val call = ApiClient.instance.apiService.sendEmail(request)

call.enqueue(object : Callback<ApiResponse<String>> {
override fun onResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.matthaigh27.chatgptwrapper.data.repository
import android.content.Context
import com.matthaigh27.chatgptwrapper.RisingApplication.Companion.appContext
import com.matthaigh27.chatgptwrapper.data.models.setting.SettingModel
import com.matthaigh27.chatgptwrapper.data.remote.ApiClient
import com.matthaigh27.chatgptwrapper.utils.helpers.chat.SettingHelper.emptySettingModel

object SharedPreferencesRepository {
Expand All @@ -12,6 +13,7 @@ object SharedPreferencesRepository {
val jsonString = config.toString()
editor.putString("config", jsonString)
editor.apply()
ApiClient.instance.initClient()
}

fun getConfig(): SettingModel {
Expand Down

0 comments on commit 3301d8b

Please sign in to comment.