diff --git a/app/src/main/java/org/tasks/dialogs/BaseDateTimePicker.kt b/app/src/main/java/org/tasks/dialogs/BaseDateTimePicker.kt index f7fc249ce..8f7f0cde1 100644 --- a/app/src/main/java/org/tasks/dialogs/BaseDateTimePicker.kt +++ b/app/src/main/java/org/tasks/dialogs/BaseDateTimePicker.kt @@ -81,7 +81,8 @@ abstract class BaseDateTimePicker : BottomSheetDialogFragment() { .findViewById(com.google.android.material.R.id.coordinator) val containerLayout = dialog.findViewById(com.google.android.material.R.id.container) - val buttons = theme.getLayoutInflater(context).inflate(R.layout.dialog_date_time_picker_buttons, null) + val buttons = theme.getLayoutInflater(requireContext()) + .inflate(R.layout.dialog_date_time_picker_buttons, null) buttons.findViewById(R.id.cancel_button).setOnClickListener { dismiss() } buttons.findViewById(R.id.ok_button).setOnClickListener { sendSelected() } buttons.layoutParams = FrameLayout.LayoutParams( diff --git a/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt b/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt index a8ca271f6..a24db5bcb 100644 --- a/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt +++ b/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt @@ -90,7 +90,7 @@ class DateTimePicker : BaseDateTimePicker() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - binding = DialogDateTimePickerBinding.inflate(theme.getLayoutInflater(context)) + binding = DialogDateTimePickerBinding.inflate(theme.getLayoutInflater(requireContext())) setupShortcutsAndCalendar() ButterKnife.bind(this, binding.root) binding.shortcuts.nextWeekButton.text = diff --git a/app/src/main/java/org/tasks/dialogs/StartDatePicker.kt b/app/src/main/java/org/tasks/dialogs/StartDatePicker.kt index e859355a8..5d1e8c9fb 100644 --- a/app/src/main/java/org/tasks/dialogs/StartDatePicker.kt +++ b/app/src/main/java/org/tasks/dialogs/StartDatePicker.kt @@ -69,7 +69,7 @@ class StartDatePicker : BaseDateTimePicker() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - binding = DialogStartDatePickerBinding.inflate(theme.getLayoutInflater(context)) + binding = DialogStartDatePickerBinding.inflate(theme.getLayoutInflater(requireContext())) setupShortcutsAndCalendar() ButterKnife.bind(this, binding.root) binding.calendarView.setOnDateChangeListener { _, y, m, d -> diff --git a/app/src/main/java/org/tasks/themes/Theme.java b/app/src/main/java/org/tasks/themes/Theme.java deleted file mode 100644 index 8b4c859d8..000000000 --- a/app/src/main/java/org/tasks/themes/Theme.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.tasks.themes; - -import android.app.Activity; -import android.content.Context; -import android.content.res.Resources; -import android.graphics.PixelFormat; -import android.view.ContextThemeWrapper; -import android.view.LayoutInflater; -import javax.inject.Inject; -import org.tasks.R; - -public class Theme { - - private final ThemeBase themeBase; - private final ThemeColor themeColor; - private final ThemeAccent themeAccent; - - @Inject - public Theme(ThemeBase themeBase, ThemeColor themeColor, ThemeAccent themeAccent) { - this.themeBase = themeBase; - this.themeColor = themeColor; - this.themeAccent = themeAccent; - } - - public Theme withThemeColor(ThemeColor themeColor) { - return new Theme(themeBase, themeColor, themeAccent); - } - - public ThemeBase getThemeBase() { - return themeBase; - } - - public ThemeColor getThemeColor() { - return themeColor; - } - - public LayoutInflater getLayoutInflater(Context context) { - return (LayoutInflater) wrap(context).getSystemService(Context.LAYOUT_INFLATER_SERVICE); - } - - public void applyThemeAndStatusBarColor(Activity activity) { - applyTheme(activity); - themeColor.applyToSystemBars(activity); - themeColor.applyTaskDescription(activity, activity.getString(R.string.app_name)); - } - - public void applyTheme(Activity activity) { - themeBase.set(activity); - applyToContext(activity); - activity.getWindow().setFormat(PixelFormat.RGBA_8888); - } - - public void applyToContext(Context context) { - Resources.Theme theme = context.getTheme(); - themeColor.applyStyle(theme); - themeAccent.applyStyle(theme); - } - - private Context wrap(Context context) { - ContextThemeWrapper wrapper = themeBase.wrap(context); - applyToContext(wrapper); - return wrapper; - } -} diff --git a/app/src/main/java/org/tasks/themes/Theme.kt b/app/src/main/java/org/tasks/themes/Theme.kt new file mode 100644 index 000000000..4caf46c59 --- /dev/null +++ b/app/src/main/java/org/tasks/themes/Theme.kt @@ -0,0 +1,43 @@ +package org.tasks.themes + +import android.app.Activity +import android.content.Context +import android.graphics.PixelFormat +import android.view.LayoutInflater +import org.tasks.R +import javax.inject.Inject + +class Theme @Inject constructor( + val themeBase: ThemeBase, + val themeColor: ThemeColor, + private val themeAccent: ThemeAccent +) { + fun withThemeColor(themeColor: ThemeColor) = Theme(themeBase, themeColor, themeAccent) + + fun getLayoutInflater(context: Context) = + wrap(context).getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + + fun applyThemeAndStatusBarColor(activity: Activity) { + applyTheme(activity) + themeColor.applyToSystemBars(activity) + themeColor.applyTaskDescription(activity, activity.getString(R.string.app_name)) + } + + fun applyTheme(activity: Activity) { + themeBase.set(activity) + applyToContext(activity) + activity.window.setFormat(PixelFormat.RGBA_8888) + } + + fun applyToContext(context: Context) { + val theme = context.theme + themeColor.applyStyle(theme) + themeAccent.applyStyle(theme) + } + + private fun wrap(context: Context): Context { + val wrapper = themeBase.wrap(context) + applyToContext(wrapper) + return wrapper + } +} \ No newline at end of file