Skip to content

Commit

Permalink
#13: Fix rendering after "Share game": recreate Android activity onRe…
Browse files Browse the repository at this point in the history
…sume.
  • Loading branch information
yvolk committed Oct 28, 2023
1 parent 46ee5a3 commit 6b73197
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ korge {
androidCompileSdk = 30
androidTargetSdk = 31

versionCode = 38
version = "1.14.0"
versionCode = 39
version = "1.14.1"

targetJvm()
targetJs()
targetDesktop()
targetAndroid()
}

Expand Down
16 changes: 15 additions & 1 deletion src/androidMain/kotlin/org/andstatus/game2048/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MainActivity : KorgwActivity() {
private val REQUEST_CODE_OPEN_JSON_GAME = 1
private var gameRecordConsumer: ((Sequence<String>) -> Unit)? = null
private var orientation: Int = Configuration.ORIENTATION_UNDEFINED
private var paused: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
myLog("onCreate MainActivity")
Expand All @@ -23,7 +24,7 @@ class MainActivity : KorgwActivity() {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
if (orientation != Configuration.ORIENTATION_UNDEFINED && newConfig.orientation != orientation) {
this.recreate()
recreate()
}
}

Expand All @@ -34,6 +35,19 @@ class MainActivity : KorgwActivity() {
myLog("activityMain ended")
}

override fun onPause() {
paused = true
super.onPause()
}

override fun onResume() {
super.onResume()
if (paused) {
paused = false
recreate()
}
}

override fun finish() {
myLog("activityMain finish")
finishAffinity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,15 +812,6 @@ class Presenter(val view: ViewData, history: History) {
)
}

fun onResumeEvent() {
if (view.closed) {
logClick("onResumeEvent view closed")
} else {
logClick("onResumeEvent reinitializing...")
view.reInitialize()
}
}

suspend fun delayWhilePresenting() {
while (isPresenting.value) delay(20)
}
Expand Down
3 changes: 0 additions & 3 deletions src/commonMain/kotlin/org/andstatus/game2048/view/ViewData.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.andstatus.game2048.view

import korlibs.event.PauseEvent
import korlibs.event.ResumeEvent
import korlibs.image.font.Font
import korlibs.io.concurrent.atomic.korAtomic
import korlibs.io.lang.Closeable
Expand Down Expand Up @@ -84,8 +83,6 @@ suspend fun viewData(stage: Stage): ViewData = coroutineScope {
view.presenter.onAppEntry()
view.gameStage.gameWindow.onEvent(PauseEvent) { view.presenter.onPauseEvent() }
.also { view.closeables.add(it) }
view.gameStage.gameWindow.onEvent(ResumeEvent) { view.presenter.onResumeEvent() }
.also { view.closeables.add(it) }
myLog("GameView${view.id} initialized")
view
}
Expand Down

0 comments on commit 6b73197

Please sign in to comment.