添加展开回调

This commit is contained in:
renhaoting 2025-10-31 19:04:40 +08:00
parent 2501a3dbf6
commit b426fda4d3
4 changed files with 62 additions and 22 deletions

View File

@ -5,6 +5,7 @@ import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.core.graphics.toColorInt import androidx.core.graphics.toColorInt
import com.remax.visualnovel.R import com.remax.visualnovel.R
@ -14,6 +15,8 @@ import com.remax.visualnovel.entity.response.ChatBubble
import com.remax.visualnovel.entity.response.ChatHistory import com.remax.visualnovel.entity.response.ChatHistory
import com.remax.visualnovel.entity.response.ChatMode import com.remax.visualnovel.entity.response.ChatMode
import com.remax.visualnovel.entity.response.ChatSound import com.remax.visualnovel.entity.response.ChatSound
import com.remax.visualnovel.ui.chat.ui.expandableSelector.ExpandAiModelSelectView
import com.remax.visualnovel.ui.chat.ui.expandableSelector.ExpandSoundSelectView
import com.remax.visualnovel.ui.chat.ui.expandableSelector.SelectorItem import com.remax.visualnovel.ui.chat.ui.expandableSelector.SelectorItem
import java.util.Date import java.util.Date
@ -43,6 +46,9 @@ class ChatSettingView @JvmOverloads constructor(
initHistoryListView() initHistoryListView()
} }
private fun scroll2Position(targetSubView: View) {
mBinding.scrollView.smoothScrollTo(0, targetSubView.top)
}
fun initAiModelSelectorView() { fun initAiModelSelectorView() {
val items = listOf( val items = listOf(
@ -74,10 +80,24 @@ class ChatSettingView @JvmOverloads constructor(
) )
) )
//aiModelSelector.setOnItemSelectedListener() with(mBinding.aiModelSelector) {
mBinding.aiModelSelector.setTitleIcon(R.mipmap.setting_ai_model) setTitleIcon(R.mipmap.setting_ai_model)
mBinding.aiModelSelector.setItems(items) setItems(items)
mBinding.aiModelSelector.selectItem(0) selectItem(0)
setOnEventListener(object : ExpandAiModelSelectView.IEventListener {
override fun onItemSelected(
position: Int,
item: SelectorItem
) {
// TODO -
}
override fun onExpanded(isExpanded: Boolean) {
if (isExpanded)
scroll2Position(this@with)
}
})
}
} }
fun initChatModeSelectorView() { fun initChatModeSelectorView() {
@ -153,7 +173,22 @@ class ChatSettingView @JvmOverloads constructor(
) )
) )
mBinding.soundActorSelector.setItems(items) with(mBinding.soundActorSelector) {
setItems(items)
setEventListener(object : ExpandSoundSelectView.IEventListener {
override fun onItemSelected(
position: Int,
item: ChatSound
) {
}
override fun onExpanded(isExpanded: Boolean) {
if (isExpanded)
scroll2Position(this@with)
}
})
}
} }
fun initBubbleSelectView() { fun initBubbleSelectView() {

View File

@ -28,7 +28,11 @@ class ExpandAiModelSelectView @JvmOverloads constructor(
private var isExpanded = false private var isExpanded = false
private var animationDuration = 300 private var animationDuration = 300
private var items: List<SelectorItem> = emptyList() private var items: List<SelectorItem> = emptyList()
private var itemSelectedListener: OnItemSelectedListener? = null private var mEventListener: IEventListener? = null
interface IEventListener {
fun onItemSelected(position: Int, item: SelectorItem)
fun onExpanded(isExpanded: Boolean)
}
init { init {
initView(context, attrs) initView(context, attrs)
@ -103,7 +107,7 @@ class ExpandAiModelSelectView @JvmOverloads constructor(
itemView.setOnClickListener { itemView.setOnClickListener {
selectItem(position) selectItem(position)
itemSelectedListener?.onItemSelected(position, item) mEventListener?.onItemSelected(position, item)
} }
return itemView return itemView
@ -130,13 +134,12 @@ class ExpandAiModelSelectView @JvmOverloads constructor(
if (position in items.indices) { if (position in items.indices) {
mBinding.titleText.text = items[position].name mBinding.titleText.text = items[position].name
} }
collapse()
} }
fun toggle() { fun toggle() {
if (isExpanded) collapse() else expand() if (isExpanded) collapse() else expand()
mEventListener?.onExpanded(isExpanded)
} }
fun expand() { fun expand() {
@ -202,11 +205,9 @@ class ExpandAiModelSelectView @JvmOverloads constructor(
return height return height
} }
fun setOnItemSelectedListener(listener: OnItemSelectedListener) { fun setOnEventListener(listener: IEventListener) {
this.itemSelectedListener = listener this.mEventListener = listener
} }
interface OnItemSelectedListener {
fun onItemSelected(position: Int, item: SelectorItem)
}
} }

View File

@ -23,10 +23,17 @@ class ExpandSoundSelectView @JvmOverloads constructor(
) : LinearLayout(context, attrs, defStyleAttr) { ) : LinearLayout(context, attrs, defStyleAttr) {
private lateinit var mBinding: LayoutExpandSelectViewBinding private lateinit var mBinding: LayoutExpandSelectViewBinding
private lateinit var mExpandView : ExpandSoundSubView private lateinit var mExpandView : ExpandSoundSubView
private var isExpanded = false private var isExpanded = false
private var animationDuration = 300 private var animationDuration = 300
private var itemSelectedListener: OnItemSelectedListener? = null
private var mEventListener: IEventListener? = null
interface IEventListener {
fun onItemSelected(position: Int, item: ChatSound)
fun onExpanded(isExpanded: Boolean)
}
fun setEventListener(listener: IEventListener) {
mEventListener = listener
}
init { init {
initView(context, attrs) initView(context, attrs)
@ -76,6 +83,7 @@ class ExpandSoundSelectView @JvmOverloads constructor(
fun toggle() { fun toggle() {
if (isExpanded) collapse() else expand() if (isExpanded) collapse() else expand()
mEventListener?.onExpanded(isExpanded)
} }
fun expand() { fun expand() {
@ -141,11 +149,6 @@ class ExpandSoundSelectView @JvmOverloads constructor(
return height return height
} }
fun setOnItemSelectedListener(listener: OnItemSelectedListener) {
this.itemSelectedListener = listener
}
interface OnItemSelectedListener {
fun onItemSelected(position: Int, item: SelectorItem)
}
} }

View File

@ -45,6 +45,7 @@
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/white" android:background="@color/white"