Skip to content

Commit

Permalink
Merge pull request #145 from DimensionSrl/feature/updates
Browse files Browse the repository at this point in the history
Improved Welcome screen lifecycle
  • Loading branch information
dulvui authored Feb 2, 2024
2 parents 957f92e + 675771d commit 6428bba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
27 changes: 16 additions & 11 deletions app/src/main/java/it/bz/noi/community/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package it.bz.noi.community

import android.content.Intent
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -40,10 +41,7 @@ class MainActivity : AppCompatActivity() {

private val navController: NavController get() = findNavController(R.id.nav_host_fragment)


private val showWelcome by lazy {
intent.getBooleanExtra(EXTRA_SHOW_WELCOME, false)
}
private var showWelcome: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -52,13 +50,14 @@ class MainActivity : AppCompatActivity() {
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

if (true || showWelcome) {
if (!runBlocking { getWelcomeUnderstood() }) {
val inflater = navController.navInflater
val graph = inflater.inflate(R.navigation.mobile_navigation)
graph.setStartDestination(R.id.welcome)
navController.graph = graph
}
showWelcome = savedInstanceState?.getBoolean(STATE_SHOW_WELCOME) ?: intent.getBooleanExtra(EXTRA_SHOW_WELCOME, false)

if (showWelcome) {
showWelcome = false
val inflater = navController.navInflater
val graph = inflater.inflate(R.navigation.mobile_navigation)
graph.setStartDestination(R.id.welcome)
navController.graph = graph
}

val toolbar = binding.toolbar
Expand Down Expand Up @@ -187,8 +186,14 @@ class MainActivity : AppCompatActivity() {
}
}

override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
super.onSaveInstanceState(outState, outPersistentState)
outState.putBoolean(STATE_SHOW_WELCOME, showWelcome)
}

companion object {
internal const val EXTRA_SHOW_WELCOME: String = "show_welcome"
private const val STATE_SHOW_WELCOME: String = "show_welcome"
private const val TAG = "MainActivity"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import it.bz.noi.community.databinding.ActivitySplashBinding
import it.bz.noi.community.oauth.AuthManager
import it.bz.noi.community.oauth.AuthStateStatus
import it.bz.noi.community.storage.getSkipParam
import it.bz.noi.community.storage.getWelcomeUnderstood
import it.bz.noi.community.storage.setSkipParam
import it.bz.noi.community.ui.onboarding.OnboardingActivity
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -82,7 +83,9 @@ class SplashScreenActivity : AppCompatActivity() {

private fun goToMainActivity() {
if (isFinishing) return
startActivity(Intent(this, MainActivity::class.java))
startActivity(Intent(this, MainActivity::class.java).apply {
putExtra(MainActivity.EXTRA_SHOW_WELCOME, runBlocking { !getWelcomeUnderstood() })
})
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import it.bz.noi.community.R
import it.bz.noi.community.databinding.ActivityOnboardingBinding
import it.bz.noi.community.oauth.AuthManager
import it.bz.noi.community.oauth.AuthStateStatus
import it.bz.noi.community.storage.getWelcomeUnderstood
import it.bz.noi.community.ui.WebViewFragment
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -112,9 +113,10 @@ class OnboardingActivity : AppCompatActivity() {
}
}

internal fun goToMainActivity() {
internal suspend fun goToMainActivity() {
val showWelcome = !getWelcomeUnderstood()
startActivity(Intent(this, MainActivity::class.java).apply {
putExtra(MainActivity.EXTRA_SHOW_WELCOME, true)
putExtra(MainActivity.EXTRA_SHOW_WELCOME, showWelcome)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import it.bz.noi.community.oauth.AuthManager
import it.bz.noi.community.oauth.AuthStateStatus
import it.bz.noi.community.storage.getPrivacyAccepted
import it.bz.noi.community.storage.getPrivacyAcceptedFlow
import it.bz.noi.community.storage.setPrivacyAccepted
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

class OnboardingViewModel(
app: Application,
Expand Down

0 comments on commit 6428bba

Please sign in to comment.