Added Multiplayer Turn Notification Service (#1947)

* Added Multiplayer Turn Notification Service
https://github.com/yairm210/Unciv/issues/1680

* Minor update on Credits.md (#1949)

# Nations
- Fix typo on word "crescent"
- Fix link that flew off on word "sword"

* 3.5.14-patch1

* Edit startgame screen. (#1950)

Co-authored-by: u-ndefine <41176671+u-ndefine@users.noreply.github.com>

* Small improvements suggested in pull request review
https://github.com/yairm210/Unciv/pull/1947

* Removed potential concurrency hazzards caused by access to non-final variables. Added option to turn off persistent notification (may be necessary on pre-Oreo phones.)
Added suggested comments. https://github.com/yairm210/Unciv/pull/1947

* Fixed miscommited debug code. https://github.com/yairm210/Unciv/pull/1947

Co-authored-by: u-ndefine <41176671+u-ndefine@users.noreply.github.com>
Co-authored-by: Yair Morgenstern <yairm210@hotmail.com>
Co-authored-by: lishaoxia1985 <49801619+lishaoxia1985@users.noreply.github.com>
This commit is contained in:
wrov
2020-02-17 17:34:46 +01:00
committed by GitHub
parent 9d1e45de08
commit bc15d97de7
9 changed files with 369 additions and 23 deletions

View File

@ -2,6 +2,8 @@ package com.unciv.app
import android.os.Build
import android.os.Bundle
import androidx.core.app.NotificationManagerCompat
import androidx.work.WorkManager
import com.badlogic.gdx.backends.android.AndroidApplication
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration
import com.unciv.UncivGame
@ -10,6 +12,7 @@ import java.io.File
class AndroidLauncher : AndroidApplication() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
createNotificationChannels()
// Only allow mods on KK+, to avoid READ_EXTERNAL_STORAGE permission earlier versions need
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
@ -23,6 +26,14 @@ class AndroidLauncher : AndroidApplication() {
initialize(game, config)
}
/**
* Necessary for Multiplayer Turner Checker, starting with Android Oreo
*/
private fun createNotificationChannels() {
MultiplayerTurnCheckWorker.createNotificationChannelInfo(context)
MultiplayerTurnCheckWorker.createNotificationChannelService(context)
}
/**
* Copies mods from external data directory (where users can access) to the private one (where
* libGDX reads from). Note: deletes all files currently in the private mod directory and
@ -43,4 +54,22 @@ class AndroidLauncher : AndroidApplication() {
if (!externalModsDir.exists()) externalModsDir.mkdirs()
externalModsDir.copyRecursively(internalModsDir)
}
override fun onPause() {
if (UncivGame.Current.settings.multiplayerTurnCheckerEnabled
&& UncivGame.Current.isGameInfoInitialized()
&& UncivGame.Current.gameInfo.gameParameters.isOnlineMultiplayer) {
MultiplayerTurnCheckWorker.startTurnChecker(applicationContext, UncivGame.Current.gameInfo, UncivGame.Current.settings)
}
super.onPause()
}
override fun onResume() {
WorkManager.getInstance(applicationContext).cancelAllWorkByTag(MultiplayerTurnCheckWorker.WORK_TAG)
with(NotificationManagerCompat.from(this)) {
cancel(MultiplayerTurnCheckWorker.NOTIFICATION_ID_INFO)
cancel(MultiplayerTurnCheckWorker.NOTIFICATION_ID_SERVICE)
}
super.onResume()
}
}