重构大模型配置为列表布局,每行显示名称、编辑、删除按钮
This commit is contained in:
@@ -46,10 +46,8 @@ data class ButtonConfig(val id: String, val label: String, val action: String, v
|
||||
class SecondActivity : AppCompatActivity() {
|
||||
|
||||
// View references
|
||||
private lateinit var spModelSelector: Spinner
|
||||
private lateinit var llModelList: LinearLayout
|
||||
private lateinit var btnAddModel: Button
|
||||
private lateinit var btnDeleteModel: Button
|
||||
private lateinit var etBaseUrl: EditText
|
||||
private lateinit var etApiKey: EditText
|
||||
private lateinit var btnToggleApiKey: ImageButton
|
||||
@@ -159,9 +157,8 @@ class SecondActivity : AppCompatActivity() {
|
||||
btnToggleApiKey = findViewById(R.id.btnToggleApiKey)
|
||||
etModel = findViewById(R.id.etModel)
|
||||
etModelName = findViewById(R.id.etModelName)
|
||||
spModelSelector = findViewById(R.id.spModelSelector)
|
||||
llModelList = findViewById(R.id.llModelList)
|
||||
btnAddModel = findViewById(R.id.btnAddModel)
|
||||
btnDeleteModel = findViewById(R.id.btnDeleteModel)
|
||||
btnTestConnection = findViewById(R.id.btnTestConnection)
|
||||
tvTestStatus = findViewById(R.id.tvTestStatus)
|
||||
|
||||
@@ -351,23 +348,42 @@ class SecondActivity : AppCompatActivity() {
|
||||
etApiKey.setSelection(etApiKey.text.length)
|
||||
}
|
||||
|
||||
private fun refreshModelSelector() {
|
||||
val names = llmConfigs.map { it.name.ifEmpty { "未命名" } }.toMutableList()
|
||||
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, names)
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
spModelSelector.adapter = adapter
|
||||
private fun refreshModelList() {
|
||||
llModelList.removeAllViews()
|
||||
for ((index, config) in llmConfigs.withIndex()) {
|
||||
val view = layoutInflater.inflate(R.layout.model_list_item, null)
|
||||
val tvName = view.findViewById<TextView>(R.id.tvModelName)
|
||||
val btnEdit = view.findViewById<Button>(R.id.btnEditModel)
|
||||
val btnDelete = view.findViewById<Button>(R.id.btnDeleteModel)
|
||||
|
||||
tvName.text = config.name.ifEmpty { "未命名" }
|
||||
|
||||
btnEdit.setOnClickListener {
|
||||
selectedLlmIndex = index
|
||||
loadSelectedModelToFields()
|
||||
Toast.makeText(this, "正在编辑: ${config.name}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
btnDelete.setOnClickListener {
|
||||
if (llmConfigs.size <= 1) {
|
||||
Toast.makeText(this, "至少保留一个配置", Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
llmConfigs.removeAt(index)
|
||||
if (selectedLlmIndex >= llmConfigs.size) {
|
||||
selectedLlmIndex = llmConfigs.size - 1
|
||||
}
|
||||
loadSelectedModelToFields()
|
||||
refreshModelList()
|
||||
Toast.makeText(this, "配置已删除", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
llModelList.addView(view)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupUI() {
|
||||
refreshModelSelector()
|
||||
|
||||
spModelSelector.setOnItemSelectedListener(object : android.widget.AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: android.widget.AdapterView<*>, view: android.view.View?, position: Int, id: Long) {
|
||||
selectedLlmIndex = position
|
||||
loadSelectedModelToFields()
|
||||
}
|
||||
override fun onNothingSelected(parent: android.widget.AdapterView<*>) {}
|
||||
})
|
||||
refreshModelList()
|
||||
|
||||
btnAddModel.setOnClickListener {
|
||||
val newName = "新配置 ${llmConfigs.size + 1}"
|
||||
@@ -380,23 +396,7 @@ class SecondActivity : AppCompatActivity() {
|
||||
llmConfigs.add(newConfig)
|
||||
selectedLlmIndex = llmConfigs.size - 1
|
||||
loadSelectedModelToFields()
|
||||
refreshModelSelector()
|
||||
spModelSelector.setSelection(selectedLlmIndex)
|
||||
}
|
||||
|
||||
btnDeleteModel.setOnClickListener {
|
||||
if (llmConfigs.size <= 1) {
|
||||
Toast.makeText(this, "至少保留一个配置", Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
llmConfigs.removeAt(selectedLlmIndex)
|
||||
if (selectedLlmIndex >= llmConfigs.size) {
|
||||
selectedLlmIndex = llmConfigs.size - 1
|
||||
}
|
||||
loadSelectedModelToFields()
|
||||
refreshModelSelector()
|
||||
spModelSelector.setSelection(selectedLlmIndex)
|
||||
Toast.makeText(this, "配置已删除", Toast.LENGTH_SHORT).show()
|
||||
refreshModelList()
|
||||
}
|
||||
|
||||
// Setup headers
|
||||
|
||||
@@ -154,49 +154,48 @@
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 模型选择器 -->
|
||||
<!-- 模型列表 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
android:orientation="vertical">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spModelSelector"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/edittext_border"
|
||||
android:spinnerMode="dropdown"
|
||||
android:padding="12dp"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnAddModel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="+ 添加"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/white"
|
||||
android:background="@drawable/button_primary_bg"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="已配置模型"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnDeleteModel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginStart="4dp"
|
||||
android:text="删除"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/white"
|
||||
android:background="@drawable/button_danger_bg"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"/>
|
||||
<Button
|
||||
android:id="@+id/btnAddModel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:text="+ 添加"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/white"
|
||||
android:background="@drawable/button_primary_bg"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llModelList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="12dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Base URL -->
|
||||
<!-- 当前编辑区 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
46
flomo-ai/app/src/main/res/layout/model_list_item.xml
Normal file
46
flomo-ai/app/src/main/res/layout/model_list_item.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingVertical="12dp"
|
||||
android:background="@drawable/edittext_border"
|
||||
android:layout_marginBottom="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvModelName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/primary"
|
||||
android:textSize="16sp"
|
||||
android:gravity="center"
|
||||
android:text="模型名称"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnEditModel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="36dp"
|
||||
android:text="编辑"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/white"
|
||||
android:background="@drawable/button_secondary_bg"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:layout_marginEnd="8dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnDeleteModel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="36dp"
|
||||
android:text="删除"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/white"
|
||||
android:background="@drawable/button_danger_bg"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"
|
||||
android:paddingHorizontal="12dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user