everywindchase hace 5 meses
padre
commit
ecf64a584d

+ 39 - 20
app/src/main/java/jx/cn/escort/adapter/IndexRecycleAdapter.kt

@@ -1,16 +1,12 @@
 package jx.cn.escort.adapter
 
+
 import android.content.Context
 import android.graphics.Bitmap
 import android.graphics.Canvas
 import android.graphics.Color
-import android.graphics.drawable.Drawable
-import android.view.Gravity
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import androidx.appcompat.widget.AppCompatTextView
-import androidx.cardview.widget.CardView
+import android.view.*
+import android.view.ViewGroup.MarginLayoutParams
 import androidx.core.graphics.drawable.toBitmap
 import androidx.recyclerview.widget.RecyclerView
 import com.google.android.material.divider.MaterialDivider
@@ -19,27 +15,36 @@ import com.xuexiang.xui.utils.DensityUtils
 import com.xuexiang.xui.utils.ResUtils
 import com.xuexiang.xui.widget.alpha.XUIAlphaTextView
 import jx.cn.escort.R
+import jx.cn.escort.beans.TaskData
 import jx.cn.escort.ui.widget.TaskCardView
 
 
-class IndexRecycleAdapter(): RecyclerView.Adapter<IndexRecycleAdapter.IndexRecycleViewHolder>() {
+open class IndexRecycleAdapter(): RecyclerView.Adapter<IndexRecycleAdapter.IndexRecycleViewHolder>() {
 
 
-    private var context: Context? =null
-    constructor(context:Context?):this(){
+    private var context: Context?=null
+    private var mData = mutableListOf<TaskData>()
+    constructor(context: Context?):this(){
         this.context=context
     }
+    constructor(context: Context?,  source:Collection<TaskData>):this(context){
+        if (source.isNotEmpty()) {
+            source.forEach{
+                mData.add(it)
+            }
 
+        }
 
+    }
 
 
 
 
-    class    IndexRecycleViewHolder:RecyclerView.ViewHolder{
-        var item: View?=null
-        constructor(itemView: View):super(itemView){
-            this.item=itemView
-        }
+
+
+
+    class    IndexRecycleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+        var item: View?= itemView
     }
 
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IndexRecycleViewHolder {
@@ -49,10 +54,22 @@ class IndexRecycleAdapter(): RecyclerView.Adapter<IndexRecycleAdapter.IndexRecyc
     }
 
     override fun onBindViewHolder(holder: IndexRecycleViewHolder, position: Int) {
-            val  cardView= holder.item?.findViewById<TaskCardView>(R.id.card_content)
-            val divideTop=  holder.item?.findViewById<MaterialDivider>(R.id.card_divide_top)
-            val     leftText = XUIAlphaTextView(context)
-            leftText.text="线路${position+1}"
+
+
+            val  cardView= holder.item?.findViewById<TaskCardView>(jx.cn.escort.R.id.card_content)
+            val divideTop=  holder.item?.findViewById<MaterialDivider>(jx.cn.escort.R.id.card_divide_top)
+
+            val contextThemeWrapper: ContextThemeWrapper = ContextThemeWrapper(context, jx.cn.escort.R.style.Cus_Theme_AppCompat)
+            var     leftText = XUIAlphaTextView(contextThemeWrapper)
+
+
+            var leftP=ViewGroup.MarginLayoutParams(DensityUtils.px2dp(context,300f),DensityUtils.px2dp(context,120f))  as  MarginLayoutParams
+            leftP.topMargin=30
+            leftText.layoutParams=leftP
+
+
+        val layoutPosition = holder.layoutPosition
+        leftText.text=mData.get(layoutPosition).name
             leftText.setTextColor(Color.BLACK)
             leftText.setSingleLine()
             var  mLeftImageResource = ResUtils.getDrawable(context, R.drawable.ic_task_title);
@@ -75,9 +92,11 @@ class IndexRecycleAdapter(): RecyclerView.Adapter<IndexRecycleAdapter.IndexRecyc
             cardView?.setDivideTop(divideTop)
             cardView?.addView(leftText)
 
+
     }
 
     override fun getItemCount(): Int {
-        return 10
+        return mData.size
     }
+
 }

+ 6 - 0
app/src/main/java/jx/cn/escort/beans/TaskData.kt

@@ -0,0 +1,6 @@
+package jx.cn.escort.beans
+
+data    class TaskData(
+    var name:String
+)
+

+ 8 - 2
app/src/main/java/jx/cn/escort/ui/fragment/BaseNavFragment.kt

@@ -9,9 +9,11 @@ import android.view.View
 import android.view.ViewGroup
 import androidx.fragment.app.Fragment
 import androidx.recyclerview.widget.GridLayoutManager
+import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import jx.cn.escort.R
 import jx.cn.escort.adapter.IndexRecycleAdapter
+import jx.cn.escort.beans.TaskData
 
 class BaseNavFragment(name:Int,context: Context?):Fragment() {
     private var name: Int? = null
@@ -31,9 +33,13 @@ class BaseNavFragment(name:Int,context: Context?):Fragment() {
 
                val view:View=inflater.inflate(name!!,container,false)
                 val recycle=view.findViewById<RecyclerView>(R.id.tasks_recycle)
-                var layoutManager=GridLayoutManager(context,1)
+                var layoutManager=LinearLayoutManager(context)
                 recycle.layoutManager=layoutManager
-                var indexRecycleAdapter=IndexRecycleAdapter(context)
+                var lines=mutableListOf<TaskData>()
+                for(index in 0..<10 step 1){
+                    lines.add(TaskData("线路${index}"))
+                }
+                var indexRecycleAdapter=IndexRecycleAdapter(context,lines)
                 recycle.adapter=indexRecycleAdapter
                 return view
             }else{

+ 14 - 6
app/src/main/java/jx/cn/escort/ui/widget/TaskCardView.kt

@@ -3,7 +3,6 @@ package jx.cn.escort.ui.widget
 import android.content.Context
 import android.util.AttributeSet
 import androidx.cardview.widget.CardView
-import androidx.core.view.marginTop
 import com.google.android.material.divider.MaterialDivider
 import com.xuexiang.xui.widget.alpha.XUIAlphaTextView
 
@@ -22,16 +21,25 @@ class TaskCardView : CardView {
         mDivideTop = view
     }
 
+
+
+
+
     override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec)
     }
 
     override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
+//        var materialDivider: MaterialDivider= getChildAt(0) as MaterialDivider
+//        var xuiAlphaTextView: XUIAlphaTextView= getChildAt(1) as XUIAlphaTextView
+//
+//        val mlp = materialDivider.layoutParams  as  MarginLayoutParams
+//        val topMargin=mlp.topMargin
+//
+//        val width: Int = xuiAlphaTextView.measuredWidth
+//        val height: Int = xuiAlphaTextView.measuredHeight
+//        xuiAlphaTextView.layout(l, topMargin,    r ,l);
+        super.onLayout(changed, l, t, r, b)
 
-        val marginTop = mDivideTop?.marginTop
-        if (marginTop != null) {
-            mLeftText?.layout(l,marginTop/2,t,b)
-        }
-         super.onLayout(changed, l, t, r, b)
     }
 }

