From f5052b43617807b6cc7290074c5fabacf435642e Mon Sep 17 00:00:00 2001 From: jiabaow Date: Mon, 30 May 2022 20:53:23 +0200 Subject: [PATCH 1/7] Revert "move game set up up" This reverts commit 0496bfe460678e89f56bd9d12ec243b59fa61085. --- app/src/main/res/layout/fragment_layout_game_setup.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/layout/fragment_layout_game_setup.xml b/app/src/main/res/layout/fragment_layout_game_setup.xml index 031a60386..07b0b0f41 100644 --- a/app/src/main/res/layout/fragment_layout_game_setup.xml +++ b/app/src/main/res/layout/fragment_layout_game_setup.xml @@ -37,13 +37,13 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="41dp" - android:layout_marginTop="60dp" + android:layout_marginTop="122dp" android:layout_marginEnd="45dp" - android:layout_marginBottom="40dp" + android:layout_marginBottom="54dp" android:fontFeatureSettings="smcp" android:text="@string/holder_setup_game_type" android:textAlignment="center" - android:textSize="30sp" + android:textSize="30dp" android:textStyle="bold" /> + android:textSize="20dp" /> Date: Mon, 30 May 2022 20:58:29 +0200 Subject: [PATCH 2/7] clean and reformat DataGetter.kt --- .../ch/sdp/vibester/database/DataGetter.kt | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index d2bec1a0c..85301f9f9 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -90,7 +90,7 @@ class DataGetter @Inject constructor() { fun updateSubFieldInt(userID: String, newVal: Int, fieldName: String, subFieldName: String, method: String) { dbUserRef.child(userID).child(fieldName).child(subFieldName) .get().addOnSuccessListener { t -> - var finalVal = checkValue(t, method, newVal) //newVal: TO DELETE IF TESTS PASS, OTHERWISE ROLL BACK! + val finalVal = checkValue(t, method, newVal) //newVal: TO DELETE IF TESTS PASS, OTHERWISE ROLL BACK! setSubFieldValue(userID, fieldName, subFieldName, finalVal) } } @@ -104,7 +104,7 @@ class DataGetter @Inject constructor() { */ private fun checkValue(t: DataSnapshot, method: String, newVal: Int): Int { var finalVal = newVal - if(t.value != null) { + if (t.value != null) { val previousVal = (t.value as Long?)!!.toInt() when (method) { "sum" -> finalVal += previousVal @@ -128,7 +128,6 @@ class DataGetter @Inject constructor() { /** * This function creates a new room in the database - * @param roomName the name of the new room * @param callback function to be called when the room has been created */ fun createRoom(callback: (PartyRoom, String) -> Unit) { @@ -182,7 +181,7 @@ class DataGetter @Inject constructor() { queryUsers.removeEventListener(this) } override fun onCancelled(error: DatabaseError) { - Log.w(ContentValues.TAG, "searchByField:onCancelled", error.toException()) + Log.w(TAG, "searchByField:onCancelled", error.toException()) } }) } @@ -230,9 +229,9 @@ class DataGetter @Inject constructor() { override fun onDataChange(dataSnapshot: DataSnapshot) { for (snapshot in dataSnapshot.children) { val partyRoom: PartyRoom? = snapshot.getValue(PartyRoom::class.java) - if(partyRoom != null) { + if (partyRoom != null) { val currUserEmail = getCurrentUser()?.email!! - if(!partyRoom.getEmailList().contains(currUserEmail)) { + if (!partyRoom.getEmailList().contains(currUserEmail)) { partyRoom.addUserEmail(currUserEmail) updateRoomUserList(partyRoom) } @@ -240,7 +239,7 @@ class DataGetter @Inject constructor() { } val snapshotMap = snapshot.value as Map val songList = snapshotMap["songList"] as List<*> - var gameSongList: MutableList> = mutableListOf() + val gameSongList: MutableList> = mutableListOf() for (song in songList) { val tempPair: Map = song as Map gameSongList.add( @@ -254,17 +253,11 @@ class DataGetter @Inject constructor() { } } override fun onCancelled(error: DatabaseError) { - Log.w(ContentValues.TAG, "getRoomData:onCancelled", error.toException()) + Log.w(TAG, "getRoomData:onCancelled", error.toException()) } }) } - /** - * This functions that updates the field of a room entry - * @param roomID ID of the room - * @param fieldName name of the field to update - * @param value new value to write to the database - */ /** * This functions that updates the field of a room entry * @param roomID ID of the room @@ -274,12 +267,7 @@ class DataGetter @Inject constructor() { fun updateRoomField(roomID: String, fieldName: String, value: T) { dbRoomRef.child("${roomID}/${fieldName}").setValue(value) } - - /** - * This functions reads the start of the game field and calls the appropriate functions - * @param roomID ID of the room - * @param callback callback to be called when the read value is available - */ + /** * This functions reads the start of the game field and calls the appropriate functions * @param roomID ID of the room @@ -300,5 +288,5 @@ class DataGetter @Inject constructor() { } } queryRooms.addValueEventListener(startGameListener) -} + } } \ No newline at end of file From acde2c1ceacce697a4d3cb9306ce1ad9be17cb36 Mon Sep 17 00:00:00 2001 From: jiabaow Date: Mon, 30 May 2022 21:05:24 +0200 Subject: [PATCH 3/7] shorten getRoomData in DataGetter.kt --- .../ch/sdp/vibester/database/DataGetter.kt | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt index 85301f9f9..935a77402 100644 --- a/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt +++ b/app/src/main/java/ch/sdp/vibester/database/DataGetter.kt @@ -9,6 +9,7 @@ import ch.sdp.vibester.user.User import com.google.firebase.auth.FirebaseUser import com.google.firebase.database.DataSnapshot import com.google.firebase.database.DatabaseError +import com.google.firebase.database.Query import com.google.firebase.database.ValueEventListener import com.google.firebase.database.ktx.getValue import java.util.* @@ -211,7 +212,8 @@ class DataGetter @Inject constructor() { return authenticator.getCurrUser() } - /** + + /** * This functions fetches the data of the given user from the database * @param roomID the name of the room to retrieve data from * @param partyRoomCallback the function to be called when the data of the appropriate room data is available @@ -221,40 +223,38 @@ class DataGetter @Inject constructor() { partyRoomCallback: (PartyRoom, String) -> Unit, songListCallback: (MutableList>) -> Unit) { - val queryRooms = dbRoomRef - .orderByChild("roomID") - .equalTo(roomID) + dbRoomRef.orderByChild("roomID").equalTo(roomID) + .addValueEventListener(object : ValueEventListener { - queryRooms.addValueEventListener(object : ValueEventListener { - override fun onDataChange(dataSnapshot: DataSnapshot) { - for (snapshot in dataSnapshot.children) { - val partyRoom: PartyRoom? = snapshot.getValue(PartyRoom::class.java) - if (partyRoom != null) { - val currUserEmail = getCurrentUser()?.email!! - if (!partyRoom.getEmailList().contains(currUserEmail)) { - partyRoom.addUserEmail(currUserEmail) - updateRoomUserList(partyRoom) + override fun onDataChange(dataSnapshot: DataSnapshot) { + for (snapshot in dataSnapshot.children) { + val partyRoom: PartyRoom? = snapshot.getValue(PartyRoom::class.java) + if (partyRoom != null) { + val currUserEmail = getCurrentUser()?.email!! + if (!partyRoom.getEmailList().contains(currUserEmail)) { + partyRoom.addUserEmail(currUserEmail) + updateRoomUserList(partyRoom) + } + partyRoomCallback(partyRoom, partyRoom.getRoomID()) } - partyRoomCallback(partyRoom, partyRoom.getRoomID()) - } - val snapshotMap = snapshot.value as Map - val songList = snapshotMap["songList"] as List<*> - val gameSongList: MutableList> = mutableListOf() - for (song in songList) { - val tempPair: Map = song as Map - gameSongList.add( - Pair( - tempPair.getOrDefault("first", ""), - tempPair.getOrDefault("second", "") + + val gameSongList: MutableList> = mutableListOf() + for (song in (snapshot.value as Map) ["songList"] as List<*>) { + val tempPair: Map = song as Map + gameSongList.add( + Pair( + tempPair.getOrDefault("first", ""), + tempPair.getOrDefault("second", "") + ) ) - ) + } + songListCallback(gameSongList) } - songListCallback(gameSongList) } - } - override fun onCancelled(error: DatabaseError) { - Log.w(TAG, "getRoomData:onCancelled", error.toException()) - } + + override fun onCancelled(error: DatabaseError) { + Log.w(TAG, "getRoomData:onCancelled", error.toException()) + } }) } From 76bf842afcd56f31ca02a336fb5b87d94257993e Mon Sep 17 00:00:00 2001 From: jiabaow Date: Mon, 30 May 2022 21:10:50 +0200 Subject: [PATCH 4/7] break up setupControls in QrScanningActivity.kt --- .../ch/sdp/vibester/activity/QrScanningActivity.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ch/sdp/vibester/activity/QrScanningActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/QrScanningActivity.kt index 4cad4c69f..f3166ddff 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/QrScanningActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/QrScanningActivity.kt @@ -101,7 +101,13 @@ class QrScanningActivity : AppCompatActivity() { .setAutoFocusEnabled(true) .build() - binding.cameraSurfaceView.getHolder().addCallback(object : SurfaceHolder.Callback { + setupCamera(camera) + + setupBarcodeDetector(barcodeDetector) + } + + private fun setupCamera(camera: CameraSource) { + binding.cameraSurfaceView.holder.addCallback(object : SurfaceHolder.Callback { override fun surfaceCreated(holder: SurfaceHolder) { surfaceHandler(holder) } @@ -123,7 +129,9 @@ class QrScanningActivity : AppCompatActivity() { camera.stop() } }) + } + private fun setupBarcodeDetector(barcodeDetector: BarcodeDetector) { barcodeDetector.setProcessor(object : Detector.Processor { override fun release() { Toast.makeText(applicationContext, getString(R.string.qrScanning_scannerClosed), Toast.LENGTH_SHORT).show() From 5bb527b053a737aff1aa060195155457bc699cf3 Mon Sep 17 00:00:00 2001 From: jiabaow Date: Mon, 30 May 2022 21:16:45 +0200 Subject: [PATCH 5/7] break down switchToGame in BuzzerSetupActivity.kt --- .../vibester/activity/BuzzerSetupActivity.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/activity/BuzzerSetupActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/BuzzerSetupActivity.kt index c44526625..f006fb52c 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/BuzzerSetupActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/BuzzerSetupActivity.kt @@ -75,7 +75,7 @@ class BuzzerSetupActivity : AppCompatActivity(), AdapterView.OnItemSelectedListe * id: the id of the field to update */ fun updatePlayerNameVisibility(n: Int, id: Int) { - var i = when (id) { + val i = when (id) { R.id.namePlayer2 -> 2 R.id.namePlayer3 -> 3 R.id.namePlayer4 -> 4 @@ -91,29 +91,36 @@ class BuzzerSetupActivity : AppCompatActivity(), AdapterView.OnItemSelectedListe fun switchToGame(view: View) { val intent = Intent(this, BuzzerScreenActivity::class.java) - val players = - findViewById(R.id.playerNames).children.filter { child: View -> child.visibility == View.VISIBLE } + val players = findViewById(R.id.playerNames).children.filter { child: View -> child.visibility == View.VISIBLE } val pNameArray = arrayOfNulls(players.count()) + if (players.count() > 0) { intent.putExtra("Number of players", players.count()) } else { intent.putExtra("Number of players", 1) } + intent.putExtra("gameManager", gameManager) intent.putExtra("Difficulty", difficulty) - val editTextIdArray = - arrayListOf(R.id.namePlayer1, R.id.namePlayer2, R.id.namePlayer3, R.id.namePlayer4) + + setupPlayerView(players, pNameArray) + + intent.putExtra("Player Names", pNameArray) + startActivity(intent) + } + + private fun setupPlayerView(players: Sequence, pNameArray: Array) { + val editTextIdArray = arrayListOf(R.id.namePlayer1, R.id.namePlayer2, R.id.namePlayer3, R.id.namePlayer4) var i = 0 for (playerView in players) { val name = findViewById(editTextIdArray[i]).text.toString() if (name.isNotEmpty()) { pNameArray[i] = name } else { findViewById(R.id.missingNameAlert).visibility = View.VISIBLE findViewById