11package  com.github.aachartmodel.aainfographics.demo.basiccontent 
22
33import  android.content.Context 
4+ import  android.content.res.ColorStateList 
45import  android.graphics.Color 
56import  android.view.LayoutInflater 
67import  android.view.View 
78import  android.view.ViewGroup 
89import  android.widget.BaseExpandableListAdapter 
10+ import  android.widget.ImageView 
911import  android.widget.TextView 
12+ import  androidx.core.graphics.ColorUtils 
13+ import  androidx.core.view.ViewCompat 
1014import  com.github.aachartmodel.aainfographics.demo.R 
15+ import  com.google.android.material.card.MaterialCardView 
1116
1217class  MyBaseExpandableListAdapter (
1318 private  val  gData :  Array <String >,
@@ -77,11 +82,35 @@ class MyBaseExpandableListAdapter(
7782 )
7883 groupHolder =  ViewHolderGroup ()
7984 groupHolder.tv_group_name =  convertView.findViewById<View >(R .id.tv_group_name) as  TextView 
85+  groupHolder.iv_indicator =  convertView.findViewById(R .id.iv_group_indicator) as  ImageView 
86+  groupHolder.cardContainer =  convertView.findViewById(R .id.card_group_container) as  MaterialCardView 
8087 convertView.tag =  groupHolder
8188 } else  {
8289 groupHolder =  convertView.tag as  ViewHolderGroup 
8390 }
84-  groupHolder.tv_group_name!! .text =  gData[groupPosition]
91+  val  accentColor =  parseGroupColor(groupPosition)
92+  groupHolder.tv_group_name?.text =  gData[groupPosition]
93+  groupHolder.tv_group_name?.setTextColor(ColorUtils .setAlphaComponent(accentColor, 230 ))
94+ 
95+  groupHolder.cardContainer?.strokeColor =  ColorUtils .setAlphaComponent(accentColor, 60 )
96+  groupHolder.cardContainer?.rippleColor =  ColorStateList .valueOf(ColorUtils .setAlphaComponent(accentColor, 80 ))
97+  groupHolder.cardContainer?.setCardBackgroundColor(
98+  if  (isExpanded) ColorUtils .setAlphaComponent(accentColor, 24 ) else  Color .WHITE 
99+  )
100+ 
101+  groupHolder.iv_indicator?.let  { indicator -> 
102+  val  targetRotation =  if  (isExpanded) 180f  else  0f 
103+  if  (indicator.rotation !=  targetRotation) {
104+  indicator.animate()?.cancel()
105+  indicator.animate()
106+  ?.rotation(targetRotation)
107+  ?.setDuration(200L )
108+  ?.start()
109+  } else  {
110+  indicator.animate()?.cancel()
111+  indicator.rotation =  targetRotation
112+  }
113+  }
85114 return  convertView
86115 }
87116
@@ -100,16 +129,33 @@ class MyBaseExpandableListAdapter(
100129 R .layout.item_exlist_item, parent, false 
101130 )
102131 itemHolder =  ViewHolderItem ()
103-  itemHolder.tv_color_dot =  convertView.findViewById<View >(R .id.tv_color_dot) as  TextView 
104-  itemHolder.tv_name =  convertView.findViewById<View >(R .id.tv_name) as  TextView 
132+  itemHolder.cardContainer =  convertView.findViewById(R .id.card_item_container) as  MaterialCardView 
133+  itemHolder.tv_color_dot =  convertView.findViewById(R .id.tv_color_dot) as  TextView 
134+  itemHolder.tv_name =  convertView.findViewById(R .id.tv_name) as  TextView 
135+  itemHolder.tv_subtitle =  convertView.findViewById(R .id.tv_subtitle) as  TextView 
136+  itemHolder.ivChevron =  convertView.findViewById(R .id.iv_item_chevron) as  ImageView 
105137 convertView.tag =  itemHolder
106138 } else  {
107139 itemHolder = 
108140 convertView.tag as  ViewHolderItem 
109141 }
110-  val  colorStr =  colorsArr[groupPosition]
111-  itemHolder.tv_color_dot?.setTextColor(Color .parseColor(colorStr))
142+  val  accentColor =  parseGroupColor(groupPosition)
143+  itemHolder.tv_color_dot?.setTextColor(accentColor)
144+  itemHolder.tv_color_dot?.let  {
145+  ViewCompat .setBackgroundTintList(
146+  it,
147+  ColorStateList .valueOf(ColorUtils .setAlphaComponent(accentColor, 60 ))
148+  )
149+  }
150+ 
112151 itemHolder.tv_name?.text =  iData[groupPosition][childPosition]
152+  itemHolder.tv_subtitle?.setTextColor(ColorUtils .setAlphaComponent(accentColor, 170 ))
153+ 
154+  itemHolder.cardContainer?.strokeColor =  ColorUtils .setAlphaComponent(accentColor, 45 )
155+  itemHolder.cardContainer?.setCardBackgroundColor(ColorUtils .setAlphaComponent(accentColor, 16 ))
156+  itemHolder.cardContainer?.rippleColor =  ColorStateList .valueOf(ColorUtils .setAlphaComponent(accentColor, 90 ))
157+  itemHolder.ivChevron?.rotation =  - 90f 
158+  itemHolder.ivChevron?.imageTintList =  ColorStateList .valueOf(ColorUtils .setAlphaComponent(accentColor, 200 ))
113159 return  convertView
114160 }
115161
@@ -118,13 +164,23 @@ class MyBaseExpandableListAdapter(
118164 return  true 
119165 }
120166
167+  private  fun  parseGroupColor (groupPosition :  Int ): Int  {
168+  val  colorStr =  colorsArr[groupPosition %  colorsArr.size]
169+  return  Color .parseColor(colorStr)
170+  }
171+ 
121172 private  class  ViewHolderGroup  {
122173 var  tv_group_name:  TextView ?  =  null 
174+  var  iv_indicator:  ImageView ?  =  null 
175+  var  cardContainer:  MaterialCardView ?  =  null 
123176 }
124177
125178 private  class  ViewHolderItem  {
179+  var  cardContainer:  MaterialCardView ?  =  null 
126180 var  tv_color_dot:  TextView ?  =  null 
127181 var  tv_name:  TextView ?  =  null 
182+  var  tv_subtitle:  TextView ?  =  null 
183+  var  ivChevron:  ImageView ?  =  null 
128184 }
129185
130186}
0 commit comments