Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Jwen/improve code quality #367

Merged
merged 31 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
95b0f08
make setupProfile private in MyProfileFragment.kt
jiabaow Jun 6, 2022
7b2997e
make functions private in PublicProfileActivity.kt
jiabaow Jun 6, 2022
85e9485
remove unused import in PublicProfileActivity.kt
jiabaow Jun 6, 2022
2ed516f
reformat MyProfileFragment.kt
jiabaow Jun 6, 2022
296a7b4
move MyProfileFragment.kt tp /Fragment
jiabaow Jun 6, 2022
b534dd4
use profileInterface for MyProfileFragment.kt and PublicProfileActivi…
jiabaow Jun 6, 2022
6ef1a5e
move setTextOfMultipleViews in ProfileInterface.kt
jiabaow Jun 6, 2022
8f343d8
move setViewVisibility from MyProfileFragment.kt to ProfileInterface.kt
jiabaow Jun 6, 2022
76a3edc
remove unused parameter of showTestDialog in MyProfileFragment.kt
jiabaow Jun 6, 2022
01899aa
delete deleteImage and showImageChangeDialog in MyProfileFragment.kt
jiabaow Jun 6, 2022
8c0f5fb
dedup onActivityResult
jiabaow Jun 6, 2022
2ae62a6
delete updateImage in MyProfileFragment.kt
jiabaow Jun 6, 2022
4b3b202
move loadFollowing in ProfileInterface.kt
jiabaow Jun 6, 2022
9ecc53d
refactor showAHideB
jiabaow Jun 6, 2022
14a1753
change onActivityResult back
jiabaow Jun 6, 2022
3023b36
refactor view for showAHideB
jiabaow Jun 6, 2022
d9dd806
refactor setViewsVisibility in MyProfileFragment.kt
jiabaow Jun 6, 2022
7c9a9d5
refactor qr code page and profile content in MyProfileFragment.kt
jiabaow Jun 6, 2022
ded0e70
fix return to main btn
jiabaow Jun 6, 2022
d016c57
change context of activity_profile.xml
jiabaow Jun 6, 2022
5207beb
fix profile return to main
jiabaow Jun 6, 2022
cdcb65d
regroup qr code visibility listeners
jiabaow Jun 6, 2022
0ab53e8
refactor setChangeImageBtnListener
jiabaow Jun 6, 2022
bccaba3
refactor setGenreListeners in GameSetupFragment.kt
jiabaow Jun 6, 2022
1b482f2
refactor setGameModeListeners in GameSetupFragment.kt
jiabaow Jun 6, 2022
4bae6a2
refactor setGenreListeners in GameSetupFragment.kt
jiabaow Jun 6, 2022
f1e9a03
clean GameSetupFragment.kt
jiabaow Jun 6, 2022
aef7859
refactor setReturnBtnListener in GameSetupFragment.kt
jiabaow Jun 6, 2022
bd2951f
extract genrePerScoreboard and chooseSetting in GameSetupFragment.kt
jiabaow Jun 6, 2022
edc4f5c
refactor switchToEnding in GameActivity.kt
jiabaow Jun 6, 2022
239d036
refactor switchToEnding in GameActivity.kt
jiabaow Jun 6, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import ch.sdp.vibester.R
import ch.sdp.vibester.TestMode
import ch.sdp.vibester.activity.profile.MyProfileFragment
import ch.sdp.vibester.auth.FireBaseAuthenticator
import ch.sdp.vibester.fragment.AuthenticationFragment
import ch.sdp.vibester.fragment.GameSetupFragment
import ch.sdp.vibester.launchFragmentInHiltContainer
import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ch.sdp.vibester.activity.profile
package ch.sdp.vibester.activity

import android.content.Context
import android.content.Intent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package ch.sdp.vibester.activity.profile
package ch.sdp.vibester.fragment

import android.content.Context
import android.content.Intent
import android.view.View
import androidx.core.os.bundleOf

