Switched persistent turn notification to false for pre-Oreo Android phones, as they may display an annoying icon in status bar. (#1957)

Fixed potential hanging notifier service due to not resetting error counter.
https://github.com/yairm210/Unciv/issues/1680
This commit is contained in:
wrov
2020-02-17 19:57:05 +01:00
committed by GitHub
parent 72abdc964f
commit 0b7a64db16
3 changed files with 14 additions and 4 deletions

View File

@ -156,7 +156,7 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
gameId = gameInfo.gameId
userId = settings.userId
configuredDelay = settings.multiplayerTurnCheckerDelayInMinutes
persistentNotificationEnabled = settings.multiplayerTurnCheckerPermanentNotificationEnabled
persistentNotificationEnabled = settings.multiplayerTurnCheckerPersistentNotificationEnabled
showPersistentNotification(applicationContext,
"", settings.multiplayerTurnCheckerDelayInMinutes.toString())
@ -185,6 +185,7 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
with(NotificationManagerCompat.from(applicationContext)) {
cancel(NOTIFICATION_ID_SERVICE)
}
failCount = 0 // Otherwise the notification service would be forever stuck in error mode.
return Result.failure()
} else {
// If check fails, retry in one minute.

View File

@ -1,5 +1,7 @@
package com.unciv.models.metadata
import com.badlogic.gdx.Application
import com.badlogic.gdx.Gdx
import com.unciv.logic.GameSaver
class GameSettings {
@ -27,9 +29,16 @@ class GameSettings {
var continuousRendering = true
var userId = ""
var multiplayerTurnCheckerEnabled = true
var multiplayerTurnCheckerPermanentNotificationEnabled = true
var multiplayerTurnCheckerPersistentNotificationEnabled = true
var multiplayerTurnCheckerDelayInMinutes = 5L
init {
// 26 = Android Oreo. Version below may display permanent icon in notification bar.
if (Gdx.app.type == Application.ApplicationType.Android && Gdx.app.version < 26) {
multiplayerTurnCheckerPersistentNotificationEnabled = false
}
}
fun save(){
GameSaver().setGeneralSettings(this)
}

View File

@ -139,8 +139,8 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen){
addMultiplayerTurnCheckerDelayBox(innerTable)
innerTable.add("Show persistent notification for turn notifier service".toLabel())
addButton(innerTable, if (settings.multiplayerTurnCheckerPermanentNotificationEnabled) "Yes" else "No") {
settings.multiplayerTurnCheckerPermanentNotificationEnabled = !settings.multiplayerTurnCheckerPermanentNotificationEnabled
addButton(innerTable, if (settings.multiplayerTurnCheckerPersistentNotificationEnabled) "Yes" else "No") {
settings.multiplayerTurnCheckerPersistentNotificationEnabled = !settings.multiplayerTurnCheckerPersistentNotificationEnabled
update()
}
}