From 09879401920008e3711bf5f28f73290c401cb397 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 10 Jan 2023 17:53:36 +0100 Subject: [PATCH] always use proper theme at date pickers --- .../calendar/pro/fragments/DayFragmentsHolder.kt | 8 +++++--- .../pro/fragments/MonthDayFragmentsHolder.kt | 12 +++++++++--- .../calendar/pro/fragments/MonthFragmentsHolder.kt | 12 +++++++++--- .../calendar/pro/fragments/MyFragmentHolder.kt | 12 ++++++++++++ .../calendar/pro/fragments/WeekFragmentsHolder.kt | 7 +++++-- .../calendar/pro/fragments/YearFragmentsHolder.kt | 13 +++++++++---- .../{date_picker.xml => date_picker_dark.xml} | 3 ++- app/src/main/res/layout/date_picker_light.xml | 8 ++++++++ app/src/main/res/values/styles.xml | 10 +++++++++- 9 files changed, 68 insertions(+), 17 deletions(-) rename app/src/main/res/layout/{date_picker.xml => date_picker_dark.xml} (75%) create mode 100644 app/src/main/res/layout/date_picker_light.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/DayFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/DayFragmentsHolder.kt index 5e366b91b..f6979d7ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/DayFragmentsHolder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/DayFragmentsHolder.kt @@ -15,7 +15,6 @@ import com.simplemobiletools.calendar.pro.helpers.DAY_CODE import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.interfaces.NavigationListener import com.simplemobiletools.commons.extensions.getAlertDialogBuilder -import com.simplemobiletools.commons.extensions.getDatePickerDialogTheme import com.simplemobiletools.commons.extensions.getProperBackgroundColor import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.views.MyViewPager @@ -104,8 +103,11 @@ class DayFragmentsHolder : MyFragmentHolder(), NavigationListener { } override fun showGoToDateDialog() { - requireActivity().setTheme(requireContext().getDatePickerDialogTheme()) - val view = layoutInflater.inflate(R.layout.date_picker, null) + if (activity == null) { + return + } + + val view = layoutInflater.inflate(getDatePickerDialogStyle(), null) val datePicker = view.findViewById(R.id.date_picker) val dateTime = getCurrentDate()!! diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthDayFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthDayFragmentsHolder.kt index e996aca15..0e3ed53f5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthDayFragmentsHolder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthDayFragmentsHolder.kt @@ -16,7 +16,10 @@ import com.simplemobiletools.calendar.pro.helpers.DAY_CODE import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.MONTHLY_DAILY_VIEW import com.simplemobiletools.calendar.pro.interfaces.NavigationListener -import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.extensions.beGone +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder +import com.simplemobiletools.commons.extensions.getProperBackgroundColor +import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.views.MyViewPager import kotlinx.android.synthetic.main.fragment_months_days_holder.view.* import org.joda.time.DateTime @@ -103,8 +106,11 @@ class MonthDayFragmentsHolder : MyFragmentHolder(), NavigationListener { } override fun showGoToDateDialog() { - requireActivity().setTheme(requireContext().getDatePickerDialogTheme()) - val view = layoutInflater.inflate(R.layout.date_picker, null) + if (activity == null) { + return + } + + val view = layoutInflater.inflate(getDatePickerDialogStyle(), null) val datePicker = view.findViewById(R.id.date_picker) datePicker.findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).beGone() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragmentsHolder.kt index b378b4e92..ea18afc40 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragmentsHolder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragmentsHolder.kt @@ -16,7 +16,10 @@ import com.simplemobiletools.calendar.pro.helpers.DAY_CODE import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.MONTHLY_VIEW import com.simplemobiletools.calendar.pro.interfaces.NavigationListener -import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.extensions.beGone +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder +import com.simplemobiletools.commons.extensions.getProperBackgroundColor +import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.views.MyViewPager import kotlinx.android.synthetic.main.fragment_months_holder.view.* import org.joda.time.DateTime @@ -103,8 +106,11 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener { } override fun showGoToDateDialog() { - requireActivity().setTheme(requireContext().getDatePickerDialogTheme()) - val view = layoutInflater.inflate(R.layout.date_picker, null) + if (activity == null) { + return + } + + val view = layoutInflater.inflate(getDatePickerDialogStyle(), null) val datePicker = view.findViewById(R.id.date_picker) datePicker.findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).beGone() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MyFragmentHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MyFragmentHolder.kt index 914b75799..ef6fff0c6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MyFragmentHolder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MyFragmentHolder.kt @@ -1,6 +1,10 @@ package com.simplemobiletools.calendar.pro.fragments +import android.graphics.Color import androidx.fragment.app.Fragment +import com.simplemobiletools.calendar.pro.R +import com.simplemobiletools.commons.extensions.getContrastColor +import com.simplemobiletools.commons.extensions.getProperBackgroundColor import org.joda.time.DateTime abstract class MyFragmentHolder : Fragment() { @@ -19,4 +23,12 @@ abstract class MyFragmentHolder : Fragment() { abstract fun printView() abstract fun getCurrentDate(): DateTime? + + fun getDatePickerDialogStyle(): Int { + return if (requireActivity().getProperBackgroundColor().getContrastColor() == Color.WHITE) { + R.layout.date_picker_dark + } else { + R.layout.date_picker_light + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt index bf451de74..b05906570 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt @@ -170,8 +170,11 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener { } override fun showGoToDateDialog() { - requireActivity().setTheme(requireContext().getDatePickerDialogTheme()) - val view = layoutInflater.inflate(R.layout.date_picker, null) + if (activity == null) { + return + } + + val view = layoutInflater.inflate(getDatePickerDialogStyle(), null) val datePicker = view.findViewById(R.id.date_picker) val dateTime = getCurrentDate()!! diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/YearFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/YearFragmentsHolder.kt index 0faf54e80..d8937726b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/YearFragmentsHolder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/YearFragmentsHolder.kt @@ -15,11 +15,13 @@ import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.YEARLY_VIEW import com.simplemobiletools.calendar.pro.helpers.YEAR_TO_OPEN import com.simplemobiletools.calendar.pro.interfaces.NavigationListener -import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.extensions.beGone +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder +import com.simplemobiletools.commons.extensions.getProperBackgroundColor +import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.views.MyViewPager import kotlinx.android.synthetic.main.fragment_years_holder.view.* import org.joda.time.DateTime -import kotlin.text.toInt class YearFragmentsHolder : MyFragmentHolder(), NavigationListener { private val PREFILLED_YEARS = 61 @@ -95,8 +97,11 @@ class YearFragmentsHolder : MyFragmentHolder(), NavigationListener { } override fun showGoToDateDialog() { - requireActivity().setTheme(requireContext().getDatePickerDialogTheme()) - val view = layoutInflater.inflate(R.layout.date_picker, null) + if (activity == null) { + return + } + + val view = layoutInflater.inflate(getDatePickerDialogStyle(), null) val datePicker = view.findViewById(R.id.date_picker) datePicker.findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).beGone() datePicker.findViewById(Resources.getSystem().getIdentifier("month", "id", "android")).beGone() diff --git a/app/src/main/res/layout/date_picker.xml b/app/src/main/res/layout/date_picker_dark.xml similarity index 75% rename from app/src/main/res/layout/date_picker.xml rename to app/src/main/res/layout/date_picker_dark.xml index eb92a3f8b..19e3f3998 100644 --- a/app/src/main/res/layout/date_picker.xml +++ b/app/src/main/res/layout/date_picker_dark.xml @@ -4,4 +4,5 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:calendarViewShown="false" - android:datePickerMode="spinner" /> + android:datePickerMode="spinner" + android:theme="@style/DatePickerDarkStyle" /> diff --git a/app/src/main/res/layout/date_picker_light.xml b/app/src/main/res/layout/date_picker_light.xml new file mode 100644 index 000000000..741062546 --- /dev/null +++ b/app/src/main/res/layout/date_picker_light.xml @@ -0,0 +1,8 @@ + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 3f41654af..48edffcf1 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ - + + + +