From 3013b813e5df6977c0be921928f73b1a3adde290 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 02 七月 2025 15:52:04 +0800
Subject: [PATCH] ### 一、巡查模块相关

---
 app/src/main/java/cn/flightfeather/thirdappmodule/view/BannerView.kt |   52 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/app/src/main/java/cn/flightfeather/thirdappmodule/view/BannerView.kt b/app/src/main/java/cn/flightfeather/thirdappmodule/view/BannerView.kt
index d937b4c..6b7357f 100644
--- a/app/src/main/java/cn/flightfeather/thirdappmodule/view/BannerView.kt
+++ b/app/src/main/java/cn/flightfeather/thirdappmodule/view/BannerView.kt
@@ -9,17 +9,20 @@
 import android.view.Gravity
 import android.view.View
 import android.view.ViewGroup
-import android.widget.LinearLayout
-import android.widget.RelativeLayout
-import android.widget.TextView
+import android.widget.*
 import cn.flightfeather.thirdappmodule.R
+import cn.flightfeather.thirdappmodule.adapter.AllListViewAdapter
+import cn.flightfeather.thirdappmodule.bean.entity.Province
 import cn.flightfeather.thirdappmodule.util.dp
 import io.reactivex.Observable
 import io.reactivex.android.schedulers.AndroidSchedulers
 import io.reactivex.schedulers.Schedulers
+import kotlinx.android.synthetic.main.activity_scense_detail.*
 import org.jetbrains.anko.alignParentBottom
 import org.jetbrains.anko.alignParentEnd
+import org.jetbrains.anko.alignParentStart
 import org.jetbrains.anko.backgroundResource
+import kotlin.collections.ArrayList
 
 
 /**
@@ -29,15 +32,15 @@
  */
 class BannerView : RelativeLayout {
 
-    constructor(context: Context) : super(context){
+    constructor(context: Context) : super(context) {
         mContext = context
     }
 
-    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs){
+    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
         mContext = context
     }
 
-    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr){
+    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
         mContext = context
     }
 
@@ -46,6 +49,7 @@
     private val viewPager = MyViewPager(context)
     private val dots = LinearLayout(context)
     private val index = LinearLayout(context)
+    private val spinner = Spinner(context)
     private var currentIndex: TextView? = null
     private var curPos = 0
     private var lastPos = 0
@@ -62,6 +66,12 @@
             initDots()
             initIndex()
 //            initObservable()
+        }
+
+    var menus = listOf<String>()
+        set(value) {
+            field = value
+            initSpinner()
         }
 
     fun refresh() {
@@ -86,7 +96,7 @@
         }.subscribe()
     }
 
-    private fun initViewPager(){
+    private fun initViewPager() {
         val viewPagerParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
         viewPager.adapter = ViewPagerAdapter(dataList)
         viewPager.currentItem = 0
@@ -106,7 +116,9 @@
                 dots.getChildAt(newPos).isEnabled = true
                 lastPos = newPos
 
-                (index.getChildAt(0) as TextView).text = "${p0 + 1}"
+                (index.getChildAt(0) as TextView).text = "${newPos + 1}"
+
+                spinner.setSelection(newPos)
             }
 
         })
@@ -171,4 +183,28 @@
         addView(index)
     }
 
+    private fun initSpinner() {
+        val spinnerParams = LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
+        spinnerParams.alignParentBottom()
+        spinnerParams.alignParentStart()
+
+        spinner.apply {
+            adapter = object : AllListViewAdapter<String>(ArrayList(menus), R.layout.item_spinner_drop_down_custom) {
+                override fun bindView(holder: ViewHolder, obj: String) {
+                    holder.setText(R.id.text1, obj)
+                }
+            }
+            onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
+                override fun onNothingSelected(parent: AdapterView<*>?) = Unit
+                override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
+                    viewPager.setCurrentItem(position, true)
+                }
+            }
+            layoutParams = spinnerParams
+            background = ContextCompat.getDrawable(context, R.drawable.shape_black_spinner)
+            setPadding(0, 0, 20.dp, 0)
+        }
+        addView(spinner)
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3