+ 5 - 2
app/src/main/res/layout/fragment_tasks.xml

@@ -5,7 +5,7 @@
         xmlns:tools="http://schemas.android.com/tools"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:theme="@style/Theme.AppCompat"
+
 >
     <com.google.android.material.divider.MaterialDivider
             android:id="@+id/divide_top"
@@ -16,6 +16,7 @@
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintBottom_toTopOf="@id/divide_title"
+            android:theme="@style/App.Material"
     />
 
     <com.xuexiang.xui.widget.actionbar.TitleBar
@@ -47,12 +48,14 @@
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintBottom_toTopOf="@id/tasks_recycle"
+            android:theme="@style/App.Material"
     />
 
 
     <androidx.recyclerview.widget.RecyclerView
             android:id="@+id/tasks_recycle"
-            android:layout_width="match_parent" android:layout_height="wrap_content"
+            android:layout_marginTop="80dp"
+            android:layout_width="match_parent" android:layout_height="match_parent"
             android:scrollbars="vertical"
             android:background="#EFEFEF"
             app:layout_constraintStart_toStartOf="parent"

+ 11 - 4
app/src/main/res/layout/fragment_tasks_card.xml

@@ -9,27 +9,34 @@
                 app:contentPadding="2dp"
                 android:layout_margin="5dp"
                 app:cardBackgroundColor="#cde2e2"
-                android:theme="@style/App.Material"
         >
 
 
+<!--        <com.xuexiang.xui.widget.alpha.XUIAlphaTextView-->
+<!--                android:layout_width="300dp"-->
+<!--                android:layout_height="45dp"-->
+<!--                android:text="测试"-->
+<!--                app:drawableLeftCompat="@drawable/ic_task_title"-->
+<!--        >-->
+
+<!--        </com.xuexiang.xui.widget.alpha.XUIAlphaTextView>-->
 
         <com.google.android.material.divider.MaterialDivider
                 android:id="@+id/card_divide_top"
-                app:dividerThickness="1.pt"
+                app:dividerThickness="1pt"
                 app:dividerColor="#b5c6c6"
                 app:dividerInsetStart="2dp"
+                app:dividerInsetEnd="2dp"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginTop="45dp"
                 app:layout_constraintStart_toStartOf="parent"
                 app:layout_constraintEnd_toEndOf="parent"
+                android:theme="@style/App.Material"
 
         />
 
 
-
-
 </jx.cn.escort.ui.widget.TaskCardView>
 
 

+ 3 - 0
app/src/main/res/values/themes.xml

@@ -107,4 +107,7 @@
 
 
     <style name="Theme.Escortapp" parent="Base.Theme.Escortapp"/>
+
+
+    <style name="Cus.Theme.AppCompat"   parent="Theme.AppCompat"/>
 </resources>