[APIService] Fix showing notification with no service running.

This commit is contained in:
Kuba Szczodrzyński 2020-01-10 21:34:55 +01:00
parent 85f72b78f7
commit 9e312f60bf
2 changed files with 7 additions and 1 deletions

View File

@ -49,6 +49,7 @@ class ApiService : Service() {
private val errorList = mutableListOf<ApiError>()
private var serviceClosed = false
set(value) { field = value; notification.serviceClosed = value }
private var taskCancelled = false
private var taskIsRunning = false
private var taskRunning: IApiTask? = null // for debug purposes
@ -132,7 +133,6 @@ class ApiService : Service() {
if (taskIsRunning)
return
if (taskCancelled || serviceClosed || (taskQueue.isEmpty() && finishingTaskQueue.isEmpty())) {
serviceClosed = false
allCompleted()
return
}
@ -214,6 +214,7 @@ class ApiService : Service() {
}
private fun allCompleted() {
serviceClosed = true
EventBus.getDefault().postSticky(ApiTaskAllFinishedEvent())
stopSelf()
}
@ -298,6 +299,8 @@ class ApiService : Service() {
}
override fun onDestroy() {
d(TAG, "Service destroyed")
serviceClosed = true
EventBus.getDefault().unregister(this)
}

View File

@ -35,6 +35,7 @@ class EdziennikNotification(val context: Context) {
private var errorCount = 0
private var criticalErrorCount = 0
var serviceClosed = false
private fun cancelPendingIntent(taskId: Int): PendingIntent {
val intent = Intent("pl.szczodrzynski.edziennik.SZKOLNY_MAIN")
@ -134,6 +135,8 @@ class EdziennikNotification(val context: Context) {
}
fun post() {
if (serviceClosed)
return
notificationManager.notify(NOTIFICATION_ID, notification)
}