回滚到设置配置背景图片之前的版本。目前正常。
This commit is contained in:
@@ -111,7 +111,6 @@ class MainActivity : AppCompatActivity() {
|
||||
inputEditText = findViewById(R.id.inputEditText)
|
||||
inputEditText.gravity = Gravity.START or Gravity.TOP
|
||||
|
||||
configButton = findViewById(R.id.configButton)
|
||||
// 状态栏目的信息
|
||||
statusText = findViewById(R.id.statusTextView)
|
||||
|
||||
@@ -147,7 +146,7 @@ class MainActivity : AppCompatActivity() {
|
||||
if (zhipuConfig != null) {
|
||||
apiKey = zhipuConfig.key
|
||||
apiUrl = zhipuConfig.url
|
||||
apiModel = zhipuConfig.model
|
||||
//apiModel = zhipuConfig.model
|
||||
statusText.text = "zhipuConfig配置文件$apiModel"
|
||||
|
||||
} else {
|
||||
@@ -256,7 +255,7 @@ class MainActivity : AppCompatActivity() {
|
||||
if (sparkConfig != null) {
|
||||
apiKey = sparkConfig.key
|
||||
apiUrl = sparkConfig.url
|
||||
apiModel = sparkConfig.model
|
||||
//apiModel = sparkConfig.model
|
||||
statusText.text = "sparkConfig配置文件$apiModel"
|
||||
} else {
|
||||
statusText.text = "没找到sparkConfig配置文件"
|
||||
@@ -334,6 +333,8 @@ class MainActivity : AppCompatActivity() {
|
||||
tabLayout = findViewById(R.id.tabLayout)
|
||||
submitToServerButton = findViewById(R.id.submitToServerButton)
|
||||
|
||||
|
||||
configButton = findViewById(R.id.configButton)
|
||||
configButton.setOnClickListener {
|
||||
val intent = Intent(this, SecondActivity::class.java)
|
||||
startActivity(intent)
|
||||
|
||||
@@ -1,29 +1,17 @@
|
||||
package com.example.flomo_ai
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.util.Log
|
||||
import android.graphics.Color
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import java.io.InputStream
|
||||
|
||||
|
||||
class SecondActivity : AppCompatActivity() {
|
||||
private lateinit var etApiButtonName: EditText
|
||||
private lateinit var etApiName: EditText
|
||||
private lateinit var etApiUrl: EditText
|
||||
private lateinit var etApiKey: EditText
|
||||
@@ -31,27 +19,22 @@ class SecondActivity : AppCompatActivity() {
|
||||
private lateinit var etApiModel: EditText
|
||||
private lateinit var btnSave: Button
|
||||
private lateinit var llConfigList: LinearLayout
|
||||
|
||||
private var configs = mutableListOf<APIConfig>()
|
||||
private var editingId: Long? = null
|
||||
private lateinit var imagePickerLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
companion object {
|
||||
private const val REQUEST_CODE_PICK_IMAGE = 1000
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(androidx.appcompat.R.style.Theme_AppCompat)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_second) // 确认布局文件正确
|
||||
setContentView(R.layout.activity_second)
|
||||
|
||||
initViews()
|
||||
loadConfigs()
|
||||
displayConfigs()
|
||||
|
||||
val btnGoBack: Button = findViewById(R.id.btnGoBack);
|
||||
val btnGoBack: Button = findViewById(R.id.btnGoBack)
|
||||
btnGoBack.setOnClickListener {
|
||||
val intent = Intent(this, MainActivity::class.java);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
finish()
|
||||
}
|
||||
|
||||
btnSave.setOnClickListener {
|
||||
@@ -61,41 +44,16 @@ class SecondActivity : AppCompatActivity() {
|
||||
addConfig()
|
||||
}
|
||||
}
|
||||
|
||||
// 创建背景图
|
||||
setContentView(R.layout.activity_second)
|
||||
|
||||
imagePickerLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK && result.data != null) {
|
||||
val selectedImageUri: Uri? = result.data?.data
|
||||
selectedImageUri?.let { uri ->
|
||||
val bitmap = getBitmapFromUri(uri)
|
||||
// 使用bitmap更新背景或其他操作
|
||||
}
|
||||
}
|
||||
}
|
||||
val chooseButton: Button = findViewById(R.id.chooseButton)
|
||||
chooseButton.setOnClickListener {
|
||||
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
|
||||
intent.type = "image/*"
|
||||
imagePickerLauncher.launch(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBitmapFromUri(uri: Uri): Bitmap? {
|
||||
val inputStream: InputStream? = contentResolver.openInputStream(uri)
|
||||
return BitmapFactory.decodeStream(inputStream)
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
etApiName = findViewById(R.id.etApiName) ?: throw IllegalStateException("etApiName is not found")
|
||||
etApiUrl = findViewById(R.id.etApiUrl) ?: throw IllegalStateException("etApiUrl is not found")
|
||||
etApiKey = findViewById(R.id.etApiKey) ?: throw IllegalStateException("etApiKey is not found")
|
||||
etApiSecretKey = findViewById(R.id.etApiSecretKey) ?: throw IllegalStateException("etApiSecretKey is not found")
|
||||
etApiModel = findViewById(R.id.etApiModel) ?: throw IllegalStateException("etApiModel is not found")
|
||||
etApiButtonName = findViewById(R.id.etApiButtonName) ?: throw IllegalStateException("etApiButtonName is not found")
|
||||
btnSave = findViewById(R.id.btnSave) ?: throw IllegalStateException("btnSave is not found")
|
||||
llConfigList = findViewById(R.id.llConfigList) ?: throw IllegalStateException("llConfigList is not found")
|
||||
etApiName = findViewById(R.id.etApiName)
|
||||
etApiUrl = findViewById(R.id.etApiUrl)
|
||||
etApiKey = findViewById(R.id.etApiKey)
|
||||
etApiSecretKey = findViewById(R.id.etApiSecretKey)
|
||||
etApiModel = findViewById(R.id.etApiModel)
|
||||
btnSave = findViewById(R.id.btnSave)
|
||||
llConfigList = findViewById(R.id.llConfigList)
|
||||
}
|
||||
|
||||
private fun loadConfigs() {
|
||||
@@ -109,20 +67,11 @@ class SecondActivity : AppCompatActivity() {
|
||||
|
||||
private fun saveConfigs() {
|
||||
val sharedPrefs = getSharedPreferences("APIConfigs", MODE_PRIVATE)
|
||||
val editor = sharedPrefs.edit()
|
||||
if (editor != null) {
|
||||
val gson = Gson()
|
||||
val json = gson.toJson(configs)
|
||||
Log.d("ConfigDebug", "Saving configs: $json")
|
||||
editor.putString("configs", json)
|
||||
editor.apply()
|
||||
} else {
|
||||
Log.e("ConfigDebug", "Failed to get SharedPreferences.Editor")
|
||||
}
|
||||
val json = Gson().toJson(configs)
|
||||
sharedPrefs.edit().putString("configs", json).apply()
|
||||
}
|
||||
|
||||
private fun addConfig() {
|
||||
val buttonname = etApiButtonName.text.toString()
|
||||
val name = etApiName.text.toString()
|
||||
val url = etApiUrl.text.toString()
|
||||
val key = etApiKey.text.toString()
|
||||
@@ -132,7 +81,7 @@ class SecondActivity : AppCompatActivity() {
|
||||
// 生成唯一的 id
|
||||
val id = System.currentTimeMillis()
|
||||
// 创建新的配置项
|
||||
val newConfig = APIConfig(id, buttonname, name, url, key, secretKey, model)
|
||||
val newConfig = APIConfig(id, name, url, key, secretKey, model)
|
||||
// 添加配置项
|
||||
configs.add(newConfig)
|
||||
// 保存配置
|
||||
@@ -144,7 +93,6 @@ class SecondActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun updateConfig() {
|
||||
val buttonname = etApiButtonName.text.toString()
|
||||
val name = etApiName.text.toString()
|
||||
val url = etApiUrl.text.toString()
|
||||
val key = etApiKey.text.toString()
|
||||
@@ -154,7 +102,7 @@ class SecondActivity : AppCompatActivity() {
|
||||
// 获取编辑的配置项 id
|
||||
val id = editingId ?: return
|
||||
// 更新配置项
|
||||
val updatedConfig = APIConfig(id, buttonname, name, url, key, secretKey, model)
|
||||
val updatedConfig = APIConfig(id, name, url, key, secretKey, model)
|
||||
val existingConfigIndex = configs.indexOfFirst { it.id == id }
|
||||
if (existingConfigIndex != -1) {
|
||||
configs[existingConfigIndex] = updatedConfig
|
||||
@@ -170,19 +118,13 @@ class SecondActivity : AppCompatActivity() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("MissingInflatedId", "SetTextI18n", "InflateParams")
|
||||
@SuppressLint("MissingInflatedId")
|
||||
private fun displayConfigs() {
|
||||
llConfigList.removeAllViews()
|
||||
for (config in configs) {
|
||||
// 为每个配置项加载对应的布局文件
|
||||
val configView = layoutInflater.inflate(R.layout.item_api_config, null)
|
||||
// 设置各项文本信息
|
||||
// 获取并设置 Name 的 TextView 前景色和背景色
|
||||
val tvButtonName = configView.findViewById<TextView>(R.id.tvButtonName)
|
||||
tvButtonName.text = "按钮名称: ${config.buttonname}"
|
||||
tvButtonName.setTextColor(Color.BLACK)
|
||||
|
||||
// 获取并设置 Name 的 TextView 前景色和背景色
|
||||
val tvName = configView.findViewById<TextView>(R.id.tvName)
|
||||
tvName.text = "Name: ${config.name}"
|
||||
@@ -225,7 +167,6 @@ class SecondActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun editConfig(config: APIConfig) {
|
||||
etApiButtonName.setText(config.buttonname)
|
||||
etApiName.setText(config.name)
|
||||
etApiUrl.setText(config.url)
|
||||
etApiKey.setText(config.key)
|
||||
@@ -243,7 +184,6 @@ class SecondActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun clearInputs() {
|
||||
etApiButtonName.text.clear()
|
||||
etApiName.text.clear()
|
||||
etApiUrl.text.clear()
|
||||
etApiKey.text.clear()
|
||||
@@ -255,7 +195,6 @@ class SecondActivity : AppCompatActivity() {
|
||||
|
||||
data class APIConfig(
|
||||
val id: Long,
|
||||
var buttonname:String,
|
||||
val name: String,
|
||||
val url: String,
|
||||
val key: String,
|
||||
|
||||
@@ -16,15 +16,12 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/back_to_main" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="文字处理 AI 区的配置"
|
||||
android:textSize="16sp"
|
||||
tools:ignore="HardcodedText,TextSizeCheck" />
|
||||
|
||||
android:text="文字处理AI区的配置"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etApiButtonName"
|
||||
@@ -56,8 +53,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="@string/api_key"
|
||||
android:minHeight="48dp"
|
||||
tools:ignore="TextFields" />
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etApiSecretKey"
|
||||
@@ -73,36 +69,21 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="API 模型类型"
|
||||
android:minHeight="48dp"
|
||||
tools:ignore="TextFields" />
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSave"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/save_config" />
|
||||
android:text="@string/save_config"
|
||||
android:layout_marginTop="16dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llConfigList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:orientation="vertical" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="设置背景图片"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/chooseButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="选择图片" />
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="16dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
@@ -1,6 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">flomo-ai</string>
|
||||
<string name="back_to_main">回首页</string>
|
||||
<string name="back_to_main">返回主界面</string>
|
||||
<string name="ai_config_title">文字处理AI区的配置</string>
|
||||
<string name="api_button_name_hint">API按钮显示名称</string>
|
||||
<string name="api_name_hint">API名称</string>
|
||||
<string name="api_url_hint">API URL</string>
|
||||
<string name="api_key_hint">API密钥</string>
|
||||
<string name="api_secret_key_hint">API Secret Key</string>
|
||||
<string name="api_model_type_hint">API模型类型</string>
|
||||
<string name="save_config">保存配置</string>
|
||||
<string name="api_key">API Key</string>
|
||||
<string name="set_background_image">设置背景图片</string>
|
||||
<string name="choose_image">选择图片</string>
|
||||
<string name="api_key">API密钥</string>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user