diff --git a/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt b/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt index 9c14ab74..7990528b 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt @@ -149,8 +149,6 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), private val fontDirPath: String get() = "$celestiaParentPath/$CELESTIA_FONT_FOLDER_NAME" - private lateinit var language: String - @SuppressLint("ClickableViewAccessibility") override fun onCreate(savedInstanceState: Bundle?) { val reporter = AppStatusReporter.shared() @@ -224,11 +222,12 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), if (currentState == AppStatusReporter.State.NONE || currentState == AppStatusReporter.State.EXTERNAL_LOADING) { loadExternalConfig(savedState) - } else { - loadConfigSuccess(savedState) - if (currentState == AppStatusReporter.State.SUCCESS) { - celestiaLoadingSucceeded() - } + } else if (currentState == AppStatusReporter.State.LOADING) { + // Do nothing + } else if (currentState == AppStatusReporter.State.LOADING_SUCCESS) { + celestiaLoadingSucceeded() + } else if (currentState == AppStatusReporter.State.FINISHED) { + celestiaLoadingFinished() } if (savedState != null) { @@ -299,7 +298,7 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), loadConfig() if (!isActive) return@launch withContext(Dispatchers.Main) { - loadConfigSuccess(null) + loadConfigSuccess() } } catch (error: Throwable) { withContext(Dispatchers.Main) { @@ -349,7 +348,9 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), override fun celestiaLoadingProgress(status: String) {} override fun celestiaLoadingStateChanged(newState: AppStatusReporter.State) { - if (newState == AppStatusReporter.State.SUCCESS) { + if (newState == AppStatusReporter.State.FINISHED) { + celestiaLoadingFinished() + } else if (newState == AppStatusReporter.State.LOADING_SUCCESS) { celestiaLoadingSucceeded() } else if (newState == AppStatusReporter.State.EXTERNAL_LOADING_FAILURE || newState == AppStatusReporter.State.LOADING_FAILURE) { celestiaLoadingFailed() @@ -357,17 +358,22 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), } fun celestiaLoadingSucceeded() { + CelestiaView.callOnRenderThread { + readSettings() + + AppStatusReporter.shared().updateState(AppStatusReporter.State.FINISHED) + } + } + + fun celestiaLoadingFinished() { lifecycleScope.launch { - // hide the loading container supportFragmentManager.findFragmentById(R.id.loading_fragment_container)?.let { supportFragmentManager.beginTransaction().hide(it).remove(it).commitAllowingStateLoss() } findViewById(R.id.loading_fragment_container).visibility = View.GONE - // apply setting - readSettings() + ResourceManager.shared.addonDirectory = addonPath - // open url/script if present readyForInteraction = true runScriptOrOpenURLIfNeeded() @@ -530,8 +536,6 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), enableMultisample = preferenceManager[PreferenceManager.PredefinedKey.MSAA] == "true" enableHiDPI = preferenceManager[PreferenceManager.PredefinedKey.FullDPI] != "false" // default on - - AppStatusReporter.shared().updateState(AppStatusReporter.State.EXTERNAL_LOADING_FINISHED) } private fun showWelcomeIfNeeded() { @@ -775,25 +779,20 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), } catch (ignored: Throwable) {} } - private fun loadConfigSuccess(savedInstanceState: Bundle?) { - ResourceManager.shared.addonDirectory = addonPath - - if (savedInstanceState == null) { - // Add gl fragment - val celestiaFragment = CelestiaFragment.newInstance( - celestiaDataDirPath, - celestiaConfigFilePath, - addonPath, - enableMultisample, - enableHiDPI, - language - ) - ResourceManager.shared.addonDirectory = addonPath - supportFragmentManager - .beginTransaction() - .add(R.id.celestia_fragment_container, celestiaFragment) - .commitAllowingStateLoss() - } + private fun loadConfigSuccess() { + // Add gl fragment + val celestiaFragment = CelestiaFragment.newInstance( + celestiaDataDirPath, + celestiaConfigFilePath, + addonPath, + enableMultisample, + enableHiDPI, + language + ) + supportFragmentManager + .beginTransaction() + .add(R.id.celestia_fragment_container, celestiaFragment) + .commitAllowingStateLoss() } private fun loadConfigFailed(error: Throwable) { @@ -1689,6 +1688,7 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), var customDataDirPath: String? = null var customConfigFilePath: String? = null + private var language: String = "en" private var addonPath: String? = null private var extraScriptPath: String? = null private var languageOverride: String? = null diff --git a/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaFragment.kt index b8f2a522..8bb8305b 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaFragment.kt @@ -142,7 +142,7 @@ class CelestiaFragment: Fragment(), SurfaceHolder.Callback, CelestiaControlView. activeControlView.listener = this inactiveControlView.listener = this - if (currentState == AppStatusReporter.State.SUCCESS) { + if (currentState.value >= AppStatusReporter.State.LOADING_SUCCESS.value) { loadingFinished() } @@ -198,7 +198,7 @@ class CelestiaFragment: Fragment(), SurfaceHolder.Callback, CelestiaControlView. } override fun celestiaLoadingStateChanged(newState: AppStatusReporter.State) { - if (newState == AppStatusReporter.State.SUCCESS) + if (newState.value >= AppStatusReporter.State.LOADING_SUCCESS.value) loadingFinished() } @@ -320,7 +320,7 @@ class CelestiaFragment: Fragment(), SurfaceHolder.Callback, CelestiaControlView. core.tick() core.start() - AppStatusReporter.shared().updateState(AppStatusReporter.State.SUCCESS) + AppStatusReporter.shared().updateState(AppStatusReporter.State.LOADING_SUCCESS) return true } diff --git a/app/src/main/java/space/celestia/mobilecelestia/utils/AppStatusReporter.java b/app/src/main/java/space/celestia/mobilecelestia/utils/AppStatusReporter.java index e67d6bb1..66a814a1 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/utils/AppStatusReporter.java +++ b/app/src/main/java/space/celestia/mobilecelestia/utils/AppStatusReporter.java @@ -29,9 +29,9 @@ public enum State { LOADING_FAILURE(-1), NONE(0), EXTERNAL_LOADING(1), - EXTERNAL_LOADING_FINISHED(2), - LOADING(3), - SUCCESS(4); + LOADING(2), + LOADING_SUCCESS(3), + FINISHED(4); private int value;