配置页添加模型删除功能

This commit is contained in:
xiaji
2026-04-06 08:10:25 +08:00
parent e0e257e373
commit 0f0f1f8ea4
3 changed files with 35 additions and 0 deletions

View File

@@ -49,6 +49,7 @@ class SecondActivity : AppCompatActivity() {
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
@@ -160,6 +161,7 @@ class SecondActivity : AppCompatActivity() {
etModelName = findViewById(R.id.etModelName)
spModelSelector = findViewById(R.id.spModelSelector)
btnAddModel = findViewById(R.id.btnAddModel)
btnDeleteModel = findViewById(R.id.btnDeleteModel)
btnTestConnection = findViewById(R.id.btnTestConnection)
tvTestStatus = findViewById(R.id.tvTestStatus)
@@ -382,6 +384,21 @@ class SecondActivity : AppCompatActivity() {
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()
}
// Setup headers
llHeadersList.removeAllViews()
if (headerConfigs.isEmpty()) {

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/error"/>
<corners android:radius="8dp"/>
</shape>

View File

@@ -182,6 +182,18 @@
android:background="@drawable/button_primary_bg"
android:minWidth="0dp"
android:minHeight="0dp"/>
<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"/>
</LinearLayout>
<!-- Base URL -->