parent
4c0af91b7b
commit
16b7a9399b
|
@ -9,11 +9,17 @@ import android.os.Build.VERSION.SDK_INT
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlinx.android.synthetic.main.onboarding_theme_picker.view.*
|
import kotlinx.android.synthetic.main.onboarding_theme_picker.view.clickable_region_automatic
|
||||||
|
import kotlinx.android.synthetic.main.onboarding_theme_picker.view.theme_automatic_radio_button
|
||||||
|
import kotlinx.android.synthetic.main.onboarding_theme_picker.view.theme_dark_image
|
||||||
|
import kotlinx.android.synthetic.main.onboarding_theme_picker.view.theme_dark_radio_button
|
||||||
|
import kotlinx.android.synthetic.main.onboarding_theme_picker.view.theme_light_image
|
||||||
|
import kotlinx.android.synthetic.main.onboarding_theme_picker.view.theme_light_radio_button
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
|
import org.mozilla.fenix.onboarding.OnboardingRadioButton
|
||||||
|
|
||||||
class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
|
||||||
|
@ -54,10 +60,12 @@ 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
|
||||||
|
@ -67,6 +75,7 @@ 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 {
|
||||||
|
@ -75,15 +84,40 @@ class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view
|
||||||
}
|
}
|
||||||
|
|
||||||
with(view.context.settings()) {
|
with(view.context.settings()) {
|
||||||
val radio = when {
|
val radio: OnboardingRadioButton
|
||||||
this.shouldUseLightTheme -> radioLightTheme
|
when {
|
||||||
this.shouldUseDarkTheme -> radioDarkTheme
|
shouldUseLightTheme -> {
|
||||||
else -> radioFollowDeviceTheme
|
radio = radioLightTheme
|
||||||
|
setLightIllustrationSelected()
|
||||||
|
}
|
||||||
|
shouldUseDarkTheme -> {
|
||||||
|
radio = radioDarkTheme
|
||||||
|
setDarkIllustrationSelected()
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
radio = radioFollowDeviceTheme
|
||||||
|
setNoIllustrationSelected()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
radio.isChecked = true
|
radio.isChecked = 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)
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
android:id="@+id/onboarding_card"
|
android:id="@+id/onboarding_card"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="16dp"
|
style="@style/OnboardingCardLight"
|
||||||
android:background="@drawable/onboarding_card_background_light"
|
|
||||||
android:paddingTop="16dp">
|
android:paddingTop="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -56,6 +55,7 @@
|
||||||
android:translationY="@dimen/onboarding_dual_pane_radio_button_translation_y"
|
android:translationY="@dimen/onboarding_dual_pane_radio_button_translation_y"
|
||||||
app:layout_constraintStart_toStartOf="@+id/theme_light_image"
|
app:layout_constraintStart_toStartOf="@+id/theme_light_image"
|
||||||
app:layout_constraintTop_toTopOf="@+id/theme_light_image"
|
app:layout_constraintTop_toTopOf="@+id/theme_light_image"
|
||||||
|
android:buttonTint="@color/onboarding_radio_button_color"
|
||||||
app:onboardingKey="@string/pref_key_light_theme" />
|
app:onboardingKey="@string/pref_key_light_theme" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
|
@ -82,6 +82,7 @@
|
||||||
android:translationY="@dimen/onboarding_dual_pane_radio_button_translation_y"
|
android:translationY="@dimen/onboarding_dual_pane_radio_button_translation_y"
|
||||||
app:layout_constraintStart_toStartOf="@+id/theme_dark_image"
|
app:layout_constraintStart_toStartOf="@+id/theme_dark_image"
|
||||||
app:layout_constraintTop_toTopOf="@+id/theme_dark_image"
|
app:layout_constraintTop_toTopOf="@+id/theme_dark_image"
|
||||||
|
android:buttonTint="@color/onboarding_radio_button_color"
|
||||||
app:onboardingKey="@string/pref_key_dark_theme" />
|
app:onboardingKey="@string/pref_key_dark_theme" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
|
@ -145,6 +146,7 @@
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/divider"
|
app:layout_constraintTop_toBottomOf="@+id/divider"
|
||||||
|
android:buttonTint="@color/onboarding_radio_button_color"
|
||||||
app:onboardingKey="@string/pref_key_follow_device_theme" />
|
app:onboardingKey="@string/pref_key_follow_device_theme" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
Loading…
Reference in New Issue