Commit 390ba8e0 by 范玉宾

add meditation child type more

parent 2a4e7104
...@@ -5,20 +5,41 @@ import android.view.LayoutInflater ...@@ -5,20 +5,41 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.yidianling.common.tools.ToastUtil
import com.yidianling.home.model.MeditationTypeModel import com.yidianling.home.model.MeditationTypeModel
class MeditationTypeAdapter(private val context: Context, class MeditationTypeAdapter(
private val data:List<MeditationTypeModel>):RecyclerView.Adapter<MeditationTypeAdapter.MeditationTypeViewHolder>() { private val context: Context,
private val data: List<MeditationTypeModel>
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MeditationTypeViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return MeditationTypeViewHolder(LayoutInflater.from(context) return when (viewType) {
.inflate(R.layout.layout_meditation_item,parent,false)) CONTENT_TYPE -> {
MeditationTypeViewHolder(
LayoutInflater.from(context)
.inflate(R.layout.layout_meditation_item, parent, false)
)
} }
else -> {
MeditationTypeMoreViewHolder(
LayoutInflater.from(context)
.inflate(R.layout.layout_meditation_more_type, parent, false)
)
override fun onBindViewHolder(holder: MeditationTypeViewHolder, position: Int) { }
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
is MeditationTypeViewHolder -> {
holder.ivType?.let { holder.ivType?.let {
Glide.with(context) Glide.with(context)
.load(data[position].imageUrl) .load(data[position].imageUrl)
...@@ -28,6 +49,13 @@ private val data:List<MeditationTypeModel>):RecyclerView.Adapter<MeditationTypeA ...@@ -28,6 +49,13 @@ private val data:List<MeditationTypeModel>):RecyclerView.Adapter<MeditationTypeA
holder.tvName?.let { holder.tvName?.let {
it.text = data[position].name it.text = data[position].name
} }
}
is MeditationTypeMoreViewHolder -> {
holder.llMoreLayout?.setOnClickListener {
ToastUtil.toastShort("查看更多类型!")
}
}
}
} }
...@@ -35,12 +63,30 @@ private val data:List<MeditationTypeModel>):RecyclerView.Adapter<MeditationTypeA ...@@ -35,12 +63,30 @@ private val data:List<MeditationTypeModel>):RecyclerView.Adapter<MeditationTypeA
return data.size return data.size
} }
override fun getItemId(position: Int) = position.toLong()
override fun getItemViewType(position: Int): Int {
val isMore = data[position].isMore
return if (isMore) {
FOOTER_TYPE
} else {
CONTENT_TYPE
}
}
inner class MeditationTypeViewHolder(itemView:View):RecyclerView.ViewHolder(itemView){ inner class MeditationTypeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val ivType: ImageView? = itemView.findViewById(R.id.iv_meditation_type) val ivType: ImageView? = itemView.findViewById(R.id.iv_meditation_type)
val tvName: TextView? = itemView.findViewById(R.id.tv_meditation_type) val tvName: TextView? = itemView.findViewById(R.id.tv_meditation_type)
} }
inner class MeditationTypeMoreViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val llMoreLayout: LinearLayout? = itemView.findViewById(R.id.ll_more_type)
}
companion object {
const val CONTENT_TYPE = 0
const val FOOTER_TYPE = 1
}
} }
\ No newline at end of file
package com.yidianling.home
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.yidianling.home.model.bean.MuseModuleBean
class MeditationTypeView(layoutInflater: LayoutInflater, container:ViewGroup?) {
val view:View = layoutInflater.inflate(R.layout.layout_meditation_entrance,container,false)
private val rv:RecyclerView
init {
rv = view.findViewById(R.id.rv_meditation_type)
}
fun bind(muse: MuseModuleBean.MuseDetailBean){
rv.layoutManager = LinearLayoutManager(view.context,LinearLayoutManager.HORIZONTAL,false)
rv.adapter = null
}
}
\ No newline at end of file
...@@ -3,5 +3,6 @@ package com.yidianling.home.model ...@@ -3,5 +3,6 @@ package com.yidianling.home.model
data class MeditationTypeModel( data class MeditationTypeModel(
val imageUrl:String, val imageUrl:String,
val name:String, val name:String,
val id:String val id:String,
val isMore:Boolean = false
) )
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="15dp"
android:height="10dp"
android:viewportWidth="15"
android:viewportHeight="10">
<path
android:pathData="M12.1864,5.6796L0.9072,5.6796C0.4062,5.6796 0,5.2735 0,4.7724C-0,4.2714 0.4062,3.8652 0.9072,3.8652L12.1864,3.8652C12.6874,3.8652 13.0936,4.2714 13.0936,4.7724C13.0936,5.2735 12.6874,5.6796 12.1864,5.6796Z"
android:strokeWidth="1"
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M8.1304,8.7724C8.0454,8.6876 7.9976,8.5725 7.9976,8.4524C7.9976,8.3324 8.0454,8.2172 8.1304,8.1324L11.4904,4.7724L8.1304,1.4124C7.9538,1.2357 7.9538,0.9492 8.1304,0.7724L8.7704,0.1324C8.9472,-0.0441 9.2336,-0.0441 9.4104,0.1324L13.3433,4.0653C13.7338,4.4559 13.7338,5.089 13.3433,5.4796L9.4104,9.4124L9.4104,9.4124C9.2336,9.589 8.9472,9.589 8.7704,9.4124L8.1304,8.7724Z"
android:strokeWidth="1"
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
</vector>
...@@ -15,9 +15,7 @@ import com.google.android.material.tabs.TabLayout ...@@ -15,9 +15,7 @@ import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import com.google.gson.Gson import com.google.gson.Gson
import com.ydl.ydl_image.module.GlideApp import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydlcommon.utils.LogUtil
import com.yidianling.home.MeditationViewPagerAdapter import com.yidianling.home.MeditationViewPagerAdapter
import com.yidianling.home.MeditationTypeAdapter
import com.yidianling.home.R import com.yidianling.home.R
import com.yidianling.home.constract.HomeViewConfig import com.yidianling.home.constract.HomeViewConfig
import com.yidianling.home.event.IHomeEvent import com.yidianling.home.event.IHomeEvent
...@@ -133,18 +131,21 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv ...@@ -133,18 +131,21 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
val innerData = mutableListOf<MeditationTypeModel>() val innerData = mutableListOf<MeditationTypeModel>()
for (i in 0 until 3){ for (i in 0 until 4){
val name = when(i){ val name = when(i){
0 -> "溪流" 0 -> "溪流"
1 -> "田园" 1 -> "田园"
else -> "雨声" 2 -> "雨声"
else -> "更多"
} }
val imageUrl = when(i){ val imageUrl = when(i){
0 -> "https://img0.baidu.com/it/u=2451025451,2376393604&fm=253&fmt=auto&app=138&f=JPEG?w=499&h=328" 0 -> "https://img0.baidu.com/it/u=2451025451,2376393604&fm=253&fmt=auto&app=138&f=JPEG?w=499&h=328"
1 -> "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.9ku.com%2Fgeshoutuji%2Fsingertuji%2F4%2F40945%2F40945_1.jpg&refer=http%3A%2F%2Fimg.9ku.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1654863419&t=aaea1ecc66afc7859a0cf64c06c6f2a4" 1 -> "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.9ku.com%2Fgeshoutuji%2Fsingertuji%2F4%2F40945%2F40945_1.jpg&refer=http%3A%2F%2Fimg.9ku.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1654863419&t=aaea1ecc66afc7859a0cf64c06c6f2a4"
2 -> "https://img2.baidu.com/it/u=3357363842,3633429992&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=740"
else -> "https://img2.baidu.com/it/u=3357363842,3633429992&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=740" else -> "https://img2.baidu.com/it/u=3357363842,3633429992&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=740"
} }
innerData.add(MeditationTypeModel(imageUrl,name,i.toString())) val isMore = i == 3
innerData.add(MeditationTypeModel(imageUrl,name,i.toString(),isMore))
} }
for (i in 0 until 3){ for (i in 0 until 3){
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#33FFFFFF"/>
<corners android:radius="8dp"/>
</shape>
\ No newline at end of file
...@@ -3,13 +3,14 @@ ...@@ -3,13 +3,14 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginStart="10dp" android:paddingStart="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_meditation_type" android:id="@+id/rv_meditation_type"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/> app:layout_constraintTop_toTopOf="parent"/>
......
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="6dp"> android:paddingHorizontal="6dp">
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:id="@+id/card_view" android:id="@+id/card_view"
android:layout_width="105dp" android:layout_width="105dp"
android:layout_height="102dp" android:layout_height="102dp"
android:clipToPadding="false"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:background="@color/baby_blue"
android:layout_marginHorizontal="6dp">
<LinearLayout
android:id="@+id/ll_more_type"
android:layout_width="40dp"
android:layout_height="102dp"
android:background="@drawable/bg_more_meditation"
android:gravity="center_horizontal"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_marginTop="25dp"
android:layout_marginHorizontal="13dp"
android:text="更多"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold"
android:layout_marginBottom="8dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_more_arrow_right" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment