fixing some warnings

This commit is contained in:
tibbi 2020-11-05 12:42:15 +01:00
parent 5bb05c04c0
commit 7eba711e35
6 changed files with 42 additions and 44 deletions

View file

@ -17,7 +17,6 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.isVisible
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.mydebug
import com.simplemobiletools.commons.views.MyRecyclerView
import kotlinx.android.synthetic.main.item_alarm.view.*
import java.util.*

View file

@ -266,7 +266,6 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent:
try {
notificationManager.deleteNotificationChannel(channelId)
} catch (e: Exception) {
e.printStackTrace()
}
val audioAttributes = AudioAttributes.Builder()
@ -302,7 +301,7 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent:
.setDefaults(Notification.DEFAULT_LIGHTS)
.setCategory(Notification.CATEGORY_EVENT)
.setAutoCancel(true)
.setSound(Uri.parse(soundUri), AudioManager.STREAM_ALARM)
.setSound(Uri.parse(soundUri), STREAM_ALARM)
.setChannelId(channelId)
.addAction(R.drawable.ic_cross_vector, getString(R.string.dismiss), if (addDeleteIntent) reminderActivityIntent else getHideTimerPendingIntent())
@ -346,7 +345,7 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No
val audioAttributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ALARM)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setLegacyStreamType(AudioManager.STREAM_ALARM)
.setLegacyStreamType(STREAM_ALARM)
.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
.build()

View file

