mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Replaced activity!! with requireActivity, context!! with requireContext etc. (#1458)
This commit is contained in:
@@ -28,7 +28,7 @@ import org.isoron.uhabits.utils.toPaletteColor
|
||||
class ColorPickerDialog : ColorPickerDialog() {
|
||||
fun setListener(callback: OnColorPickedCallback) {
|
||||
super.setOnColorSelectedListener { c: Int ->
|
||||
val pc = c.toPaletteColor(context!!)
|
||||
val pc = c.toPaletteColor(requireContext())
|
||||
callback.onColorPicked(pc)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,12 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
||||
private var onDateClickedListener: OnDateClickedListener? = null
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val component = (activity!!.application as HabitsApplication).component
|
||||
val component = (requireActivity().application as HabitsApplication).component
|
||||
commandRunner = component.commandRunner
|
||||
habit = component.habitList.getById(arguments!!.getLong("habit"))!!
|
||||
habit = component.habitList.getById(requireArguments().getLong("habit"))!!
|
||||
preferences = component.preferences
|
||||
|
||||
val themeSwitcher = AndroidThemeSwitcher(activity!!, preferences)
|
||||
val themeSwitcher = AndroidThemeSwitcher(requireActivity(), preferences)
|
||||
themeSwitcher.apply()
|
||||
|
||||
chart = HistoryChart(
|
||||
@@ -69,10 +69,10 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
||||
onDateClickedListener = onDateClickedListener ?: object : OnDateClickedListener {},
|
||||
padding = 10.0,
|
||||
)
|
||||
dataView = AndroidDataView(context!!, null)
|
||||
dataView = AndroidDataView(requireContext(), null)
|
||||
dataView.view = chart!!
|
||||
|
||||
return Dialog(context!!).apply {
|
||||
return Dialog(requireContext()).apply {
|
||||
val metrics = resources.displayMetrics
|
||||
val maxHeight = resources.getDimensionPixelSize(R.dimen.history_editor_max_height)
|
||||
setContentView(dataView)
|
||||
|
||||
@@ -60,7 +60,7 @@ class WeekdayPickerDialog :
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val builder = AlertDialog.Builder(
|
||||
activity!!
|
||||
requireActivity()
|
||||
)
|
||||
builder
|
||||
.setTitle(R.string.select_weekdays)
|
||||
|
||||
@@ -40,13 +40,13 @@ class HabitTypeDialog : AppCompatDialogFragment() {
|
||||
val binding = SelectHabitTypeBinding.inflate(inflater, container, false)
|
||||
|
||||
binding.buttonYesNo.setOnClickListener {
|
||||
val intent = IntentFactory().startEditActivity(activity!!, HabitType.YES_NO.value)
|
||||
val intent = IntentFactory().startEditActivity(requireActivity(), HabitType.YES_NO.value)
|
||||
startActivity(intent)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.buttonMeasurable.setOnClickListener {
|
||||
val intent = IntentFactory().startEditActivity(activity!!, HabitType.NUMERICAL.value)
|
||||
val intent = IntentFactory().startEditActivity(requireActivity(), HabitType.NUMERICAL.value)
|
||||
startActivity(intent)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class SettingsFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeLis
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
addPreferencesFromResource(R.xml.preferences)
|
||||
val appContext = context!!.applicationContext
|
||||
val appContext = requireContext().applicationContext
|
||||
if (appContext is HabitsApplication) {
|
||||
prefs = appContext.component.preferences
|
||||
widgetUpdater = appContext.component.widgetUpdater
|
||||
@@ -91,9 +91,9 @@ class SettingsFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeLis
|
||||
return true
|
||||
} else if (key == "reminderCustomize") {
|
||||
if (SDK_INT < Build.VERSION_CODES.O) return true
|
||||
createAndroidNotificationChannel(context!!)
|
||||
createAndroidNotificationChannel(requireContext())
|
||||
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context!!.packageName)
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, NotificationTray.REMINDERS_CHANNEL_ID)
|
||||
startActivity(intent)
|
||||
return true
|
||||
@@ -103,7 +103,7 @@ class SettingsFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeLis
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
ringtoneManager = RingtoneManager(activity!!)
|
||||
ringtoneManager = RingtoneManager(requireActivity())
|
||||
sharedPrefs = preferenceManager.sharedPreferences
|
||||
sharedPrefs!!.registerOnSharedPreferenceChangeListener(this)
|
||||
if (!prefs.isDeveloper) {
|
||||
@@ -146,8 +146,8 @@ class SettingsFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeLis
|
||||
val pref = findPreference(key)
|
||||
pref.onPreferenceClickListener =
|
||||
Preference.OnPreferenceClickListener {
|
||||
activity!!.setResult(result)
|
||||
activity!!.finish()
|
||||
requireActivity().setResult(result)
|
||||
requireActivity().finish()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user