@@ -40,8 +40,6 @@ open class PaymentOptionsView @JvmOverloads constructor(
4040 recyclerView.adapter = adapter
4141 recyclerView.layoutManager = LinearLayoutManager (context, LinearLayoutManager .VERTICAL , false )
4242 recyclerView.itemAnimator = null
43- val dividerItemDecoration = DividerItemDecoration (context, LinearLayoutManager .VERTICAL )
44- recyclerView.addItemDecoration(dividerItemDecoration)
4543 adapter.submitList(getEntries())
4644
4745 val listener = PaymentCredentialsStore .Callback {
@@ -110,6 +108,12 @@ open class PaymentOptionsView @JvmOverloads constructor(
110108 it.type == PaymentCredentials .Type .PAYDIREKT
111109 }
112110
111+ if (globalList.size > 0 ) {
112+ globalList.add(
113+ Entry (isDivider = true )
114+ )
115+ }
116+
113117 globalList.add(
114118 Entry (
115119 text = " Paydirekt" ,
@@ -137,13 +141,19 @@ open class PaymentOptionsView @JvmOverloads constructor(
137141
138142 projectsWithCreditCards
139143 .filter { it.brand == null }
140- .forEach { project ->
144+ .forEachIndexed { i, project ->
141145 val count = credentials.count {
142146 it.appId == Snabble .getInstance().config.appId &&
143147 it.type == PaymentCredentials .Type .CREDIT_CARD_PSD2 &&
144148 it.projectId == project.id
145149 }
146150
151+ if (i > 0 ) {
152+ projectList.add(
153+ Entry (isDivider = true )
154+ )
155+ }
156+
147157 projectList.add(
148158 Entry (
149159 text = project.name,
@@ -251,13 +261,16 @@ open class PaymentOptionsView @JvmOverloads constructor(
251261
252262 data class Entry (
253263 val isSectionHeader : Boolean = false ,
254- val text : String ,
264+ val isDivider : Boolean = false ,
265+ val text : String? = null ,
255266 val count : Int = 0 ,
256267 val icon : Int? = null ,
257268 val project : Project ? = null ,
258269 val click : OnClickListener ? = null ,
259270 )
260271
272+ class DividerViewHolder (itemView : View ) : RecyclerView.ViewHolder(itemView)
273+
261274 class HeaderViewHolder (itemView : View ) : RecyclerView.ViewHolder(itemView) {
262275 val text: TextView = itemView.findViewById(R .id.text)
263276 }
@@ -272,15 +285,28 @@ open class PaymentOptionsView @JvmOverloads constructor(
272285 companion object {
273286 const val SECTION_HEADER = 0
274287 const val ENTRY = 1
288+ const val DIVIDER = 2
275289 }
276290 override fun getItemViewType (position : Int ): Int {
277- return if (getItem(position).isSectionHeader) SECTION_HEADER else ENTRY
291+ val item = getItem(position)
292+ return when {
293+ item.isSectionHeader -> {
294+ SECTION_HEADER
295+ }
296+ item.isDivider -> {
297+ DIVIDER
298+ }
299+ else -> {
300+ ENTRY
301+ }
302+ }
278303 }
279304
280305 override fun onCreateViewHolder (parent : ViewGroup , viewType : Int ): RecyclerView .ViewHolder {
281306 val inflater = LayoutInflater .from(parent.context)
282307 return when (viewType) {
283308 SECTION_HEADER -> HeaderViewHolder (inflater.inflate(R .layout.snabble_item_payment_options_header, parent, false ))
309+ DIVIDER -> DividerViewHolder (inflater.inflate(R .layout.snabble_divider, parent, false ))
284310 else -> EntryViewHolder (inflater.inflate(R .layout.snabble_item_payment_options_entry, parent, false ))
285311 }
286312 }
0 commit comments