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

Safety check #119

Merged
merged 8 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
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
Expand All @@ -80,7 +80,7 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.databinding:databinding-runtime:7.1.3'
implementation 'androidx.databinding:databinding-runtime:7.2.0'
implementation 'androidx.fragment:fragment-ktx:1.4.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.hamcrest:hamcrest:2.2'
Expand All @@ -106,7 +106,7 @@ dependencies {
}

// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:29.3.0')
implementation platform('com.google.firebase:firebase-bom:30.0.1')

// Declare the dependency for the Cloud Firestore library
// When using the BoM, you don't specify versions in Firebase library dependencies
Expand Down Expand Up @@ -135,7 +135,7 @@ dependencies {
androidTestImplementation "io.mockk:mockk-android:1.12.2"

//Declare the dependency for camera related functions
def camerax_version = "1.1.0-beta03"
def camerax_version = "1.1.0-rc01"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
Expand All @@ -148,8 +148,8 @@ dependencies {

// For UI dependency
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation("io.coil-kt:coil:2.0.0-rc03")

implementation('io.coil-kt:coil:2.1.0')
implementation 'com.google.firebase:firebase-appcheck-safetynet:16.0.0'
}


Expand Down
36 changes: 24 additions & 12 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,11 @@ 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
import kotlinx.coroutines.runBlocking

class LoadingActivity : AppCompatActivity() {
Expand All @@ -19,6 +22,26 @@ class LoadingActivity : AppCompatActivity() {
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) {
openLogin()
finish()
}
}

private fun openLogin() {
val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)
Expand Down Expand Up @@ -48,17 +71,6 @@ class LoadingActivity : AppCompatActivity() {
}
}

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

Firebase.initialize(this@LoadingActivity)
useEmulatorsIfNeeded()


}

fun nav() {
Log.w("LoadingPage", "nav")
Expand All @@ -73,7 +85,7 @@ class LoadingActivity : AppCompatActivity() {
}
}


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

companion object {
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/ch/epfl/sweng/rps/models/Game.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.epfl.sweng.rps.models

import android.util.Log
import ch.epfl.sweng.rps.models.GameMode.GameEdition
import com.google.firebase.Timestamp
import com.google.firebase.firestore.DocumentSnapshot
Expand Down Expand Up @@ -67,21 +66,22 @@ sealed class Game {
}

companion object {
fun DocumentSnapshot.toGame(): Game? {
val editionString = this["edition"] as String?
val gameMode = this["game_mode"] as String?

fun fromDocumentSnapshot(document: DocumentSnapshot): Game? {
val editionString = document["edition"] as String?
val gameMode = document["game_mode"] as String?
val edition =
editionString?.let { GameEdition.valueOf(it) }
?: gameMode?.let { GameMode.fromString(it).edition } ?: run {
Log.e("Game", "Could not parse edition from document: '${editionString}'")
return null
}
?: gameMode?.let { GameMode.fromString(it).edition }
?: throw IllegalArgumentException("Document has no edition or game mode")

val type = when (edition) {
GameEdition.RockPaperScissors -> Rps::class.java
GameEdition.TicTacToe -> TicTacToe::class.java
}
return toObject(type)
return document.toObject(type)
}

fun DocumentSnapshot.toGame(): Game? = fromDocumentSnapshot(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.annotation.VisibleForTesting
import ch.epfl.sweng.rps.db.FirebaseReferences
import ch.epfl.sweng.rps.db.FirebaseRepository
import ch.epfl.sweng.rps.models.Game
import ch.epfl.sweng.rps.models.Game.Companion.toGame
import ch.epfl.sweng.rps.models.Hand
import ch.epfl.sweng.rps.models.Round
import com.google.firebase.Timestamp
Expand Down Expand Up @@ -38,7 +39,7 @@ class FirebaseGameService(
Log.e("FirebaseGameService", "Error while listening to game $gameId", e)
error = e
} else {
game = value?.toObject<Game>()
game = value?.toGame()
}
}
_active = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ class SettingsActivity : AppCompatActivity(),
}
joinQueue?.setOnPreferenceClickListener {
viewLifecycleOwner.lifecycleScope.launch {
val TAG = "Matchmaking"
val games = ServiceLocator.getInstance().repository.myActiveGames()
Log.w("JOIN_QUEUE", "games: $games")
Log.w(TAG, "games: $games")
if (games.isNotEmpty()) {
Toast.makeText(
context,
Expand All @@ -155,7 +156,7 @@ class SettingsActivity : AppCompatActivity(),
).show()
return@launch
}
Log.d("JOIN_QUEUE", "Joining queue")
Log.d(TAG, "Joining queue")
try {
ServiceLocator.getInstance().matchmakingService.queue(
GameMode(
Expand All @@ -166,10 +167,10 @@ class SettingsActivity : AppCompatActivity(),
GameMode.GameEdition.RockPaperScissors
)
).collect {
Log.i("QueueStatus", it.toString())
Log.i(TAG, it.toString())
}
} catch (e: Exception) {
Log.e("QueueStatus", e.toString(), e)
Log.e(TAG, e.toString(), e)
}
}
true
Expand Down
2 changes: 1 addition & 1 deletion firebase/functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
module.exports = {
"env": {
"browser": true,
"commonjs": true,
Expand Down
Loading