Skip to content

Commit

Permalink
Merge pull request #19 from Trendyol/feature/rippleeffects
Browse files Browse the repository at this point in the history
Feature/rippleeffects
  • Loading branch information
MertNYuksel authored Jan 6, 2020
2 parents 7a8784d + 04c30c2 commit d4582e9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.trendyol.uicomponents.dialogs.list

import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.trendyol.dialog.R
import com.trendyol.dialog.databinding.ItemListBinding
Expand All @@ -10,28 +11,20 @@ internal class DialogListAdapter(
private val showItemsAsHtml: Boolean,
private val selectedItemDrawable: Int?,
private val selectedTextColor: Int?
) : RecyclerView.Adapter<DialogListAdapter.ItemViewHolder>() {

private var items: List<Pair<Boolean, CharSequence>> = emptyList()
) : ListAdapter<Pair<Boolean, CharSequence>, DialogListAdapter.ItemViewHolder>(ListItemDiffCallback()) {
var onItemSelectedListener: ((Int) -> Unit)? = null

fun setItems(list: List<Pair<Boolean, CharSequence>>) {
items = items.toMutableList().apply {
clear()
addAll(list)
}
notifyDataSetChanged()
submitList(list.toMutableList())
}

override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
holder.bind(items[position])
holder.bind(getItem(position))
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder =
ItemViewHolder(parent.inflate(R.layout.item_list, false))

override fun getItemCount(): Int = items.size

inner class ItemViewHolder(
private val binding: ItemListBinding
) : RecyclerView.ViewHolder(binding.root) {
Expand All @@ -55,4 +48,4 @@ internal class DialogListAdapter(
binding.executePendingBindings()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.trendyol.uicomponents.dialogs.list

import androidx.recyclerview.widget.DiffUtil

class ListItemDiffCallback: DiffUtil.ItemCallback<Pair<Boolean, CharSequence>>() {
override fun areContentsTheSame(
oldItem: Pair<Boolean, CharSequence>,
newItem: Pair<Boolean, CharSequence>
): Boolean {
return oldItem.first == newItem.first && oldItem.second.toString() == newItem.second.toString()
}

override fun areItemsTheSame(
oldItem: Pair<Boolean, CharSequence>,
newItem: Pair<Boolean, CharSequence>
): Boolean {
return oldItem.second == newItem.second
}
}
1 change: 1 addition & 0 deletions libraries/dialogs/src/main/res/layout/fragment_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
android:layout_gravity="center_vertical"
android:padding="@dimen/dialogs_margin_inner"
app:isVisible="@{viewState.showCloseButton}"
android:background="?selectableItemBackgroundBorderless"
app:srcCompat="@drawable/ic_close" />
</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions libraries/dialogs/src/main/res/layout/item_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:padding="@dimen/dialogs_margin_outer">

<androidx.appcompat.widget.AppCompatTextView
Expand Down

0 comments on commit d4582e9

Please sign in to comment.