diff --git a/app/src/main/java/org/unitmesh/llmpoc/ui/home/HomeFragment.kt b/app/src/main/java/org/unitmesh/llmpoc/ui/home/HomeFragment.kt index 31a0bb2..5a0706e 100644 --- a/app/src/main/java/org/unitmesh/llmpoc/ui/home/HomeFragment.kt +++ b/app/src/main/java/org/unitmesh/llmpoc/ui/home/HomeFragment.kt @@ -4,9 +4,12 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Button +import android.widget.EditText import android.widget.TextView import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider +import org.unitmesh.llmpoc.R import org.unitmesh.llmpoc.databinding.FragmentHomeBinding class HomeFragment : Fragment() { @@ -18,12 +21,11 @@ class HomeFragment : Fragment() { private val binding get() = _binding!! override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, ): View { - val homeViewModel = - ViewModelProvider(this).get(HomeViewModel::class.java) + val homeViewModel = ViewModelProvider(this)[HomeViewModel::class.java] _binding = FragmentHomeBinding.inflate(inflater, container, false) val root: View = binding.root @@ -32,6 +34,14 @@ class HomeFragment : Fragment() { homeViewModel.text.observe(viewLifecycleOwner) { textView.text = it } + + // 在此处初始化布局元素 + val addButton: Button = root.findViewById(R.id.addButton) + val computeButton: Button = root.findViewById(R.id.computeButton) + + addButton.setOnClickListener { addSentence() } + computeButton.setOnClickListener { compute() } + return root } @@ -39,4 +49,17 @@ class HomeFragment : Fragment() { super.onDestroyView() _binding = null } + + fun addSentence() { + + } + + fun compute() { + + } + + fun showJsonOutput(view: View) { + val textView: TextView = binding.jsonOutput + textView.text = "json output" + } } \ No newline at end of file diff --git a/app/src/main/java/org/unitmesh/llmpoc/ui/home/HomeViewModel.kt b/app/src/main/java/org/unitmesh/llmpoc/ui/home/HomeViewModel.kt index bfe6294..31fa001 100644 --- a/app/src/main/java/org/unitmesh/llmpoc/ui/home/HomeViewModel.kt +++ b/app/src/main/java/org/unitmesh/llmpoc/ui/home/HomeViewModel.kt @@ -9,5 +9,14 @@ class HomeViewModel : ViewModel() { private val _text = MutableLiveData().apply { value = "This is home Fragment" } + val text: LiveData = _text + + fun addSentence(sourceSentence: String, compareSentence: String) { + // 处理添加句子的逻辑 + } + + fun computeSimilarity() { + // 处理计算相似度的逻辑 + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index f3d9b08..5d3a564 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -1,22 +1,113 @@ - - + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".ui.home.HomeFragment"> + + + + + + + + + + + + + + + + + + + + + + + + +