Skip to content

Commit

Permalink
Minor improvements to adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
Akilesh-T committed Jul 9, 2020
1 parent 20bb357 commit 73ba9ae
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ class BackupRestoreFragment: Fragment() {
titleIcon.setImageResource(R.drawable.ic_backup_contents)
}

val colorListAdapter =
ColorListAdapter(
requireContext(),
accents
) {}
val colorListAdapter = ColorListAdapter(accents) {}

colorPreviewBinding.recyclerViewColor.apply {
adapter = colorListAdapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.akilesh.qacc.ui.colorpicker

import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.view.LayoutInflater
Expand All @@ -12,7 +11,6 @@ import app.akilesh.qacc.databinding.RecyclerviewItemColorPreviewBinding
import app.akilesh.qacc.model.Colour

class ColorListAdapter internal constructor(
private val context: Context,
private val colours: List<Colour>,
val adapterOnClick : (Colour) -> Unit
) : RecyclerView.Adapter<ColorListAdapter.ColorViewHolder>() {
Expand All @@ -26,13 +24,15 @@ class ColorListAdapter internal constructor(
override fun onBindViewHolder(holder: ColorViewHolder, position: Int) = holder.bind(colours[position])

inner class ColorViewHolder(private var binding: RecyclerviewItemColorPreviewBinding) : RecyclerView.ViewHolder(binding.root) {
init {
binding.colorCard.setOnClickListener { adapterOnClick(colours[adapterPosition]) }
}
fun bind(colour: Colour) {
val backgroundColor = Color.parseColor(colour.hex)
val textColor = Palette.Swatch(backgroundColor, 1).bodyTextColor
binding.colorCard.backgroundTintList = ColorStateList.valueOf(backgroundColor)
binding.colorName.text = String.format(context.resources.getString(R.string.colour), colour.name, colour.hex)
binding.colorName.text = binding.colorName.context.resources.getString(R.string.colour, colour.name, colour.hex)
binding.colorName.setTextColor(textColor)
binding.colorCard.setOnClickListener { adapterOnClick(colour) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ interface ColorPicker {
val dialog = builder.create()

val colorListAdapter = ColorListAdapter(
context,
colorList
) { selectedColour ->
viewModel.colour.hex = selectedColour.hex
Expand Down Expand Up @@ -98,10 +97,11 @@ interface ColorPicker {

mdColorPaletteBinding.pager.apply {
setPageTransformer(ZoomOutPageTransformer())
adapter = MDColorsViewPagerAdapter(context, viewModel, binding, dialog)
adapter = MDColorsViewPagerAdapter(viewModel, binding, dialog)
}
setTabIndicatorColor(mdColorPaletteBinding.tabLayout, 0)
TabLayoutMediator(mdColorPaletteBinding.tabLayout, mdColorPaletteBinding.pager) { _, _ ->
TabLayoutMediator(mdColorPaletteBinding.tabLayout, mdColorPaletteBinding.pager) { tab, _ ->
tab.view.isClickable = false
}.attach()
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
val useSystemAccent = sharedPreferences.getBoolean("system_accent", false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.akilesh.qacc.ui.colorpicker

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
Expand All @@ -16,7 +15,6 @@ import app.akilesh.qacc.utils.AppUtils.getColorAccent
import app.akilesh.qacc.utils.AppUtils.setPreview

class MDColorsViewPagerAdapter internal constructor(
private val context: Context,
private val viewModel: ColorPickerViewModel,
private val colorPickerFragmentBinding: ColorPickerFragmentBinding,
private val dialog: AlertDialog
Expand All @@ -38,7 +36,6 @@ class MDColorsViewPagerAdapter internal constructor(
inner class MDColorViewHolder(private var binding: ColorPreviewBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(position: Int) {
val colorListAdapter = ColorListAdapter(
context,
mdColorPalette.getValue(position)
) { selectedColour ->
viewModel.colour.hex = selectedColour.hex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class CreateAllFragment: Fragment() {
createAllAdapter.colours.addAll(AEX)
createAllAdapter.colours.addAll(brandColors)
binding.accentListRv.apply {
setHasFixedSize(true)
setItemViewCacheSize(15)
adapter = createAllAdapter
layoutManager = GridLayoutManager(requireContext(), 2, GridLayoutManager.VERTICAL, false)
}
Expand Down

0 comments on commit 73ba9ae

Please sign in to comment.