Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

Fix issue #1961 #1972

Merged
merged 2 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.view.View
import android.view.View.OnClickListener
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.appcompat.widget.AppCompatRadioButton
import androidx.core.widget.CompoundButtonCompat
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -72,7 +73,9 @@ internal class SingleChoiceDialogAdapter(
disabledItems: IntArray?,
initialSelection: Int,
private val waitForActionButton: Boolean,
internal var selection: SingleChoiceListener
internal var selection: SingleChoiceListener,
@ColorInt private val checkedColor: Int,
@ColorInt private val uncheckedColor: Int
) : RecyclerView.Adapter<SingleChoiceViewHolder>(),
DialogAdapter<CharSequence, SingleChoiceListener> {

Expand Down Expand Up @@ -117,7 +120,10 @@ internal class SingleChoiceDialogAdapter(
.let {
CompoundButtonCompat.setButtonTintList(
viewHolder.controlView,
createColorSelector(dialog.windowContext, checked = it[0], unchecked = it[1])
createColorSelector(dialog.windowContext,
checked = if (checkedColor == -1) it[0] else checkedColor,
unchecked = if (uncheckedColor == -1) it[1] else uncheckedColor
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.afollestad.materialdialogs.list
import android.util.Log
import androidx.annotation.ArrayRes
import androidx.annotation.CheckResult
import androidx.annotation.ColorInt
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton.POSITIVE
import com.afollestad.materialdialogs.actions.setActionButtonEnabled
Expand All @@ -42,6 +43,8 @@ import com.afollestad.materialdialogs.utils.MDUtil.getStringArray
disabledIndices: IntArray? = null,
initialSelection: Int = -1,
waitForPositiveButton: Boolean = true,
@ColorInt checkedColor: Int = -1,
@ColorInt uncheckedColor: Int = -1,
selection: SingleChoiceListener = null
): MaterialDialog {
assertOneSet("listItemsSingleChoice", items, res)
Expand Down Expand Up @@ -72,7 +75,9 @@ import com.afollestad.materialdialogs.utils.MDUtil.getStringArray
disabledItems = disabledIndices,
initialSelection = initialSelection,
waitForActionButton = waitForPositiveButton,
selection = selection
selection = selection,
checkedColor = checkedColor,
uncheckedColor = uncheckedColor
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,20 @@ class MainActivity : AppCompatActivity() {
}
}

R.id.single_choice_custom_radio_color.onClickDebounced {
MaterialDialog(this).show {
title(R.string.socialNetworks)
listItemsSingleChoice(
R.array.socialNetworks, initialSelection = 1, checkedColor = Color.RED, uncheckedColor = Color.CYAN
) { _, index, text ->
toast("Selected item $text at index $index")
}
positiveButton(R.string.choose)
debugMode(debugMode)
lifecycleOwner(this@MainActivity)
}
}

R.id.multiple_choice.onClickDebounced {
MaterialDialog(this).show {
title(R.string.socialNetworks)
Expand Down
6 changes: 6 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@
style="@style/SampleButton"
/>

<Button
android:id="@+id/single_choice_custom_radio_color"
android:text="Single Choice, Custom Radio Color"
style="@style/SampleButton"
/>

<!-- Multiple Choice Lists -->

<TextView
Expand Down