prevent kotlin exceptions

This commit is contained in:
Milos Kozak 2020-07-07 17:16:22 +02:00
parent ceaa3c8750
commit 2b7cb0d558
5 changed files with 34 additions and 29 deletions

View file

@ -27,7 +27,7 @@ class DummyService : DaggerService() {
private val disposable = CompositeDisposable()
override fun onBind(intent: Intent): IBinder? = null
override fun onBind(intent: Intent?): IBinder? = null
override fun onCreate() {
super.onCreate()

View file

@ -39,14 +39,19 @@ class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() {
val activePump: PumpInterface = activePlugin.activePump
aapsLogger.debug(LTag.PUMP,"TimeDateOrTZChangeReceiver::Date, Time and/or TimeZone changed. [action={}]", action)
try {
aapsLogger.debug(LTag.PUMP, "TimeDateOrTZChangeReceiver::Intent::{}", gson.toJson(intent))
} catch (ignored : Exception) {}
if (action == null) {
when {
action == null -> {
aapsLogger.error(LTag.PUMP,"TimeDateOrTZChangeReceiver::Action is null. Exiting.")
} else if (Intent.ACTION_TIMEZONE_CHANGED == action) {
}
Intent.ACTION_TIMEZONE_CHANGED == action -> {
aapsLogger.info(LTag.PUMP,"TimeDateOrTZChangeReceiver::Timezone changed. Notifying pump driver.")
activePump.timezoneOrDSTChanged(TimeChangeType.TimezoneChange)
} else if (Intent.ACTION_TIME_CHANGED == action) {
}
Intent.ACTION_TIME_CHANGED == action -> {
val currentDst = calculateDST()
if (currentDst == isDST) {
aapsLogger.info(LTag.PUMP,"TimeDateOrTZChangeReceiver::Time changed (manual). Notifying pump driver.")
@ -61,10 +66,10 @@ class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() {
}
}
isDST = currentDst
} else {
}
else -> {
aapsLogger.error(LTag.PUMP,"TimeDateOrTZChangeReceiver::Unknown action received [name={}]. Exiting.", action)
}
}
}
}

View file

@ -72,7 +72,7 @@ class LocationService : DaggerService() {
}
}
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
try {
startForeground(notificationHolder.notificationID, notificationHolder.notification)

View file

@ -29,13 +29,13 @@ class AlarmSoundService : DaggerService() {
startForeground(notificationHolder.notificationID, notificationHolder.notification)
}
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
startForeground(notificationHolder.notificationID, notificationHolder.notification)
player?.let { if (it.isPlaying) it.stop() }
aapsLogger.debug(LTag.CORE, "onStartCommand")
if (intent.hasExtra("soundid")) resourceId = intent.getIntExtra("soundid", R.raw.error)
if (intent?.hasExtra("soundid") == true) resourceId = intent.getIntExtra("soundid", R.raw.error)
player = MediaPlayer()
try {
val afd = resourceHelper.openRawResourceFd(resourceId) ?: return START_STICKY

View file

@ -126,7 +126,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
})
}
danar_history_spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val selected = typeList[position]
loadDataFromDB(selected.type)
showingType = selected.type