diff --git a/app/src/main/java/org/tasks/dialogs/ColorPalettePicker.kt b/app/src/main/java/org/tasks/dialogs/ColorPalettePicker.kt index 91c72ab91..4bec0a106 100644 --- a/app/src/main/java/org/tasks/dialogs/ColorPalettePicker.kt +++ b/app/src/main/java/org/tasks/dialogs/ColorPalettePicker.kt @@ -79,12 +79,12 @@ class ColorPalettePicker : InjectingDialogFragment() { val inflater = LayoutInflater.from(context) val view = inflater.inflate(R.layout.dialog_icon_picker, null) ButterKnife.bind(this, view) - palette = arguments!!.getSerializable(EXTRA_PALETTE) as Palette + palette = requireArguments().getSerializable(EXTRA_PALETTE) as Palette colors = when (palette) { Palette.COLORS -> colorProvider.getThemeColors() Palette.ACCENTS -> colorProvider.getAccentColors() Palette.LAUNCHERS -> ThemeColor.LAUNCHER_COLORS.map { color -> - ThemeColor(context, ContextCompat.getColor(context!!, color)) + ThemeColor(context, ContextCompat.getColor(requireContext(), color)) } Palette.WIDGET -> colorProvider.getWidgetColors() } @@ -111,7 +111,7 @@ class ColorPalettePicker : InjectingDialogFragment() { builder.setNegativeButton(android.R.string.cancel, null) } else { builder.setPositiveButton(R.string.button_subscribe) { _: DialogInterface?, _: Int -> - context?.startActivity(Intent(context!!, PurchaseActivity::class.java)) + context?.startActivity(Intent(requireContext(), PurchaseActivity::class.java)) } } return builder.show() diff --git a/app/src/main/java/org/tasks/dialogs/ColorWheelPicker.kt b/app/src/main/java/org/tasks/dialogs/ColorWheelPicker.kt index 03a0d52ff..e16cee443 100644 --- a/app/src/main/java/org/tasks/dialogs/ColorWheelPicker.kt +++ b/app/src/main/java/org/tasks/dialogs/ColorWheelPicker.kt @@ -49,7 +49,7 @@ class ColorWheelPicker : InjectingDialogFragment() { override fun inject(component: DialogFragmentComponent) = component.inject(this) override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - selected = savedInstanceState?.getInt(EXTRA_SELECTED) ?: arguments!!.getInt(EXTRA_SELECTED, 0) + selected = savedInstanceState?.getInt(EXTRA_SELECTED) ?: requireArguments().getInt(EXTRA_SELECTED, 0) val button = if (inventory.purchasedThemes()) android.R.string.ok else R.string.button_subscribe val builder = ColorPickerDialogBuilder diff --git a/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt b/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt index 1f9702c3f..58a95a7c2 100644 --- a/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt +++ b/app/src/main/java/org/tasks/dialogs/DateTimePicker.kt @@ -124,7 +124,7 @@ class DateTimePicker : InjectingBottomSheetDialogFragment() { } } val timestamp = savedInstanceState?.getLong(EXTRA_SELECTED) - ?: arguments!!.getLong(EXTRA_TIMESTAMP) + ?: requireArguments().getLong(EXTRA_TIMESTAMP) selected = if (timestamp > 0) DateTime(timestamp) else null return binding.root diff --git a/app/src/main/java/org/tasks/dialogs/ThemePickerDialog.kt b/app/src/main/java/org/tasks/dialogs/ThemePickerDialog.kt index 35161693c..ec2675ecd 100644 --- a/app/src/main/java/org/tasks/dialogs/ThemePickerDialog.kt +++ b/app/src/main/java/org/tasks/dialogs/ThemePickerDialog.kt @@ -57,13 +57,13 @@ class ThemePickerDialog : InjectingDialogFragment() { override fun inject(component: DialogFragmentComponent) = component.inject(this) override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - selected = savedInstanceState?.getInt(EXTRA_SELECTED) ?: arguments!!.getInt(EXTRA_SELECTED) + selected = savedInstanceState?.getInt(EXTRA_SELECTED) ?: requireArguments().getInt(EXTRA_SELECTED) val widget = arguments?.getBoolean(EXTRA_WIDGET) ?: false val themes = resources.getStringArray( if (widget) R.array.widget_themes else R.array.base_theme_names ) - adapter = object : ArrayAdapter(activity!!, R.layout.simple_list_item_single_choice, themes) { + adapter = object : ArrayAdapter(requireActivity(), R.layout.simple_list_item_single_choice, themes) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { val view = super.getView(position, convertView, parent) val textColor = if (isAvailable(position)) { @@ -79,7 +79,7 @@ class ThemePickerDialog : InjectingDialogFragment() { dialog = dialogBuilder.newDialog() .setTitle(R.string.theme) - .setSingleChoiceItems(adapter, arguments!!.getInt(EXTRA_SELECTED)) { _, which -> + .setSingleChoiceItems(adapter, requireArguments().getInt(EXTRA_SELECTED)) { _, which -> selected = which if (available()) { deliverResult() diff --git a/app/src/main/java/org/tasks/injection/InjectingPreferenceFragment.kt b/app/src/main/java/org/tasks/injection/InjectingPreferenceFragment.kt index 019e2c9f9..5aff279d2 100644 --- a/app/src/main/java/org/tasks/injection/InjectingPreferenceFragment.kt +++ b/app/src/main/java/org/tasks/injection/InjectingPreferenceFragment.kt @@ -48,7 +48,7 @@ abstract class InjectingPreferenceFragment : PreferenceFragmentCompat() { final override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(getPreferenceXml(), rootKey) - tintIcons(preferenceScreen, ContextCompat.getColor(context!!, R.color.icon_tint_with_alpha)) + tintIcons(preferenceScreen, ContextCompat.getColor(requireContext(), R.color.icon_tint_with_alpha)) setupPreferences(savedInstanceState) } @@ -76,7 +76,7 @@ abstract class InjectingPreferenceFragment : PreferenceFragmentCompat() { protected fun tintColorPreference(resId: Int, tint: Int) { val pref = findPreference(resId) - pref.icon = DrawableUtil.getWrapped(context!!, R.drawable.color_picker) + pref.icon = DrawableUtil.getWrapped(requireContext(), R.drawable.color_picker) DrawableUtil.setTint(pref.icon, tint) } @@ -117,7 +117,7 @@ abstract class InjectingPreferenceFragment : PreferenceFragmentCompat() { abstract fun setupPreferences(savedInstanceState: Bundle?) protected fun recreate() { - activity!!.recreate() + requireActivity().recreate() } protected fun findPreference(@StringRes prefId: Int): Preference { diff --git a/app/src/main/java/org/tasks/preferences/fragments/Advanced.kt b/app/src/main/java/org/tasks/preferences/fragments/Advanced.kt index 823f1fbeb..3177ecfa0 100644 --- a/app/src/main/java/org/tasks/preferences/fragments/Advanced.kt +++ b/app/src/main/java/org/tasks/preferences/fragments/Advanced.kt @@ -100,7 +100,7 @@ class Advanced : InjectingPreferenceFragment() { if (resultCode == Activity.RESULT_OK) { val uri = data!!.data!! if (AndroidUtilities.atLeastLollipop()) { - context!!.contentResolver + requireContext().contentResolver .takePersistableUriPermission( uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION @@ -231,7 +231,7 @@ class Advanced : InjectingPreferenceFragment() { .newDialog() .setMessage(R.string.EPr_delete_task_data_warning) .setPositiveButton(R.string.EPr_delete_task_data) { _, _ -> - context!!.deleteDatabase(database.name) + requireContext().deleteDatabase(database.name) exitProcess(0) } .setNegativeButton(android.R.string.cancel, null) diff --git a/app/src/main/java/org/tasks/preferences/fragments/LookAndFeel.kt b/app/src/main/java/org/tasks/preferences/fragments/LookAndFeel.kt index 1d05e7dc8..e56a97f0f 100644 --- a/app/src/main/java/org/tasks/preferences/fragments/LookAndFeel.kt +++ b/app/src/main/java/org/tasks/preferences/fragments/LookAndFeel.kt @@ -8,9 +8,7 @@ import android.content.pm.PackageManager import android.content.res.Configuration import android.os.Bundle import android.os.Handler -import android.widget.Toast import androidx.annotation.StringRes -import androidx.preference.ListPreference import androidx.preference.Preference import com.google.common.base.Strings import com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop @@ -25,7 +23,6 @@ import org.tasks.dialogs.ColorPalettePicker import org.tasks.dialogs.ColorPalettePicker.Companion.newColorPalette import org.tasks.dialogs.ColorPickerAdapter import org.tasks.dialogs.ColorWheelPicker -import org.tasks.dialogs.MyTimePickerDialog.newTimePicker import org.tasks.dialogs.ThemePickerDialog import org.tasks.dialogs.ThemePickerDialog.Companion.newThemePickerDialog import org.tasks.gtasks.PlayServices @@ -41,14 +38,10 @@ import org.tasks.themes.ThemeBase.DEFAULT_BASE_THEME import org.tasks.themes.ThemeBase.EXTRA_THEME_OVERRIDE import org.tasks.themes.ThemeColor import org.tasks.themes.ThemeColor.getLauncherColor -import org.tasks.time.DateTime import org.tasks.ui.ChipProvider import org.tasks.ui.NavigationDrawerFragment.REQUEST_PURCHASE import org.tasks.ui.SingleCheckedArrayAdapter -import org.tasks.ui.TimePreference import org.tasks.ui.Toaster -import org.threeten.bp.DayOfWeek -import org.threeten.bp.format.TextStyle import javax.inject.Inject private const val REQUEST_THEME_PICKER = 10001 @@ -177,7 +170,7 @@ class LookAndFeel : InjectingPreferenceFragment() { private fun setupLocationPickers() { val choices = listOf(getString(R.string.map_provider_mapbox), getString(R.string.map_provider_google)) - val singleCheckedArrayAdapter = SingleCheckedArrayAdapter(context!!, choices, themeAccent) + val singleCheckedArrayAdapter = SingleCheckedArrayAdapter(requireContext(), choices, themeAccent) val mapProviderPreference = findPreference(R.string.p_map_provider) mapProviderPreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { dialogBuilder @@ -351,7 +344,7 @@ class LookAndFeel : InjectingPreferenceFragment() { val packageManager: PackageManager? = context?.packageManager for (i in ThemeColor.LAUNCHERS.indices) { val componentName = ComponentName( - context!!, + requireContext(), "com.todoroo.astrid.activity.TaskListActivity" + ThemeColor.LAUNCHERS[i] ) packageManager?.setComponentEnabledSetting( diff --git a/app/src/main/java/org/tasks/preferences/fragments/Notifications.kt b/app/src/main/java/org/tasks/preferences/fragments/Notifications.kt index d1dbe2fc0..d1b1bcba7 100644 --- a/app/src/main/java/org/tasks/preferences/fragments/Notifications.kt +++ b/app/src/main/java/org/tasks/preferences/fragments/Notifications.kt @@ -144,7 +144,7 @@ class Notifications : InjectingPreferenceFragment() { private fun checkBatteryOptimizations() { if (atLeastMarshmallow()) { - val powerManager = context!!.getSystemService(POWER_SERVICE) as PowerManager + val powerManager = requireContext().getSystemService(POWER_SERVICE) as PowerManager findPreference(R.string.disable_battery_optimizations).isVisible = !powerManager.isIgnoringBatteryOptimizations(getString(R.string.app_package)) } diff --git a/app/src/main/java/org/tasks/preferences/fragments/ScrollableWidget.kt b/app/src/main/java/org/tasks/preferences/fragments/ScrollableWidget.kt index 6bd4b06cc..4906ceca8 100644 --- a/app/src/main/java/org/tasks/preferences/fragments/ScrollableWidget.kt +++ b/app/src/main/java/org/tasks/preferences/fragments/ScrollableWidget.kt @@ -54,7 +54,7 @@ class ScrollableWidget : InjectingPreferenceFragment() { override fun getPreferenceXml() = R.xml.preferences_widget override fun setupPreferences(savedInstanceState: Bundle?) { - appWidgetId = arguments!!.getInt(EXTRA_WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) + appWidgetId = requireArguments().getInt(EXTRA_WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) widgetPreferences = WidgetPreferences(context, preferences, appWidgetId) val row = setupSlider(R.string.p_widget_opacity, 100) diff --git a/app/src/main/java/org/tasks/preferences/fragments/TaskerListNotification.kt b/app/src/main/java/org/tasks/preferences/fragments/TaskerListNotification.kt index 57f0f98ff..627bbe20f 100644 --- a/app/src/main/java/org/tasks/preferences/fragments/TaskerListNotification.kt +++ b/app/src/main/java/org/tasks/preferences/fragments/TaskerListNotification.kt @@ -72,7 +72,7 @@ class TaskerListNotification : InjectingPreferenceFragment() { } else if (requestCode == REQUEST_SUBSCRIPTION) { if (!inventory.purchasedTasker()) { cancelled = true - activity!!.finish() + requireActivity().finish() } } else { super.onActivityResult(requestCode, resultCode, data)