Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nav #123

Merged
merged 3 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ dependencies {
implementation "androidx.camera:camera-extensions:${camerax_version}"

implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0'

// For UI dependency
implementation 'de.hdodenhof:circleimageview:3.1.0'
Expand Down
28 changes: 15 additions & 13 deletions app/src/main/java/ch/epfl/sweng/rps/LoadingActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import ch.epfl.sweng.rps.ui.onboarding.OnBoardingActivity
import ch.epfl.sweng.rps.utils.FirebaseEmulatorsUtils
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.appcheck.safetynet.SafetyNetAppCheckProviderFactory
import com.google.firebase.ktx.Firebase
import com.google.firebase.ktx.initialize
import kotlinx.coroutines.delay
Expand All @@ -19,21 +17,16 @@ class LoadingActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_loading)
setupApp()
}


/**
* Here logic to setup the app
*/
suspend fun logic() {
Log.w("LoadingPage", "logic")

val isTest = intent.getBooleanExtra("isTest", false)
Firebase.initialize(this@LoadingActivity)
val firebaseAppCheck = FirebaseAppCheck.getInstance()
firebaseAppCheck.installAppCheckProviderFactory(
SafetyNetAppCheckProviderFactory.getInstance()
)
useEmulatorsIfNeeded()
delay(1000)
if (!isTest) {
Expand All @@ -59,13 +52,16 @@ class LoadingActivity : AppCompatActivity() {
}
}

val isTest: Boolean
get() = intent.getBooleanExtra("isTest", false)

private fun setupApp() {
// All the logic here is to check if the user is logged in or not
val helpMeNav = intent.extras?.getBoolean(HELP_ME_NAV_EXTRA, false) ?: false
if (!helpMeNav) {
if (!hasRunLogic) {
runBlocking { logic() }
hasRunLogic = true
}
val isTest = intent.getBooleanExtra("isTest", false)

if (!isTest) {
nav()
}
Expand All @@ -78,20 +74,26 @@ class LoadingActivity : AppCompatActivity() {
intent.extras?.getBoolean(OnBoardingActivity.DONE_ONBOARDING_EXTRA, false) ?: false
if (OnBoardingActivity.isFirstTime(this) && !doneOnBoarding) {
Log.w("LoadingPage", "nav to onboarding")
OnBoardingActivity.launch(this, OnBoardingActivity.Destination.LOADING)
OnBoardingActivity.launch(this, OnBoardingActivity.Destination.FINISH)
} else {
Log.w("LoadingPage", "nav to main")
startActivity(Intent(this, LoginActivity::class.java))
}
}


private val isTest get() = intent.getBooleanExtra("isTest", false)
override fun onResume() {
super.onResume()
setupApp()
}


companion object {
const val HELP_ME_NAV_EXTRA = "helpMeNav"
const val IS_TEST_EXTRA = "isTest"

private var hasRunLogic = false

fun launch(context: Context, helpMeNav: Boolean, vararg extras: Pair<String, Any>) {
val intent = Intent(context, LoadingActivity::class.java)
intent.putExtra(HELP_ME_NAV_EXTRA, helpMeNav)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.ApiException
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.GoogleAuthProvider
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
import kotlinx.coroutines.runBlocking

class FirebaseAuthenticator private constructor(
private val context: ComponentActivity,
val callback: (User) -> Unit
):
) :
Authenticator() {

companion object {
Expand All @@ -34,7 +32,6 @@ class FirebaseAuthenticator private constructor(
private const val TAG = "GoogleActivity"
}

private var auth: FirebaseAuth = Firebase.auth
private val repo = ServiceLocator.getInstance().repository
private val resultLauncher =
context.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { res ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentManager
import androidx.preference.PreferenceManager
import ch.epfl.sweng.rps.LoadingActivity
import ch.epfl.sweng.rps.R
import com.ramotion.paperonboarding.PaperOnboardingFragment
import com.ramotion.paperonboarding.PaperOnboardingPage
Expand Down Expand Up @@ -51,17 +50,15 @@ class OnBoardingActivity : AppCompatActivity() {
const val DONE_ONBOARDING_EXTRA = "done_onboarding"

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun navOut(context: OnBoardingActivity, onDestroy: (() -> Unit)? = null) {
setFirstTime(context, false)
val destination = context.intent.getSerializableExtra(DESTINATION_EXTRA) as Destination
fun navOut(onBoardingActivity: OnBoardingActivity, onDestroy: (() -> Unit)? = null) {
setFirstTime(onBoardingActivity, false)
val destination =
onBoardingActivity.intent.getSerializableExtra(DESTINATION_EXTRA) as Destination
Log.i("OnBoardingActivity", "onboarding finished")
Log.i("OnBoardingActivity", "destination: $destination")
when (destination) {
Destination.FINISH -> {
context.finish()
}
Destination.LOADING -> {
LoadingActivity.launch(context, true, DONE_ONBOARDING_EXTRA to true)
onBoardingActivity.finish()
}
}
}
Expand All @@ -71,7 +68,6 @@ class OnBoardingActivity : AppCompatActivity() {

enum class Destination {
FINISH,
LOADING
}

private lateinit var fragmentManager: FragmentManager
Expand Down