Thomas Richardson commited on
Commit
be71d59
·
unverified ·
2 Parent(s): ec1f8e5689c7ae

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
- <LinearLayout
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
- <com.google.android.material.textfield.TextInputLayout
55
- android:id="@+id/txt_uuid"
56
- style="@style/CommonEditText"
57
- android:layout_marginBottom="@dimen/spacing_tiny"
58
- android:enabled="false"
59
- android:hint="@string/label_setting_uuid">
60
 
61
- <com.google.android.material.textfield.TextInputEditText
62
- android:layout_width="match_parent"
63
- android:layout_height="wrap_content"/>
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"
82
- android:layout_marginBottom="@dimen/spacing_tiny"
83
- android:hint="@string/label_setting_openai_key">
84
 
85
- <com.google.android.material.textfield.TextInputEditText
86
- android:layout_width="match_parent"
87
- android:layout_height="wrap_content" />
88
 
89
- </com.google.android.material.textfield.TextInputLayout>
90
 
91
- <com.google.android.material.textfield.TextInputLayout
92
- android:id="@+id/txt_pinecone_key"
93
- style="@style/CommonEditText"
94
- android:layout_marginBottom="@dimen/spacing_tiny"
95
- android:hint="@string/label_setting_pinecone_key">
96
 
97
- <com.google.android.material.textfield.TextInputEditText
98
- android:layout_width="match_parent"
99
- android:layout_height="wrap_content" />
100
 
101
- </com.google.android.material.textfield.TextInputLayout>
102
 
103
- <com.google.android.material.textfield.TextInputLayout
104
- android:id="@+id/txt_pinecone_env"
105
- style="@style/CommonEditText"
106
- android:layout_marginBottom="@dimen/spacing_tiny"
107
- android:hint="@string/label_setting_pinecone_env">
108
 
109
- <com.google.android.material.textfield.TextInputEditText
110
- android:layout_width="match_parent"
111
- android:layout_height="wrap_content" />
112
 
113
- </com.google.android.material.textfield.TextInputLayout>
114
 
115
- <com.google.android.material.textfield.TextInputLayout
116
- android:id="@+id/txt_firebase_key"
117
- style="@style/CommonEditText"
118
- android:hint="@string/label_setting_firebase_key"
119
- android:layout_marginBottom="@dimen/spacing_small">
120
 
121
- <com.google.android.material.textfield.TextInputEditText
122
- android:layout_width="match_parent"
123
- android:layout_height="wrap_content" />
124
 
125
- </com.google.android.material.textfield.TextInputLayout>
126
 
127
- <View
128
- style="@style/HorizontalDividerStyle"
129
- android:layout_marginBottom="@dimen/spacing_small" />
130
 
131
- <com.google.android.material.textfield.TextInputLayout
132
- android:id="@+id/txt_temperature"
133
- style="@style/CommonEditText"
134
- android:layout_height="match_parent"
135
- android:hint="@string/label_setting_temperature">
136
 
137
- <com.google.android.material.textfield.TextInputEditText
138
- android:layout_width="match_parent"
139
- android:layout_height="wrap_content" />
140
 
141
- </com.google.android.material.textfield.TextInputLayout>
 
142
 
143
- </LinearLayout>
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"