Merge pull request #247 from ttt246/feature/firebase_cred
Browse files
Android/app/src/main/java/com/matthaigh27/chatgptwrapper/ui/setting/view/SettingActivity.kt
CHANGED
|
@@ -15,6 +15,7 @@ import com.matthaigh27.chatgptwrapper.ui.base.BaseActivity
|
|
| 15 |
import com.matthaigh27.chatgptwrapper.ui.chat.view.ChatActivity
|
| 16 |
import com.matthaigh27.chatgptwrapper.ui.chat.view.dialogs.ConfirmDialog
|
| 17 |
import com.matthaigh27.chatgptwrapper.ui.setting.viewmodel.SettingViewModel
|
|
|
|
| 18 |
|
| 19 |
class SettingActivity : BaseActivity() {
|
| 20 |
private val CONFIRM_MESSAGE = "Are you sure you want to set?"
|
|
@@ -67,9 +68,16 @@ class SettingActivity : BaseActivity() {
|
|
| 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())
|
| 72 |
txtOpenAIKey.editText?.setText(data.openaiKey)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
}
|
| 74 |
}
|
| 75 |
|
|
@@ -100,11 +108,18 @@ class SettingActivity : BaseActivity() {
|
|
| 100 |
private fun saveSettingData() {
|
| 101 |
val pineconeKey = txtPineconeKey.editText?.text.toString()
|
| 102 |
val pineconeEnv = txtPineconeEnv.editText?.text.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() {
|
|
|
|
| 15 |
import com.matthaigh27.chatgptwrapper.ui.chat.view.ChatActivity
|
| 16 |
import com.matthaigh27.chatgptwrapper.ui.chat.view.dialogs.ConfirmDialog
|
| 17 |
import com.matthaigh27.chatgptwrapper.ui.setting.viewmodel.SettingViewModel
|
| 18 |
+
import java.util.Base64
|
| 19 |
|
| 20 |
class SettingActivity : BaseActivity() {
|
| 21 |
private val CONFIRM_MESSAGE = "Are you sure you want to set?"
|
|
|
|
| 68 |
txtPineconeKey.editText?.setText(data.pineconeKey)
|
| 69 |
txtServerUrl.editText?.setText(data.serverUrl)
|
| 70 |
txtPineconeEnv.editText?.setText(data.pineconeEnv)
|
|
|
|
| 71 |
txtTemperature.editText?.setText(data.setting.temperature.toString())
|
| 72 |
txtOpenAIKey.editText?.setText(data.openaiKey)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Decode firebase credential file
|
| 77 |
+
*/
|
| 78 |
+
val decoder: Base64.Decoder = Base64.getDecoder()
|
| 79 |
+
val decoded = String(decoder.decode(data.firebaseKey))
|
| 80 |
+
txtFirebaseKey.editText?.setText(decoded)
|
| 81 |
}
|
| 82 |
}
|
| 83 |
|
|
|
|
| 108 |
private fun saveSettingData() {
|
| 109 |
val pineconeKey = txtPineconeKey.editText?.text.toString()
|
| 110 |
val pineconeEnv = txtPineconeEnv.editText?.text.toString()
|
|
|
|
| 111 |
val temperature = txtTemperature.editText?.text.toString().toFloat()
|
| 112 |
val openaiKey = txtOpenAIKey.editText?.text.toString()
|
| 113 |
val serverUrl: String = txtServerUrl.editText?.text.toString()
|
| 114 |
|
| 115 |
+
/**
|
| 116 |
+
* Encode firebase credential file to base64
|
| 117 |
+
*/
|
| 118 |
+
var firebaseKey = txtFirebaseKey.editText?.text.toString()
|
| 119 |
+
val encoder: Base64.Encoder = Base64.getEncoder()
|
| 120 |
+
val encoded: String = encoder.encodeToString(firebaseKey.toByteArray())
|
| 121 |
+
firebaseKey = encoded
|
| 122 |
+
|
| 123 |
val confirmDialog = ConfirmDialog(this)
|
| 124 |
confirmDialog.setOnClickListener(object : ConfirmDialog.OnDialogButtonClickListener {
|
| 125 |
override fun onPositiveButtonClick() {
|
Android/app/src/main/res/layout/activity_setting.xml
CHANGED
|
@@ -43,104 +43,112 @@
|
|
| 43 |
|
| 44 |
</androidx.constraintlayout.widget.ConstraintLayout>
|
| 45 |
|
| 46 |
-
<
|
| 47 |
android:layout_width="match_parent"
|
| 48 |
android:layout_height="0dp"
|
| 49 |
android:orientation="vertical"
|
| 50 |
android:padding="@dimen/spacing_small"
|
| 51 |
app:layout_constraintBottom_toTopOf="@+id/ll_action"
|
| 52 |
-
app:layout_constraintTop_toBottomOf="@+id/cl_header"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
-
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
|
| 89 |
-
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
|
| 113 |
-
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
|
| 125 |
-
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
|
| 141 |
-
|
|
|
|
| 142 |
|
| 143 |
-
</
|
| 144 |
|
| 145 |
<LinearLayout
|
| 146 |
android:id="@+id/ll_action"
|
|
|
|
| 43 |
|
| 44 |
</androidx.constraintlayout.widget.ConstraintLayout>
|
| 45 |
|
| 46 |
+
<ScrollView
|
| 47 |
android:layout_width="match_parent"
|
| 48 |
android:layout_height="0dp"
|
| 49 |
android:orientation="vertical"
|
| 50 |
android:padding="@dimen/spacing_small"
|
| 51 |
app:layout_constraintBottom_toTopOf="@+id/ll_action"
|
| 52 |
+
app:layout_constraintTop_toBottomOf="@+id/cl_header"
|
| 53 |
+
app:layout_constraintVertical_bias="0.0"
|
| 54 |
+
tools:layout_editor_absoluteX="0dp">
|
| 55 |
+
|
| 56 |
+
<LinearLayout
|
| 57 |
+
android:layout_width="match_parent"
|
| 58 |
+
android:layout_height="match_parent"
|
| 59 |
+
android:orientation="vertical">
|
| 60 |
|
| 61 |
+
<com.google.android.material.textfield.TextInputLayout
|
| 62 |
+
android:id="@+id/txt_uuid"
|
| 63 |
+
style="@style/CommonEditText"
|
| 64 |
+
android:layout_marginBottom="@dimen/spacing_tiny"
|
| 65 |
+
android:enabled="false"
|
| 66 |
+
android:hint="@string/label_setting_uuid">
|
| 67 |
|
| 68 |
+
<com.google.android.material.textfield.TextInputEditText
|
| 69 |
+
android:layout_width="match_parent"
|
| 70 |
+
android:layout_height="wrap_content" />
|
| 71 |
|
| 72 |
+
</com.google.android.material.textfield.TextInputLayout>
|
| 73 |
|
| 74 |
+
<com.google.android.material.textfield.TextInputLayout
|
| 75 |
+
android:id="@+id/txt_server_url"
|
| 76 |
+
style="@style/CommonEditText"
|
| 77 |
+
android:layout_marginBottom="@dimen/spacing_tiny"
|
| 78 |
+
android:hint="@string/label_setting_server_url">
|
| 79 |
|
| 80 |
+
<com.google.android.material.textfield.TextInputEditText
|
| 81 |
+
android:layout_width="match_parent"
|
| 82 |
+
android:layout_height="wrap_content" />
|
| 83 |
|
| 84 |
+
</com.google.android.material.textfield.TextInputLayout>
|
| 85 |
|
| 86 |
+
<com.google.android.material.textfield.TextInputLayout
|
| 87 |
+
android:id="@+id/txt_openai_key"
|
| 88 |
+
style="@style/CommonEditText"
|
| 89 |
+
android:layout_marginBottom="@dimen/spacing_tiny"
|
| 90 |
+
android:hint="@string/label_setting_openai_key">
|
| 91 |
|
| 92 |
+
<com.google.android.material.textfield.TextInputEditText
|
| 93 |
+
android:layout_width="match_parent"
|
| 94 |
+
android:layout_height="wrap_content" />
|
| 95 |
|
| 96 |
+
</com.google.android.material.textfield.TextInputLayout>
|
| 97 |
|
| 98 |
+
<com.google.android.material.textfield.TextInputLayout
|
| 99 |
+
android:id="@+id/txt_pinecone_key"
|
| 100 |
+
style="@style/CommonEditText"
|
| 101 |
+
android:layout_marginBottom="@dimen/spacing_tiny"
|
| 102 |
+
android:hint="@string/label_setting_pinecone_key">
|
| 103 |
|
| 104 |
+
<com.google.android.material.textfield.TextInputEditText
|
| 105 |
+
android:layout_width="match_parent"
|
| 106 |
+
android:layout_height="wrap_content" />
|
| 107 |
|
| 108 |
+
</com.google.android.material.textfield.TextInputLayout>
|
| 109 |
|
| 110 |
+
<com.google.android.material.textfield.TextInputLayout
|
| 111 |
+
android:id="@+id/txt_pinecone_env"
|
| 112 |
+
style="@style/CommonEditText"
|
| 113 |
+
android:layout_marginBottom="@dimen/spacing_tiny"
|
| 114 |
+
android:hint="@string/label_setting_pinecone_env">
|
| 115 |
|
| 116 |
+
<com.google.android.material.textfield.TextInputEditText
|
| 117 |
+
android:layout_width="match_parent"
|
| 118 |
+
android:layout_height="wrap_content" />
|
| 119 |
|
| 120 |
+
</com.google.android.material.textfield.TextInputLayout>
|
| 121 |
|
| 122 |
+
<com.google.android.material.textfield.TextInputLayout
|
| 123 |
+
android:id="@+id/txt_firebase_key"
|
| 124 |
+
style="@style/CommonEditText"
|
| 125 |
+
android:layout_marginBottom="@dimen/spacing_small"
|
| 126 |
+
android:hint="@string/label_setting_firebase_key">
|
| 127 |
|
| 128 |
+
<com.google.android.material.textfield.TextInputEditText
|
| 129 |
+
android:layout_width="match_parent"
|
| 130 |
+
android:layout_height="wrap_content"/>
|
| 131 |
|
| 132 |
+
</com.google.android.material.textfield.TextInputLayout>
|
| 133 |
|
| 134 |
+
<View
|
| 135 |
+
style="@style/HorizontalDividerStyle"
|
| 136 |
+
android:layout_marginBottom="@dimen/spacing_small" />
|
| 137 |
|
| 138 |
+
<com.google.android.material.textfield.TextInputLayout
|
| 139 |
+
android:id="@+id/txt_temperature"
|
| 140 |
+
style="@style/CommonEditText"
|
| 141 |
+
android:layout_height="match_parent"
|
| 142 |
+
android:hint="@string/label_setting_temperature">
|
| 143 |
|
| 144 |
+
<com.google.android.material.textfield.TextInputEditText
|
| 145 |
+
android:layout_width="match_parent"
|
| 146 |
+
android:layout_height="wrap_content" />
|
| 147 |
|
| 148 |
+
</com.google.android.material.textfield.TextInputLayout>
|
| 149 |
+
</LinearLayout>
|
| 150 |
|
| 151 |
+
</ScrollView>
|
| 152 |
|
| 153 |
<LinearLayout
|
| 154 |
android:id="@+id/ll_action"
|