1
0
Fork 0

For #8643 and #7606 - illustrations are now connected to their radio buttons

master
Mihai Branescu 2020-04-30 12:47:15 +03:00
parent cde31cf785
commit 6f97e75579
3 changed files with 27 additions and 49 deletions

View File

@ -35,10 +35,12 @@ class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view
} }
radioLightTheme.addToRadioGroup(radioDarkTheme) radioLightTheme.addToRadioGroup(radioDarkTheme)
radioDarkTheme.addToRadioGroup(radioLightTheme)
radioLightTheme.addToRadioGroup(radioFollowDeviceTheme) radioLightTheme.addToRadioGroup(radioFollowDeviceTheme)
radioLightTheme.addIllustration(view.theme_light_image)
radioDarkTheme.addToRadioGroup(radioLightTheme)
radioDarkTheme.addToRadioGroup(radioFollowDeviceTheme) radioDarkTheme.addToRadioGroup(radioFollowDeviceTheme)
radioDarkTheme.addIllustration(view.theme_dark_image)
radioFollowDeviceTheme.addToRadioGroup(radioDarkTheme) radioFollowDeviceTheme.addToRadioGroup(radioDarkTheme)
radioFollowDeviceTheme.addToRadioGroup(radioLightTheme) radioFollowDeviceTheme.addToRadioGroup(radioLightTheme)
@ -60,12 +62,10 @@ class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view
} }
radioLightTheme.onClickListener { radioLightTheme.onClickListener {
setLightIllustrationSelected()
setNewTheme(AppCompatDelegate.MODE_NIGHT_NO) setNewTheme(AppCompatDelegate.MODE_NIGHT_NO)
} }
radioDarkTheme.onClickListener { radioDarkTheme.onClickListener {
setDarkIllustrationSelected()
view.context.components.analytics.metrics.track( view.context.components.analytics.metrics.track(
Event.DarkThemeSelected( Event.DarkThemeSelected(
Event.DarkThemeSelected.Source.ONBOARDING Event.DarkThemeSelected.Source.ONBOARDING
@ -75,7 +75,6 @@ class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view
} }
radioFollowDeviceTheme.onClickListener { radioFollowDeviceTheme.onClickListener {
setNoIllustrationSelected()
if (SDK_INT >= Build.VERSION_CODES.P) { if (SDK_INT >= Build.VERSION_CODES.P) {
setNewTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) setNewTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
} else { } else {
@ -84,40 +83,21 @@ class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view
} }
with(view.context.settings()) { with(view.context.settings()) {
val radio: OnboardingRadioButton val radio: OnboardingRadioButton = when {
when {
shouldUseLightTheme -> { shouldUseLightTheme -> {
radio = radioLightTheme radioLightTheme
setLightIllustrationSelected()
} }
shouldUseDarkTheme -> { shouldUseDarkTheme -> {
radio = radioDarkTheme radioDarkTheme
setDarkIllustrationSelected()
} }
else -> { else -> {
radio = radioFollowDeviceTheme radioFollowDeviceTheme
setNoIllustrationSelected()
} }
} }
radio.isChecked = true radio.updateRadioValue(true)
} }
} }
private fun setNoIllustrationSelected() {
itemView.theme_dark_image.isSelected = false
itemView.theme_light_image.isSelected = false
}
private fun setDarkIllustrationSelected() {
itemView.theme_dark_image.isSelected = true
itemView.theme_light_image.isSelected = false
}
private fun setLightIllustrationSelected() {
itemView.theme_dark_image.isSelected = false
itemView.theme_light_image.isSelected = true
}
private fun setNewTheme(mode: Int) { private fun setNewTheme(mode: Int) {
if (AppCompatDelegate.getDefaultNightMode() == mode) return if (AppCompatDelegate.getDefaultNightMode() == mode) return
AppCompatDelegate.setDefaultNightMode(mode) AppCompatDelegate.setDefaultNightMode(mode)

View File

@ -23,19 +23,19 @@ class OnboardingToolbarPositionPickerViewHolder(view: View) : RecyclerView.ViewH
val radio: OnboardingRadioButton val radio: OnboardingRadioButton
radioTopToolbar.addToRadioGroup(radioBottomToolbar) radioTopToolbar.addToRadioGroup(radioBottomToolbar)
radioBottomToolbar.addToRadioGroup(radioTopToolbar) radioTopToolbar.addIllustration(view.toolbar_top_image)
if (view.context.settings().shouldUseBottomToolbar) { radioBottomToolbar.addToRadioGroup(radioTopToolbar)
radio = radioBottomToolbar radioBottomToolbar.addIllustration(view.toolbar_bottom_image)
setBottomIllustrationSelected()
radio = if (view.context.settings().shouldUseBottomToolbar) {
radioBottomToolbar
} else { } else {
radio = radioTopToolbar radioTopToolbar
setTopIllustrationSelected()
} }
radio.isChecked = true radio.updateRadioValue(true)
radioBottomToolbar.onClickListener { radioBottomToolbar.onClickListener {
setBottomIllustrationSelected()
itemView.context.asActivity()?.recreate() itemView.context.asActivity()?.recreate()
} }
@ -44,7 +44,6 @@ class OnboardingToolbarPositionPickerViewHolder(view: View) : RecyclerView.ViewH
} }
radioTopToolbar.onClickListener { radioTopToolbar.onClickListener {
setTopIllustrationSelected()
itemView.context.asActivity()?.recreate() itemView.context.asActivity()?.recreate()
} }
@ -53,16 +52,6 @@ class OnboardingToolbarPositionPickerViewHolder(view: View) : RecyclerView.ViewH
} }
} }
private fun setTopIllustrationSelected() {
itemView.toolbar_top_image.isSelected = true
itemView.toolbar_bottom_image.isSelected = false
}
private fun setBottomIllustrationSelected() {
itemView.toolbar_top_image.isSelected = false
itemView.toolbar_bottom_image.isSelected = true
}
companion object { companion object {
const val LAYOUT_ID = R.layout.onboarding_toolbar_position_picker const val LAYOUT_ID = R.layout.onboarding_toolbar_position_picker
} }

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.onboarding
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.ImageButton
import androidx.appcompat.widget.AppCompatRadioButton import androidx.appcompat.widget.AppCompatRadioButton
import androidx.core.content.edit import androidx.core.content.edit
import androidx.core.content.withStyledAttributes import androidx.core.content.withStyledAttributes
@ -14,6 +15,7 @@ import org.mozilla.fenix.ext.settings
class OnboardingRadioButton(context: Context, attrs: AttributeSet) : AppCompatRadioButton(context, attrs) { class OnboardingRadioButton(context: Context, attrs: AttributeSet) : AppCompatRadioButton(context, attrs) {
private val radioGroups = mutableListOf<OnboardingRadioButton>() private val radioGroups = mutableListOf<OnboardingRadioButton>()
private var illustration: ImageButton? = null
private var clickListener: (() -> Unit)? = null private var clickListener: (() -> Unit)? = null
var key: Int = 0 var key: Int = 0
@ -31,6 +33,10 @@ class OnboardingRadioButton(context: Context, attrs: AttributeSet) : AppCompatRa
radioGroups.add(radioButton) radioGroups.add(radioButton)
} }
fun addIllustration(illustration: ImageButton) {
this.illustration = illustration
}
fun onClickListener(listener: () -> Unit) { fun onClickListener(listener: () -> Unit) {
clickListener = listener clickListener = listener
} }
@ -43,8 +49,11 @@ class OnboardingRadioButton(context: Context, attrs: AttributeSet) : AppCompatRa
} }
} }
private fun updateRadioValue(isChecked: Boolean) { fun updateRadioValue(isChecked: Boolean) {
this.isChecked = isChecked this.isChecked = isChecked
illustration?.let {
it.isSelected = isChecked
}
context.settings().preferences.edit { context.settings().preferences.edit {
putBoolean(context.getString(key), isChecked) putBoolean(context.getString(key), isChecked)
} }