Skip to content

Commit

Permalink
Remove external_loading_finished, divide success state
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Apr 30, 2021
1 parent af7cc32 commit 13415e4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
68 changes: 34 additions & 34 deletions app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -349,25 +348,32 @@ 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()
}
}

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<View>(R.id.loading_fragment_container).visibility = View.GONE

// apply setting
readSettings()
ResourceManager.shared.addonDirectory = addonPath

// open url/script if present
readyForInteraction = true
runScriptOrOpenURLIfNeeded()

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 13415e4

Please sign in to comment.