import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.UiController
Expand All @@ -17,16 +14,13 @@ import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.BoundedMatcher
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.MainActivity
import ch.sdp.vibester.auth.FireBaseAuthenticator
import ch.sdp.vibester.database.DataGetter
import ch.sdp.vibester.database.ImageGetter
import ch.sdp.vibester.fragment.AuthenticationFragment
import ch.sdp.vibester.launchFragmentInHiltContainer
import ch.sdp.vibester.user.User
import com.google.firebase.auth.FirebaseUser
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
android:name=".activity.BuzzerScreenActivity"
android:exported="false" />
<activity
android:name=".activity.profile.PublicProfileActivity"
android:name=".activity.PublicProfileActivity"
android:windowSoftInputMode="adjustPan"
android:exported="false" />
<activity
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/ch/sdp/vibester/activity/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,11 @@ open class GameActivity : AppCompatActivity() {
val intent = Intent(this, GameEndingActivity::class.java)

//Set list of incorrect songs
val incorrectSongList: ArrayList<String> = ArrayList(
gameManager.getWrongSongs().map { it.getTrackName() + " - " + it.getArtistName() })
val incorrectSongList: ArrayList<String> = createSongList(gameManager.getWrongSongs())
intent.putStringArrayListExtra("incorrectSongList", incorrectSongList)

//Set list of correct songs
val correctSongList: ArrayList<String> = ArrayList(
gameManager.getCorrectSongs().map { it.getTrackName() + " - " + it.getArtistName() })
val correctSongList: ArrayList<String> = createSongList(gameManager.getCorrectSongs())
intent.putStringArrayListExtra("correctSongList", correctSongList)

// Set statistics
Expand All @@ -146,6 +144,11 @@ open class GameActivity : AppCompatActivity() {
startActivity(intent)
}


private fun createSongList(songs: MutableList<Song>): ArrayList<String> {
return ArrayList(songs.map { it.getTrackName() + " - " + it.getArtistName() })
}

/**
* Function to set a song for the first round and play a game.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ch.sdp.vibester.activity.profile
package ch.sdp.vibester.activity

import android.app.Activity
import android.content.Intent
Expand All @@ -16,12 +16,11 @@ import androidx.core.widget.NestedScrollView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.MainActivity
import ch.sdp.vibester.auth.FireBaseAuthenticator
import ch.sdp.vibester.database.DataGetter
import ch.sdp.vibester.database.ImageGetter
import ch.sdp.vibester.helper.Helper
import ch.sdp.vibester.helper.IntentSwitcher
import ch.sdp.vibester.helper.ProfileInterface
import ch.sdp.vibester.user.OnItemClickListener
import ch.sdp.vibester.user.ProfileFollowingAdapter
import ch.sdp.vibester.user.User
Expand All @@ -36,7 +35,7 @@ import javax.inject.Inject

/** profile page of a user with only public information */
@AndroidEntryPoint
class PublicProfileActivity : AppCompatActivity(), OnItemClickListener {
class PublicProfileActivity : AppCompatActivity(), OnItemClickListener, ProfileInterface {
@Inject
lateinit var dataGetter: DataGetter

Expand All @@ -46,13 +45,13 @@ class PublicProfileActivity : AppCompatActivity(), OnItemClickListener {
@Inject
lateinit var imageGetter: ImageGetter

private val imageSize = 1000
private val imageRequestCode = 100
override val imageSize = 1000
override val imageRequestCode = 100

private var followings: MutableList<User> ? = null
private var profileFollowingAdapter: ProfileFollowingAdapter?= null
override var followings: MutableList<User> ? = null
override var profileFollowingAdapter: ProfileFollowingAdapter?= null

lateinit var userId: String
private lateinit var userId: String

override fun onCreate(savedInstanceState: Bundle?) {
requestWindowFeature(Window.FEATURE_NO_TITLE)
Expand All @@ -61,10 +60,12 @@ class PublicProfileActivity : AppCompatActivity(), OnItemClickListener {
setContentView(R.layout.activity_profile)

userId = intent.getStringExtra("UserId").toString()
val statView = findViewById<NestedScrollView>(R.id.profile_scroll_stat)
val followingView = findViewById<NestedScrollView>(R.id.profile_scroll_following)
if (intent.getStringExtra("ScoresOrFollowing") == R.string.profile_scores.toString()) {
showAHideB(R.id.profile_scroll_stat, R.id.profile_scroll_following)
showAHideB(statView, followingView)
} else if (intent.getStringExtra("ScoresOrFollowing") == R.string.profile_following.toString()) {
showAHideB(R.id.profile_scroll_following, R.id.profile_scroll_stat)
showAHideB(followingView, statView)
}

setupRecycleViewForFriends()
Expand All @@ -75,22 +76,21 @@ class PublicProfileActivity : AppCompatActivity(), OnItemClickListener {
setFollowingScoresBtnListener(R.id.profile_following, R.id.profile_scroll_following, R.id.profile_scroll_stat)

queryDatabase()

}

fun queryDatabase() {
override fun queryDatabase() {
dataGetter.getUserData(userId, this::setupProfile)
}

private fun setupRecycleViewForFriends() {
override fun setupRecycleViewForFriends() {
findViewById<RecyclerView>(R.id.profile_followingList).apply {
layoutManager = LinearLayoutManager(context)
adapter = followings?.let { ProfileFollowingAdapter(it, dataGetter, authenticator,this@PublicProfileActivity) }
setHasFixedSize(true)
}
}

private fun showFriendsPosition(friends: MutableList<User>?) {
override fun showFriendsPosition(friends: MutableList<User>?) {
profileFollowingAdapter = ProfileFollowingAdapter(friends!!, dataGetter, authenticator, this)
findViewById<RecyclerView>(R.id.profile_followingList)!!.adapter = profileFollowingAdapter
}
Expand All @@ -116,64 +116,23 @@ class PublicProfileActivity : AppCompatActivity(), OnItemClickListener {
}
}

/**
* @param btnId Id of the button (either following or scores)
* @param show id of the view to show
* @param hide id of the view to hide
*/
private fun setFollowingScoresBtnListener(btnId: Int, show: Int, hide: Int) {
override fun setFollowingScoresBtnListener(btnId: Int, show: Int, hide: Int) {
findViewById<Button>(btnId).setOnClickListener {
showAHideB(show, hide)
showAHideB(findViewById<NestedScrollView>(show), findViewById<NestedScrollView>(hide))
}
}

/**
* @param a id of the view to show
* @param b id of the view to hide
*/
fun showAHideB(a: Int, b: Int) {
findViewById<NestedScrollView>(a).visibility = View.VISIBLE
findViewById<NestedScrollView>(b).visibility = View.GONE
}

/**
* A function that downloads an image and sets it.
* @param imageURI URI of the image
*/
private fun setImage(imageURI: Uri) {
override fun setImage(imageURI: Uri) {
val avatar = findViewById<ImageView>(R.id.profile_image_ImageView)
Helper().setImage(imageURI, avatar, imageSize)
}


/**
* Function that sets the text of a given TextView to the string variant of an integer.
* @param id: The id of the TextView to be changed.
* @param text: The integer to be set as the text.
*/
private fun setTextOfView(id: Int, text: Int) {
override fun setTextOfView(id: Int, text: Int) {
findViewById<TextView>(id).text = text.toString()
}

/**
* Function that sets the texts of multiple TextViews.
* @param user: The user from which we will recover the text to set.
*/
private fun setTextOfMultipleViews(user: User) {
setTextOfView(R.id.profile_total_games_stat, user.totalGames)
setTextOfView(R.id.profile_top_tracks, user.scores.getOrDefault("top tracks", 0))
setTextOfView(R.id.profile_kpop, user.scores.getOrDefault("kpop", 0))
setTextOfView(R.id.profile_rock, user.scores.getOrDefault("rock", 0))
setTextOfView(R.id.profile_bts, user.scores.getOrDefault("BTS", 0))
setTextOfView(R.id.profile_imagine_dragons, user.scores.getOrDefault("Imagine Dragons", 0))
setTextOfView(R.id.profile_billie_eilish, user.scores.getOrDefault("Billie Eilish", 0))
}

/**
* Function to handle setting up the profile.
* @param user: The user whose profile we are setting up.
*/
fun setupProfile(user: User){
override fun setupProfile(user: User){
// Currently assuming that empty username means no user !
if (user.username != "") {
findViewById<TextView>(R.id.username).text = user.username
Expand All @@ -187,34 +146,12 @@ class PublicProfileActivity : AppCompatActivity(), OnItemClickListener {
}

if (user.following.isNotEmpty()) {
loadFollowing(user.following)
loadFollowing(user.following, dataGetter)
}

}

/**
* helper function to add user from followingMap to followings
* @param followingMap user.following
*
*/
private fun loadFollowing(followingMap: Map<String, Boolean>) {
followingMap.forEach { (userId, isFollowing) -> if (isFollowing) dataGetter.getUserData(userId, this::addFollowing) }
showFriendsPosition(followings)
}

/**
* callback function to add one user to followings
* @param following the user to add in list
*/
private fun addFollowing(following: User) {
followings?.add(following)
}

/**
* generate the qr code bitmap of the given data
* @param data Qr Code data
*/
private fun generateQrCode(data: String) {
override fun generateQrCode(data: String) {
val size = 512
val hints = HashMap<EncodeHintType?, Any?>()
hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.H
Expand Down
Loading