diff --git a/app/src/main/java/com/example/flomo_ai/MainActivity.kt b/app/src/main/java/com/example/flomo_ai/MainActivity.kt index 64fea75..ad31d7a 100644 --- a/app/src/main/java/com/example/flomo_ai/MainActivity.kt +++ b/app/src/main/java/com/example/flomo_ai/MainActivity.kt @@ -1,100 +1,28 @@ package com.example.flomo_ai import android.annotation.SuppressLint +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context import android.content.Intent import android.os.Bundle import android.view.Gravity +import android.view.View +import android.widget.AdapterView +import android.widget.ArrayAdapter import android.widget.Button import android.widget.EditText +import android.widget.Spinner import android.widget.TextView +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity -import com.google.android.material.tabs.TabLayout -import com.google.gson.Gson import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext +import kotlinx.coroutines.delay -import okhttp3.Interceptor -import okhttp3.OkHttpClient -import okhttp3.Request -import okhttp3.Response -import okhttp3.RequestBody.Companion.toRequestBody -import com.google.gson.JsonObject -import okhttp3.MediaType.Companion.toMediaType - -import com.google.gson.reflect.TypeToken import android.util.Log -import java.io.IOException -import java.net.UnknownHostException -import org.json.JSONObject - -import com.squareup.moshi.Moshi -import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory - -import android.graphics.Bitmap -import android.graphics.BitmapFactory -import android.net.Uri -import java.io.InputStream -import android.content.Context -import android.app.Activity -import android.widget.ImageView - - -// 定义请求体数据类 -data class ChatRequest( - val model: String, - val messages: List -) - -data class Message( - val role: String, - val content: String -) - - -// 从返回的 JSON 响应中提取标签列表 -fun extractLabels(responseBody: String): List? { - try { - // 假设 responseBody 中包含一个完整的 JSON 对象,我们需要先提取出其中的 content 部分 - val fullJsonObject = Gson().fromJson(responseBody, JsonObject::class.java) - val choicesArray = fullJsonObject.getAsJsonArray("choices") - if (choicesArray.size() > 0) { - val firstChoice = choicesArray.get(0).asJsonObject - val messageObject = firstChoice.get("message").asJsonObject - val content = messageObject.get("content").asString - // 从 content 中提取出 labels - val startIndex = content.indexOf("\"labels\": [") + "\"labels\": [".length - val endIndex = content.indexOf("]", startIndex) - val labelsStr = content.substring(startIndex, endIndex) - // 处理引号 - //val processedLabelsStr = labelsStr.replace("\"", "") - val labels = labelsStr.split("\", \"") - val processedLabels = mutableListOf() - for (label in labels) { - // 假设 label 是原始字符串 - var processedLabel = label - // 去掉单引号和双引号 - if (label.contains("'")) { - processedLabel = processedLabel.replace("'", "") - } - if (label.contains("\"")) { - processedLabel = processedLabel.replace("\"", "") - } - // 去掉所有空格 - processedLabel = processedLabel.replace(" ", "") - processedLabels.add(processedLabel) - } - return processedLabels - } - } catch (e: Exception) { - e.printStackTrace() - Log.e("ExtractLabels", "Error during extraction: ${e.message}") - - } - return null -} class MainActivity : AppCompatActivity() { private lateinit var inputEditText: EditText @@ -110,259 +38,132 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - inputEditText = findViewById(R.id.inputEditText) - inputEditText.gravity = Gravity.START or Gravity.TOP + // Initialize views + val promptSelector = findViewById(R.id.promptSelector) + val inputEditText = findViewById(R.id.inputEditText) + val sendButton = findViewById