package cn.flightfeather.thirdappmodule.view
|
|
import android.app.Dialog
|
import android.content.Context
|
import android.graphics.drawable.Drawable
|
import android.support.design.widget.FloatingActionButton
|
import android.support.v7.widget.CardView
|
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.RecyclerView
|
import android.util.AttributeSet
|
import android.view.DragEvent
|
import android.view.LayoutInflater
|
import android.view.View
|
import android.view.ViewGroup
|
import android.widget.FrameLayout
|
import android.widget.ImageView
|
import android.widget.LinearLayout
|
import android.widget.TextView
|
import cn.flightfeather.thirdappmodule.R
|
import cn.flightfeather.thirdappmodule.adapter.AllRecyclerViewAdapter
|
import cn.flightfeather.thirdappmodule.bean.entity.Scense
|
import cn.flightfeather.thirdappmodule.util.DialogUtil
|
|
/**
|
* @author riku
|
* Date: 2019/7/23
|
* 侧边滑动栏
|
*/
|
class SlideSideBarView : FrameLayout, View.OnClickListener, View.OnDragListener {
|
|
constructor(context: Context) : super(context){
|
init()
|
}
|
|
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs){
|
init(attrs)
|
}
|
|
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr){
|
init(attrs)
|
}
|
|
companion object{
|
const val LEFT = 0
|
const val RIGHT = 1
|
}
|
|
var onCloseClickListener: OnClickListener? = null
|
|
private lateinit var mRootView:View
|
private lateinit var leftToggle:CardView
|
private lateinit var leftToggleText: TextView
|
private lateinit var leftToggleImg:ImageView
|
|
//dialog
|
lateinit var dialog: Dialog
|
|
lateinit var customView:View
|
private lateinit var bodyView:CardView
|
lateinit var contentView:RecyclerView
|
lateinit var title:TextView
|
lateinit var count:TextView
|
lateinit var closeBtn: FloatingActionButton
|
|
var imgDrawable: Drawable? = null
|
|
private fun init(attrs: AttributeSet?) {
|
attrs?.let {
|
val typedArray = context.obtainStyledAttributes(it, R.styleable.SlideSideBarView)
|
imgDrawable = typedArray.getDrawable(R.styleable.SlideSideBarView_src)
|
typedArray.recycle()
|
}
|
init()
|
}
|
|
private fun init() {
|
mRootView = LayoutInflater.from(context).inflate(R.layout.layout_slide_side_bar_left, null)
|
dialog = DialogUtil.create(context, R.layout.dialog_scene_list)
|
|
mRootView.apply {
|
leftToggle = findViewById(R.id.cv_left_toggle)
|
leftToggleText = findViewById(R.id.tv_left_toggle)
|
leftToggleImg = findViewById(R.id.img_left_toggle)
|
}
|
dialog.apply {
|
customView = findViewById(R.id.custom_view)
|
bodyView = findViewById(R.id.cv_body)
|
contentView = findViewById(R.id.rv_content)
|
title = findViewById(R.id.tv_title)
|
count = findViewById(R.id.tv_count)
|
closeBtn = findViewById(R.id.fab_close)
|
}
|
contentView.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
|
leftToggleText.text = "0"
|
|
imgDrawable?.let {
|
leftToggleImg.setImageDrawable(imgDrawable)
|
}
|
|
leftToggle.setOnClickListener(this)
|
leftToggle.setOnDragListener(this)
|
bodyView.setOnDragListener(this)
|
closeBtn.setOnClickListener(this)
|
|
val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
removeAllViews()
|
addView(mRootView, params)
|
}
|
|
private fun move(visible: Int) {
|
when (visible) {
|
View.VISIBLE->{
|
dialog.show()
|
// bodyView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.scale_zoom_in))
|
// bodyView . visibility = View . VISIBLE
|
}
|
View.GONE->{
|
dialog.dismiss()
|
// bodyView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.scale_zoom_out))
|
// bodyView.visibility = View.INVISIBLE
|
}
|
}
|
}
|
fun show() {
|
move(View.VISIBLE)
|
}
|
|
fun setToggleText(t: String) {
|
leftToggleText.text = t
|
leftToggleText.visibility = View.VISIBLE
|
}
|
|
fun setTitle(t: String) {
|
title.text = t
|
}
|
|
fun setAdapter(a: AllRecyclerViewAdapter<Scense>) {
|
contentView.adapter = a
|
notifyDataChanged()
|
}
|
|
fun notifyDataChanged() {
|
contentView.adapter?.notifyDataSetChanged()
|
val t = "${contentView.adapter?.itemCount ?: 0}个"
|
val t1 = "${contentView.adapter?.itemCount ?: 0}"
|
count.text = t
|
leftToggleText.text = t1
|
}
|
|
fun notifyDataRemoved(p: Int) {
|
contentView.adapter?.apply {
|
notifyItemRemoved(p)
|
notifyItemRangeChanged(0, itemCount - 1)
|
}
|
val t = "${contentView.adapter?.itemCount ?: 0}个"
|
val t1 = "${contentView.adapter?.itemCount ?: 0}"
|
count.text = t
|
leftToggleText.text = t1
|
}
|
|
fun notifyDataInserted(p: Int) {
|
contentView.adapter?.apply {
|
notifyItemInserted(p)
|
notifyItemRangeChanged(0, itemCount - 1)
|
}
|
val t = "${contentView.adapter?.itemCount ?: 0}个"
|
val t1 = "${contentView.adapter?.itemCount ?: 0}"
|
count.text = t
|
leftToggleText.text = t1
|
}
|
|
override fun onClick(v: View?) {
|
when (v?.id) {
|
R.id.fab_close -> {
|
move(View.GONE)
|
onCloseClickListener?.onClick(v)
|
}
|
R.id.cv_left_toggle, R.id.cv_right_toggle -> {
|
move(View.VISIBLE)
|
}
|
}
|
// when (v?.id) {
|
// R.id.cv_left_toggle -> {
|
// when (mode) {
|
// 0 -> {
|
// move(View.VISIBLE)
|
// }
|
// 1 -> {
|
// move(View.GONE)
|
// }
|
// }
|
// rightToggle.startAnimation(AnimationUtils.loadAnimation(context, R.anim.left_enter).apply {
|
// setAnimationListener(object : Animation.AnimationListener {
|
// override fun onAnimationRepeat(animation: Animation?) {
|
//
|
// }
|
//
|
// override fun onAnimationEnd(animation: Animation?) {
|
// }
|
//
|
// override fun onAnimationStart(animation: Animation?) {
|
// rightToggle.visibility = View.VISIBLE
|
// leftToggle.visibility = View.GONE
|
// }
|
//
|
// })
|
// })
|
// }
|
// R.id.cv_right_toggle -> {
|
// when (mode) {
|
// 0 -> {
|
// move(View.GONE)
|
// }
|
// 1 -> {
|
// move(View.VISIBLE)
|
// }
|
// }
|
// rightToggle.startAnimation(AnimationUtils.loadAnimation(context, R.anim.left_exit).apply {
|
// setAnimationListener(object : Animation.AnimationListener {
|
// override fun onAnimationRepeat(animation: Animation?) {
|
//
|
// }
|
//
|
// override fun onAnimationEnd(animation: Animation?) {
|
// leftToggle.visibility = View.VISIBLE
|
// }
|
//
|
// override fun onAnimationStart(animation: Animation?) {
|
// rightToggle.visibility = View.GONE
|
// }
|
//
|
// })
|
// })
|
// }
|
// }
|
}
|
|
override fun onDrag(v: View?, event: DragEvent?): Boolean {
|
return true
|
}
|
}
|