Implement custom save locations for Android and Desktop (#3160)

* Implement custom save locations for Android and Desktop

* Request write permission to save to external storage

* Fix race condition for custom saves/loads caused by autosaves

* Remove unnecessary WRITE_EXTERNAL_STORAGE permission for saving files

* Fix padding for custom save/load location buttons

* Use nullability checks as defined in coding style guide

* Use nullability checks as defined in coding style guide

* Use early return for readability

* Rename save/load completion callbacks for custom locations and implement error handling
This commit is contained in:
Billy Brawner
2020-09-20 13:22:07 -07:00
committed by GitHub
parent fded66b523
commit 205b5ccfea
11 changed files with 362 additions and 11 deletions

View File

@ -1,5 +1,6 @@
package com.unciv.app
import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.core.app.NotificationManagerCompat
@ -13,8 +14,12 @@ import com.unciv.ui.utils.ORIGINAL_FONT_SIZE
import java.io.File
class AndroidLauncher : AndroidApplication() {
private var customSaveLocationHelper: CustomSaveLocationHelperAndroid? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
customSaveLocationHelper = CustomSaveLocationHelperAndroid(this)
}
MultiplayerTurnCheckWorker.createNotificationChannels(applicationContext)
// Only allow mods on KK+, to avoid READ_EXTERNAL_STORAGE permission earlier versions need
@ -29,7 +34,8 @@ class AndroidLauncher : AndroidApplication() {
version = BuildConfig.VERSION_NAME,
crashReportSender = CrashReportSenderAndroid(this),
exitEvent = this::finish,
fontImplementation = NativeFontAndroid(ORIGINAL_FONT_SIZE.toInt())
fontImplementation = NativeFontAndroid(ORIGINAL_FONT_SIZE.toInt()),
customSaveLocationHelper = customSaveLocationHelper
)
val game = UncivGame ( androidParameters )
initialize(game, config)
@ -77,4 +83,13 @@ class AndroidLauncher : AndroidApplication() {
catch (ex:Exception){}
super.onResume()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// This should only happen on API 19+ but it's wrapped in the if check to keep the
// compiler happy
customSaveLocationHelper?.handleIntentData(requestCode, data?.data)
}
super.onActivityResult(requestCode, resultCode, data)
}
}