修改名称。
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
package com.xscm.modulemain.dialog
|
||||
|
||||
import android.R
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.xscm.modulemain.adapter.EmotionAdapter
|
||||
import com.xscm.modulemain.databinding.DialogEmotionPickerBinding
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.tencent.qcloud.tuikit.timcommon.util.ThreadUtils
|
||||
import com.xscm.moduleutil.bean.room.Emotion
|
||||
import com.xscm.moduleutil.bean.room.EmotionDeatils
|
||||
import com.xscm.moduleutil.http.BaseObserver
|
||||
import com.xscm.moduleutil.http.RetrofitClient
|
||||
import io.reactivex.disposables.Disposable
|
||||
import retrofit2.Retrofit
|
||||
|
||||
class EmotionPickerDialog(context: Context) : Dialog(context, com.xscm.moduleutil.R.style.BaseDialogStyleH) {
|
||||
|
||||
private lateinit var binding: DialogEmotionPickerBinding
|
||||
private lateinit var emotionAdapter: EmotionAdapter
|
||||
private val emotions = mutableListOf<Emotion>()
|
||||
private val emotionsDeatils = mutableListOf<EmotionDeatils>()
|
||||
|
||||
private var onEmotionSelectedListener: ((EmotionDeatils) -> Unit)? = null
|
||||
private var currentPage = 1
|
||||
private var isLoading = false
|
||||
private var currentTab = "1" // 默认tab
|
||||
|
||||
init {
|
||||
binding = DialogEmotionPickerBinding.inflate(LayoutInflater.from(context))
|
||||
setContentView(binding.root)
|
||||
|
||||
setupWindow()
|
||||
setupViews()
|
||||
// loadEmotions(currentTab, 1)
|
||||
}
|
||||
|
||||
private fun setupWindow() {
|
||||
val window = window ?: return
|
||||
window.setGravity(Gravity.BOTTOM)
|
||||
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
window.setBackgroundDrawableResource(android.R.color.transparent)
|
||||
|
||||
val params = window.attributes
|
||||
params.windowAnimations = com.xscm.moduleutil.R.style.BaseDialogStyleH
|
||||
window.attributes = params
|
||||
}
|
||||
|
||||
private fun setupViews() {
|
||||
RetrofitClient.getInstance().upEmotion(object : BaseObserver<List<Emotion>>() {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
}
|
||||
|
||||
override fun onNext(t: List<Emotion>) {
|
||||
if (t.isNotEmpty()) {
|
||||
emotions.addAll(t)
|
||||
for (i in t) {
|
||||
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(i.type_name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
// 设置Tab
|
||||
// 在代码中设置
|
||||
val tabLayout = binding.tabLayout
|
||||
tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
||||
override fun onTabSelected(tab: TabLayout.Tab?) {
|
||||
// 设置选中状态的文本大小
|
||||
tab?.view?.findViewById<TextView>(com.google.android.material.R.id.text)?.apply {
|
||||
textSize = 16f
|
||||
setTextColor(Color.WHITE)
|
||||
}
|
||||
loadEmotions(emotions.get(tab?.position!!).id.toString(), 1);
|
||||
}
|
||||
|
||||
override fun onTabUnselected(tab: TabLayout.Tab?) {
|
||||
// 设置未选中状态的文本大小
|
||||
tab?.view?.findViewById<TextView>(com.google.android.material.R.id.text)?.apply {
|
||||
textSize = 12f
|
||||
setTextColor(Color.parseColor("#999999"))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTabReselected(tab: TabLayout.Tab?) {
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// 设置RecyclerView
|
||||
emotionAdapter = EmotionAdapter()
|
||||
binding.rvEmotions.layoutManager = GridLayoutManager(context, 4)
|
||||
binding.rvEmotions.adapter = emotionAdapter
|
||||
|
||||
// 在 setupViews() 方法中
|
||||
emotionAdapter.setOnEmotionClickListener { emotion ->
|
||||
onEmotionSelectedListener?.invoke( emotion)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
// // 设置下拉刷新
|
||||
// binding.swipeRefreshLayout.setOnRefreshListener {
|
||||
// loadEmotions(currentTab, 1)
|
||||
// }
|
||||
//
|
||||
// // 设置上拉加载更多
|
||||
// binding.rvEmotions.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
// override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
// super.onScrolled(recyclerView, dx, dy)
|
||||
//
|
||||
// val layoutManager = recyclerView.layoutManager as LinearLayoutManager
|
||||
// val visibleItemCount = layoutManager.childCount
|
||||
// val totalItemCount = layoutManager.itemCount
|
||||
// val firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition()
|
||||
//
|
||||
// if (!isLoading && (visibleItemCount + firstVisibleItemPosition) >= totalItemCount && firstVisibleItemPosition >= 0) {
|
||||
// loadEmotions(currentTab, ++currentPage)
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
|
||||
// 设置表情点击事件
|
||||
// emotionAdapter.setOnEmotionClickListener { emotion ->
|
||||
// onEmotionSelectedListener?.invoke(emotion)
|
||||
// dismiss()
|
||||
// }
|
||||
//
|
||||
// // 关闭按钮
|
||||
// binding.ivClose.setOnClickListener {
|
||||
// dismiss()
|
||||
// }
|
||||
}
|
||||
|
||||
private fun loadEmotions(type: String, page: Int) {
|
||||
if (page == 1) {
|
||||
emotionsDeatils.clear()
|
||||
}
|
||||
|
||||
isLoading = true
|
||||
|
||||
RetrofitClient.getInstance().getEmotionDeatils(type, object : BaseObserver<List<EmotionDeatils>>() {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
}
|
||||
|
||||
override fun onNext(t: List<EmotionDeatils>) {
|
||||
if (t.isNotEmpty()) {
|
||||
emotionsDeatils.addAll(t)
|
||||
emotionAdapter.setNewData(emotionsDeatils)
|
||||
}else{
|
||||
emotionsDeatils.clear()
|
||||
emotionAdapter.setNewData(emotionsDeatils)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
isLoading = false
|
||||
|
||||
}
|
||||
|
||||
fun setOnEmotionSelectedListener(listener: (EmotionDeatils) -> Unit) {
|
||||
onEmotionSelectedListener = listener
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user