Skip to content

Commit

Permalink
Merge pull request #247 from Spendesk/release/1.11.2
Browse files Browse the repository at this point in the history
Release/1.11.2
  • Loading branch information
Scythe14 authored Jul 27, 2023
2 parents 88b79c1 + e5dfe6e commit ac2ebd2
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 27 deletions.
5 changes: 0 additions & 5 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
buildscript {

ext {
grapes_version = '1.11.1'
grapes_version = '1.11.2'

kotlin_version = '1.7.10'
firebase_app_distribution_version = '2.1.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package com.spendesk.grapes.selectors
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.spendesk.grapes.R
import kotlin.properties.Delegates

/**
* @author danyboucanova
* @since 08/06/2021
*/
class PickerAdapter : RecyclerView.Adapter<PickerAdapter.PickerViewHolder>() {
class PickerAdapter(
private val itemsWidth: Int = ViewGroup.LayoutParams.WRAP_CONTENT,
private val itemsHeight: Int = ViewGroup.LayoutParams.WRAP_CONTENT
) : RecyclerView.Adapter<PickerAdapter.PickerViewHolder>() {

sealed class PickerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
class Label(val view: PickerLabelTextView) : PickerViewHolder(view)
Expand All @@ -29,12 +31,12 @@ class PickerAdapter : RecyclerView.Adapter<PickerAdapter.PickerViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PickerViewHolder =
when (PickerViewType.values()[viewType]) {
PickerViewType.LABEL -> PickerViewHolder.Label(PickerLabelTextView(parent.context))
PickerViewType.BLOCK -> PickerViewHolder.Block(PickerBlockIconCardView(parent.context))
PickerViewType.LABEL -> PickerViewHolder.Label(PickerLabelTextView(parent.context))
}.apply {
this.itemView.layoutParams = when (this) {
is PickerViewHolder.Label -> RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
is PickerViewHolder.Block -> RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
is PickerViewHolder.Label,
is PickerViewHolder.Block -> RecyclerView.LayoutParams(itemsWidth, itemsHeight)
}
}

Expand All @@ -46,6 +48,7 @@ class PickerAdapter : RecyclerView.Adapter<PickerAdapter.PickerViewHolder>() {
holder.view.updateConfiguration(data.configuration.copy(isSelected = position == selectedPosition))
handleOnClickListener(holder.itemView, position, data.id)
}

is PickerViewHolder.Block -> {
val data = listItems[position] as PickerModel.Block

Expand Down Expand Up @@ -81,4 +84,4 @@ class PickerAdapter : RecyclerView.Adapter<PickerAdapter.PickerViewHolder>() {
onItemSelected?.invoke(selectedPosition, itemId)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.graphics.Typeface
import android.util.AttributeSet
import android.util.TypedValue
import android.view.Gravity
import androidx.annotation.DimenRes
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.setPadding
Expand All @@ -25,8 +26,6 @@ class PickerLabelTextView : SelectLabelTextView {
//endregion constructors

init {
with(resources.getDimensionPixelOffset(R.dimen.pickerLabelPadding)) { setPadding(this) }

isClickable = true
gravity = Gravity.CENTER

Expand All @@ -36,13 +35,15 @@ class PickerLabelTextView : SelectLabelTextView {

data class Configuration(
val isSelected: Boolean,
val text: CharSequence
val text: CharSequence,
@DimenRes val padding: Int? = null,
)

fun updateConfiguration(configuration: Configuration) {
text = configuration.text
isChecked = configuration.isSelected

configuration.padding?.let { setPadding(resources.getDimensionPixelOffset(it)) }
setTextColor(ContextCompat.getColor(context, if (configuration.isSelected) R.color.pickerLabelSelectedTextColor else R.color.pickerLabelUnselectedTextColor))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ sealed class PickerModel(val viewType: PickerViewType) {

class Label(val id: String, val configuration: PickerLabelTextView.Configuration) : PickerModel(PickerViewType.LABEL)
class Block(val id: String, val configuration: PickerBlockIconCardView.Configuration) : PickerModel(PickerViewType.BLOCK)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ package com.spendesk.grapes.selectors
enum class PickerViewType {
LABEL,
BLOCK
}
}
3 changes: 1 addition & 2 deletions library/src/main/res/values/dimens_selectors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

<dimen name="pickerTextListViewItemDecorationMarginVert">@dimen/normalMargin</dimen>

<dimen name="pickerLabelPadding">16dp</dimen>
<dimen name="pickerLabelTextSize">16sp</dimen>
<dimen name="pickerListViewMargin">16dp</dimen>
<dimen name="pickerTextListViewMarginHorz">16dp</dimen>
Expand Down Expand Up @@ -39,4 +38,4 @@
<dimen name="keyboardSuggestionsViewTextSize">16sp</dimen>
<dimen name="keyboardSuggestionsViewTextPaddingVertical">12dp</dimen>

</resources>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ package com.spendesk.grapes.samples.home.fragments

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.spendesk.grapes.extensions.shortToaster
import com.spendesk.grapes.samples.R
import com.spendesk.grapes.samples.core.internal.viewBinding
import com.spendesk.grapes.samples.databinding.FragmentHomeSelectorsBinding
import com.spendesk.grapes.selectors.*
import com.spendesk.grapes.selectors.DotsView
import com.spendesk.grapes.selectors.HeaderStatusIndicator
import com.spendesk.grapes.selectors.PickerAdapter
import com.spendesk.grapes.selectors.PickerBlockIconCardView
import com.spendesk.grapes.selectors.PickerLabelTextView
import com.spendesk.grapes.selectors.PickerModel
import com.spendesk.grapes.selectors.SelectorView
import com.spendesk.grapes.selectors.SwitchCardView
import com.spendesk.grapes.selectors.TabCardView
import kotlin.random.Random

/**
Expand Down Expand Up @@ -74,7 +83,7 @@ class SelectorFragment : Fragment(R.layout.fragment_home_selectors) {
}

// Picker Cards List
val pickerCardListViewAdapter = PickerAdapter()
val pickerCardListViewAdapter = PickerAdapter(itemsWidth = ViewGroup.LayoutParams.WRAP_CONTENT, itemsHeight = ViewGroup.LayoutParams.WRAP_CONTENT)
val pickerCardListModel = listOf<PickerModel>(
PickerModel.Block(
id = "lel",
Expand Down Expand Up @@ -108,12 +117,12 @@ class SelectorFragment : Fragment(R.layout.fragment_home_selectors) {


// Picker Texts List
val pickerTextListViewAdapter = PickerAdapter()
val pickerTextListViewAdapter = PickerAdapter(itemsWidth = ViewGroup.LayoutParams.WRAP_CONTENT, itemsHeight = ViewGroup.LayoutParams.WRAP_CONTENT)
val pickerTextListModel = listOf<PickerModel>(
PickerModel.Label(id = "hoy", configuration = PickerLabelTextView.Configuration(isSelected = false, "level 1")),
PickerModel.Label(id = "hey", configuration = PickerLabelTextView.Configuration(isSelected = false, "level 2")),
PickerModel.Label(id = "hoyjoy", configuration = PickerLabelTextView.Configuration(isSelected = false, "level 3")),
PickerModel.Label(id = "uesh", configuration = PickerLabelTextView.Configuration(isSelected = false, "level 4"))
PickerModel.Label(id = "hoy", configuration = PickerLabelTextView.Configuration(isSelected = false, "level 1", padding = R.dimen.normalMargin)),
PickerModel.Label(id = "hey", configuration = PickerLabelTextView.Configuration(isSelected = false, "level 2", padding = R.dimen.normalMargin)),
PickerModel.Label(id = "hoyjoy", configuration = PickerLabelTextView.Configuration(isSelected = false, "level 3", padding = R.dimen.normalMargin)),
PickerModel.Label(id = "uesh", configuration = PickerLabelTextView.Configuration(isSelected = false, "level 4", padding = R.dimen.normalMargin))
)
homeSelectorsSectionPickerTextListView.adapter = pickerTextListViewAdapter
pickerTextListViewAdapter.onItemSelected = { _, _ -> activity?.shortToaster("Picker Card Item List Checked !") }
Expand Down

0 comments on commit ac2ebd2

Please sign in to comment.