-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
270c3a8
commit 5265b43
Showing
11 changed files
with
189 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
slidingchipsview/src/main/java/id/co/edtslib/slidingchipsview/ChipAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package id.co.edtslib.slidingchipsview | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import id.co.edtslib.baserecyclerview.BaseRecyclerViewAdapter | ||
import id.co.edtslib.slidingchipsview.databinding.AdapterChipBinding | ||
|
||
class ChipAdapter<T>(private val textColor: Int, private val textPadding: Float, | ||
private val chipBackgroundColor: Int, private val strokeColor: Int, | ||
private val textStyle: Int): BaseRecyclerViewAdapter<AdapterChipBinding, T>() { | ||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> AdapterChipBinding | ||
get() = AdapterChipBinding::inflate | ||
|
||
override fun createHolder() = ChipHolder<T>(binding, textColor, textPadding, | ||
chipBackgroundColor, strokeColor, textStyle) | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
slidingchipsview/src/main/java/id/co/edtslib/slidingchipsview/ChipHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package id.co.edtslib.slidingchipsview | ||
|
||
import androidx.core.content.ContextCompat | ||
import androidx.core.widget.TextViewCompat | ||
import id.co.edtslib.baserecyclerview.BaseRecyclerViewAdapterDelegate | ||
import id.co.edtslib.baserecyclerview.BaseViewHolder | ||
import id.co.edtslib.slidingchipsview.databinding.AdapterChipBinding | ||
|
||
class ChipHolder<T>(private val binding: AdapterChipBinding, textColor: Int, | ||
textPadding: Float, chipBackgroundColor: Int, strokeColor: Int, textStyle: Int): | ||
BaseViewHolder<T>(binding) { | ||
init { | ||
binding.chip.setTextColor( | ||
ContextCompat.getColorStateList( | ||
itemView.context, | ||
textColor | ||
) | ||
) | ||
|
||
binding.chip.chipStartPadding = textPadding | ||
binding.chip.chipEndPadding = textPadding | ||
|
||
binding.chip.chipBackgroundColor = ContextCompat.getColorStateList( | ||
itemView.context, | ||
chipBackgroundColor | ||
) | ||
|
||
if (strokeColor != 0) { | ||
binding.chip.chipStrokeColor = ContextCompat.getColorStateList( | ||
itemView.context, | ||
strokeColor | ||
) | ||
binding.chip.chipStrokeWidth = itemView.context.resources.getDimensionPixelSize(R.dimen.chip_dimen_1dp).toFloat() | ||
} | ||
|
||
if (textStyle > 0) { | ||
TextViewCompat.setTextAppearance(binding.chip, textStyle) | ||
} | ||
|
||
} | ||
override fun setData( | ||
list: MutableList<T>, | ||
position: Int, | ||
delegate: BaseRecyclerViewAdapterDelegate<T>? | ||
) { | ||
val item = list[position] | ||
if (item is RecyclerData<*>) { | ||
binding.chip.text = item.data.toString() | ||
itemView.isSelected = item.selected | ||
|
||
binding.chip.setOnClickListener { | ||
delegate?.onClick(item, position, this) | ||
} | ||
|
||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
slidingchipsview/src/main/java/id/co/edtslib/slidingchipsview/RecyclerData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package id.co.edtslib.slidingchipsview | ||
|
||
data class RecyclerData<T>( | ||
val data: T, | ||
var selected: Boolean | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.