riku
2025-10-17 fbae5f3ea74727ccadc48314a864a1ea0099a945
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
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
    }
}