@ -42,7 +42,7 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
super.onResume()
setupViews()
val configTextColor = context!!.config.textColor
val configTextColor = requireContext().config.textColor
if (storedTextColor != configTextColor) {
(view.alarms_list.adapter as AlarmsAdapter).updateTextColor(configTextColor)
}
@ -54,12 +54,12 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
}
private fun storeStateVariables() {
storedTextColor = context!!.config.textColor
storedTextColor = requireContext().config.textColor
}
private fun setupViews() {
view.apply {
context!!.updateTextColors(alarm_fragment)
requireContext().updateTextColors(alarm_fragment)
alarm_fab.setOnClickListener {
val newAlarm = context.createNewAlarm(DEFAULT_ALARM_MINUTES, 0)
newAlarm.isEnabled = true
@ -106,14 +106,14 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
}
override fun alarmToggled(id: Int, isEnabled: Boolean) {
if (context!!.dbHelper.updateAlarmEnabledState(id, isEnabled)) {
if (requireContext().dbHelper.updateAlarmEnabledState(id, isEnabled)) {
val alarm = alarms.firstOrNull { it.id == id } ?: return
alarm.isEnabled = isEnabled
checkAlarmState(alarm)
} else {
activity!!.toast(R.string.unknown_error_occurred)
requireActivity().toast(R.string.unknown_error_occurred)
}
context!!.updateWidgets()
requireContext().updateWidgets()
}
private fun checkAlarmState(alarm: Alarm) {

View file

@ -40,7 +40,7 @@ class ClockFragment : Fragment() {
super.onResume()
setupDateTime()
val configTextColor = context!!.config.textColor
val configTextColor = requireContext().config.textColor
if (storedTextColor != configTextColor) {
(view.time_zones_list.adapter as? TimeZonesAdapter)?.updateTextColor(configTextColor)
}
@ -53,7 +53,7 @@ class ClockFragment : Fragment() {
}
private fun storeStateVariables() {
storedTextColor = context!!.config.textColor
storedTextColor = requireContext().config.textColor
}
private fun setupDateTime() {
@ -67,7 +67,7 @@ class ClockFragment : Fragment() {
private fun setupViews() {
view.apply {
context!!.updateTextColors(clock_fragment)
requireContext().updateTextColors(clock_fragment)
clock_fab.setOnClickListener {
fabClicked()
}
@ -80,9 +80,9 @@ class ClockFragment : Fragment() {
val hours = (passedSeconds / 3600) % 24
val minutes = (passedSeconds / 60) % 60
val seconds = passedSeconds % 60
view.clock_time.text = context!!.getFormattedTime(passedSeconds, context!!.config.showSeconds, true)
view.clock_time.text = requireContext().getFormattedTime(passedSeconds, requireContext().config.showSeconds, true)
if (!context!!.config.use24HourFormat) {
if (!requireContext().config.use24HourFormat) {
view.clock_time.textSize = resources.getDimension(R.dimen.clock_text_size_smaller) / resources.displayMetrics.density
}
@ -102,29 +102,29 @@ class ClockFragment : Fragment() {
private fun updateDate() {
calendar = Calendar.getInstance()
val formattedDate = context!!.getFormattedDate(calendar)
val formattedDate = requireContext().getFormattedDate(calendar)
view.clock_date.text = formattedDate
(view.time_zones_list.adapter as? TimeZonesAdapter)?.todayDateString = formattedDate
}
fun updateAlarm() {
view.apply {
val nextAlarm = context!!.getNextAlarm()
val nextAlarm = requireContext().getNextAlarm()
clock_alarm.beVisibleIf(nextAlarm.isNotEmpty())
clock_alarm.text = nextAlarm
clock_alarm.colorLeftDrawable(context!!.config.textColor)
clock_alarm.colorLeftDrawable(requireContext().config.textColor)
}
}
private fun updateTimeZones() {
val selectedTimeZones = context!!.config.selectedTimeZones
val selectedTimeZones = requireContext().config.selectedTimeZones
view.time_zones_list.beVisibleIf(selectedTimeZones.isNotEmpty())
if (selectedTimeZones.isEmpty()) {
return
}
val selectedTimeZoneIDs = selectedTimeZones.map { it.toInt() }
val timeZones = context!!.getAllTimeZonesModified().filter { selectedTimeZoneIDs.contains(it.id) } as ArrayList<MyTimeZone>
val timeZones = requireContext().getAllTimeZonesModified().filter { selectedTimeZoneIDs.contains(it.id) } as ArrayList<MyTimeZone>
val currAdapter = view.time_zones_list.adapter
if (currAdapter == null) {
TimeZonesAdapter(activity as SimpleActivity, timeZones, view.time_zones_list) {

View file

@ -120,7 +120,7 @@ class StopwatchFragment : Fragment() {
super.onResume()
setupViews()
val configTextColor = context!!.config.textColor
val configTextColor = requireContext().config.textColor
if (storedTextColor != configTextColor) {
stopwatchAdapter.updateTextColor(configTextColor)
}
@ -141,7 +141,7 @@ class StopwatchFragment : Fragment() {
}
private fun storeStateVariables() {
storedTextColor = context!!.config.textColor
storedTextColor = requireContext().config.textColor
}
override fun onSaveInstanceState(outState: Bundle) {
@ -168,7 +168,7 @@ class StopwatchFragment : Fragment() {
sorting = getInt(SORTING, SORT_BY_LAP or SORT_DESCENDING)
val lapsToken = object : TypeToken<List<Lap>>() {}.type
laps = Gson().fromJson<ArrayList<Lap>>(getString(LAPS), lapsToken)
laps = Gson().fromJson(getString(LAPS), lapsToken)
if (laps.isNotEmpty()) {
view.stopwatch_sorting_indicators_holder.beVisibleIf(laps.isNotEmpty())
@ -183,11 +183,11 @@ class StopwatchFragment : Fragment() {
}
private fun setupViews() {
val adjustedPrimaryColor = context!!.getAdjustedPrimaryColor()
val adjustedPrimaryColor = requireContext().getAdjustedPrimaryColor()
view.apply {
context!!.updateTextColors(stopwatch_fragment)
requireContext().updateTextColors(stopwatch_fragment)
stopwatch_play_pause.background = resources.getColoredDrawableWithColor(R.drawable.circle_background_filled, adjustedPrimaryColor)
stopwatch_reset.applyColorFilter(context!!.config.textColor)
stopwatch_reset.applyColorFilter(requireContext().config.textColor)
}
updateIcons()
@ -196,7 +196,7 @@ class StopwatchFragment : Fragment() {
private fun updateIcons() {
val drawableId = if (isRunning) R.drawable.ic_pause_vector else R.drawable.ic_play_vector
val iconColor = if (context!!.getAdjustedPrimaryColor() == Color.WHITE) Color.BLACK else Color.WHITE
val iconColor = if (requireContext().getAdjustedPrimaryColor() == Color.WHITE) Color.BLACK else Color.WHITE
view.stopwatch_play_pause.setImageDrawable(resources.getColoredDrawableWithColor(drawableId, iconColor))
}
@ -267,7 +267,7 @@ class StopwatchFragment : Fragment() {
}
private fun updateSortingIndicators() {
var bitmap = context!!.resources.getColoredBitmap(R.drawable.ic_sorting_triangle, context!!.getAdjustedPrimaryColor())
var bitmap = requireContext().resources.getColoredBitmap(R.drawable.ic_sorting_triangle, requireContext().getAdjustedPrimaryColor())
view.apply {
stopwatch_sorting_indicator_1.beInvisibleIf(sorting and SORT_BY_LAP == 0)
stopwatch_sorting_indicator_2.beInvisibleIf(sorting and SORT_BY_LAP_TIME == 0)
@ -293,7 +293,7 @@ class StopwatchFragment : Fragment() {
}
private fun checkHaptic(view: View) {
if (context!!.config.vibrateOnButtonPress) {
if (requireContext().config.vibrateOnButtonPress) {
view.performHapticFeedback()
}
}

View file

@ -46,8 +46,8 @@ class TimerFragment : Fragment() {
timer_label.setText(config.timerLabel)
requiredActivity.updateTextColors(timer_fragment)
timer_play_pause.background = resources.getColoredDrawableWithColor(R.drawable.circle_background_filled, context!!.getAdjustedPrimaryColor())
timer_play_pause.applyColorFilter(if (context!!.getAdjustedPrimaryColor() == Color.WHITE) Color.BLACK else Color.WHITE)
timer_play_pause.background = resources.getColoredDrawableWithColor(R.drawable.circle_background_filled, requireContext().getAdjustedPrimaryColor())
timer_play_pause.applyColorFilter(if (requireContext().getAdjustedPrimaryColor() == Color.WHITE) Color.BLACK else Color.WHITE)
timer_reset.applyColorFilter(textColor)
timer_initial_time.text = config.timerSeconds.getFormattedDuration()
@ -96,20 +96,20 @@ class TimerFragment : Fragment() {
timer_sound.setOnClickListener {
SelectAlarmSoundDialog(activity as SimpleActivity, config.timerSoundUri, AudioManager.STREAM_ALARM, PICK_AUDIO_FILE_INTENT_ID,
ALARM_SOUND_TYPE_ALARM, true,
onAlarmPicked = { sound ->
if (sound != null) {
updateAlarmSound(sound)
}
},
onAlarmSoundDeleted = { sound ->
if (config.timerSoundUri == sound.uri) {
val defaultAlarm = context.getDefaultAlarmSound(ALARM_SOUND_TYPE_ALARM)
updateAlarmSound(defaultAlarm)
}
ALARM_SOUND_TYPE_ALARM, true,
onAlarmPicked = { sound ->
if (sound != null) {
updateAlarmSound(sound)
}
},
onAlarmSoundDeleted = { sound ->
if (config.timerSoundUri == sound.uri) {
val defaultAlarm = context.getDefaultAlarmSound(ALARM_SOUND_TYPE_ALARM)
updateAlarmSound(defaultAlarm)
}
context.checkAlarmsWithDeletedSoundUri(sound.uri)
})
context.checkAlarmsWithDeletedSoundUri(sound.uri)
})
}
timer_label.onTextChangeListener { text ->