forked from github/szkolny
[APIService] Fix showing notification with no service running.
This commit is contained in:
parent
85f72b78f7
commit
9e312f60bf
@ -49,6 +49,7 @@ class ApiService : Service() {
|
|||||||
private val errorList = mutableListOf<ApiError>()
|
private val errorList = mutableListOf<ApiError>()
|
||||||
|
|
||||||
private var serviceClosed = false
|
private var serviceClosed = false
|
||||||
|
set(value) { field = value; notification.serviceClosed = value }
|
||||||
private var taskCancelled = false
|
private var taskCancelled = false
|
||||||
private var taskIsRunning = false
|
private var taskIsRunning = false
|
||||||
private var taskRunning: IApiTask? = null // for debug purposes
|
private var taskRunning: IApiTask? = null // for debug purposes
|
||||||
@ -132,7 +133,6 @@ class ApiService : Service() {
|
|||||||
if (taskIsRunning)
|
if (taskIsRunning)
|
||||||
return
|
return
|
||||||
if (taskCancelled || serviceClosed || (taskQueue.isEmpty() && finishingTaskQueue.isEmpty())) {
|
if (taskCancelled || serviceClosed || (taskQueue.isEmpty() && finishingTaskQueue.isEmpty())) {
|
||||||
serviceClosed = false
|
|
||||||
allCompleted()
|
allCompleted()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -214,6 +214,7 @@ class ApiService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun allCompleted() {
|
private fun allCompleted() {
|
||||||
|
serviceClosed = true
|
||||||
EventBus.getDefault().postSticky(ApiTaskAllFinishedEvent())
|
EventBus.getDefault().postSticky(ApiTaskAllFinishedEvent())
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
@ -298,6 +299,8 @@ class ApiService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
d(TAG, "Service destroyed")
|
||||||
|
serviceClosed = true
|
||||||
EventBus.getDefault().unregister(this)
|
EventBus.getDefault().unregister(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ class EdziennikNotification(val context: Context) {
|
|||||||
|
|
||||||
private var errorCount = 0
|
private var errorCount = 0
|
||||||
private var criticalErrorCount = 0
|
private var criticalErrorCount = 0
|
||||||
|
var serviceClosed = false
|
||||||
|
|
||||||
private fun cancelPendingIntent(taskId: Int): PendingIntent {
|
private fun cancelPendingIntent(taskId: Int): PendingIntent {
|
||||||
val intent = Intent("pl.szczodrzynski.edziennik.SZKOLNY_MAIN")
|
val intent = Intent("pl.szczodrzynski.edziennik.SZKOLNY_MAIN")
|
||||||
@ -134,6 +135,8 @@ class EdziennikNotification(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun post() {
|
fun post() {
|
||||||
|
if (serviceClosed)
|
||||||
|
return
|
||||||
notificationManager.notify(NOTIFICATION_ID, notification)
|
notificationManager.notify(NOTIFICATION_ID, notification)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user