mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-02-20 13:54:43 +01:00
[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 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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user