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

kamila/user_profile #51

Merged
merged 40 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
217d1ee
activity_profile.xml: add the profile layout
kamilababayeva Mar 9, 2022
57063e9
strings.xml: fix the conflict
kamilababayeva Mar 9, 2022
7e72d82
activity_profile.xml: basic profile
kamilababayeva Mar 9, 2022
8152aff
table_shape.xml: design for the profile table
kamilababayeva Mar 9, 2022
b4304d0
UserProfile.kt: userProfile data class
kamilababayeva Mar 9, 2022
23f7a4b
ProfileSetup.kt: set profile activity
kamilababayeva Mar 9, 2022
58771e4
ProfileSetup.kt: initialize user data
kamilababayeva Mar 9, 2022
7b0caa2
ProfileSetup.kt: extract ID to retrieve user's data
kamilababayeva Mar 9, 2022
9dc3a2c
ProfileSetup.kt: remove useless code
kamilababayeva Mar 9, 2022
0c58e9a
ProfileDataProvider.kt: class to retrieve profile data
kamilababayeva Mar 9, 2022
83e8501
strings.xml: fix the conflict
kamilababayeva Mar 9, 2022
105008f
MainActivity.kt: fix the conflict
kamilababayeva Mar 9, 2022
5c98286
Manifest.xml:combine activities
kamilababayeva Mar 9, 2022
58908bc
Helper: add Glide to render the image
kamilababayeva Mar 10, 2022
5a8e10f
activity_profile.xml: fix the image position
kamilababayeva Mar 10, 2022
7640664
activity_main.xml: add the button for profile
kamilababayeva Mar 10, 2022
5967ac3
UserProfile.kt: change val to var
kamilababayeva Mar 10, 2022
a694ddd
activity_profile.xml: change the text size
kamilababayeva Mar 10, 2022
f7ca742
ProfileSetup.kt: add image loading to the profile
kamilababayeva Mar 10, 2022
9656e42
ProfileDataProvider.kt: function to set users (needed for testing)
kamilababayeva Mar 10, 2022
53e94ec
MainActivity.kt: add button to fire ProfileSetup activity
kamilababayeva Mar 10, 2022
d3c2bb6
MainActivity.kt: add test for the Profile Setup button
kamilababayeva Mar 10, 2022
e4ee052
activity_profile.xml: change id of table
kamilababayeva Mar 10, 2022
4373d3e
ProfileSetupTest.kt: add tesst to check the elements on the activity
kamilababayeva Mar 10, 2022
fca142b
ProfileDataProvider.kt: combine two functions to set profile data; ad…
kamilababayeva Mar 10, 2022
eadf01b
ProfileSetup.kt: change function name
kamilababayeva Mar 10, 2022
58e7850
ProfileDataProviderTest.kt: check the function generate the profile d…
kamilababayeva Mar 10, 2022
374ca59
Helper.kt: add error and placeholder image
kamilababayeva Mar 10, 2022
e2b6707
ProfileSetupTest.kt: check the matching text
kamilababayeva Mar 10, 2022
fc2f215
UserProfile: put data as Serializable
kamilababayeva Mar 10, 2022
7213c32
ProfileSetup.kt: get data as Serializable
kamilababayeva Mar 10, 2022
4bd4966
ProfileSetupTest.kt: fix the test
kamilababayeva Mar 10, 2022
845cd8d
MainActivity: move the logic of getting data
kamilababayeva Mar 10, 2022
cf4d198
Merge branch 'main' into kamila/user-profile
kamilababayeva Mar 10, 2022
3024d3a
activity_profile.xml: fix font
kamilababayeva Mar 10, 2022
51d3685
ProfileDataProvider: fix the data
kamilababayeva Mar 10, 2022
6c05f11
ProfileSetup.kt: disable image display
kamilababayeva Mar 10, 2022
87644b0
Resolve the merge conflicts
kamilababayeva Mar 10, 2022
0e46952
activity_main.xml: move the profile button
kamilababayeva Mar 10, 2022
d53c95b
Merge branch 'main' into kamila/user-profile
MaximeZmt Mar 11, 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
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion app/src/androidTest/java/ch/sdp/vibester/MainActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.test.espresso.intent.matcher.IntentMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.profile.ProfileSetup
import ch.sdp.vibester.scoreboard.ScoreBoardActivity
import org.junit.After
import org.junit.Before
Expand Down Expand Up @@ -49,10 +50,15 @@ class MainActivityTest {
intended(hasComponent(ScoreBoardActivity::class.qualifiedName))
}

@Test
fun profileTest() {
onView(withId(R.id.profileButton)).perform(click())
intended(hasComponent(ProfileSetup::class.qualifiedName))
}

@Test
fun checkIntentOnWelcome(){ //FILLER TESTING
onView(withId(R.id.placeholder_welcome)).perform(click())
intended(hasComponent(WelcomeScreen::class.qualifiedName))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ch.sdp.vibester.profile

import android.content.Intent
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import ch.sdp.vibester.GreetingActivity
import ch.sdp.vibester.R
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.io.Serializable


@RunWith(AndroidJUnit4::class)
class ProfileSetupTest {

@Test
fun checkProfileData() {
val inputProfile = UserProfile("user0", "username0","bit.ly/3IUnyAF", 5, 8, 34, 2)
val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileSetup::class.java)
intent.putExtra("userProfile", inputProfile)
val scn: ActivityScenario<ProfileSetup> = ActivityScenario.launch(intent)
onView(withId(R.id.handle)).check(matches(withText(inputProfile.handle)))
onView(withId(R.id.username)).check(matches(withText(inputProfile.username)))
onView(withId(R.id.correctSongs)).check(matches(withText(inputProfile.correctSongs.toString())))
onView(withId(R.id.totalGames)).check(matches(withText(inputProfile.totalGames.toString())))
onView(withId(R.id.ranking)).check(matches(withText(inputProfile.ranking.toString())))
}

@Test
fun checkProfileLayout() {
val inputProfile = UserProfile("user0", "username0","bit.ly/3IUnyAF", 5, 8, 34, 2)
val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileSetup::class.java)
intent.putExtra("userProfile", inputProfile)
val scn: ActivityScenario<ProfileSetup> = ActivityScenario.launch(intent)
onView(withId(R.id.profileStatistics)).check(matches(isDisplayed()))
onView(withId(R.id.handle)).check(matches(isDisplayed()))
onView(withId(R.id.username)).check(matches(isDisplayed()))
// onView(withId(R.id.avatar)).check(matches(isDisplayed()))
}

}
73 changes: 38 additions & 35 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.sdp.vibester">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity
android:name=".GameSetupScreen"
android:exported="false" />
<activity android:name=".scoreboard.ScoreBoardActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".WelcomeScreen"
android:exported="false" />
<activity
android:name=".GreetingActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.sdp.vibester">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity
android:name=".GameSetupScreen"
android:exported="false" />
<activity android:name=".scoreboard.ScoreBoardActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".profile.ProfileSetup"
android:exported="false" />
<activity
android:name=".WelcomeScreen"
android:exported="false" />
<activity
android:name=".GreetingActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
23 changes: 20 additions & 3 deletions app/src/main/java/ch/sdp/vibester/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import android.view.View
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import ch.sdp.vibester.profile.ProfileDataProvider
import ch.sdp.vibester.scoreboard.ScoreBoardActivity
import ch.sdp.vibester.profile.ProfileSetup
import ch.sdp.vibester.profile.UserProfile
import java.io.Serializable

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -16,11 +20,24 @@ class MainActivity : AppCompatActivity() {
val txtInput = findViewById<EditText>(R.id.mainNameInput)

val btnGreeting = findViewById<Button>(R.id.mainButton)

val greetingIntent = Intent(this, GreetingActivity::class.java)

btnGreeting.setOnClickListener {
greetingIntent.putExtra("name", txtInput.text.toString())
startActivity(greetingIntent)
btnGreeting.setOnClickListener {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the indentations be too much here?

greetingIntent.putExtra("name", txtInput.text.toString())
startActivity(greetingIntent)
}


val btnProfile = findViewById<Button>(R.id.profileButton)
val profileIntent = Intent(this, ProfileSetup::class.java)

btnProfile.setOnClickListener{
val userID = (0..5).random().toString()
val dataProvider = userID.let { ProfileDataProvider(it) }
val user: UserProfile = dataProvider.getUserProfileData()
profileIntent.putExtra("userProfile", user)
startActivity(profileIntent)
}

// button to scoreboard
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/ch/sdp/vibester/profile/Helper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ch.sdp.vibester.profile

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.widget.ImageView
import com.bumptech.glide.Glide
/**
* Helper function to load image from given url into profile avatar
*/
fun ImageView.loadImg(url: String) {
Glide.with(context).load(url)
.fitCenter()
.circleCrop()
.error(ColorDrawable(Color.RED))
.placeholder(ColorDrawable(Color.GRAY))
.into(this)
}
67 changes: 67 additions & 0 deletions app/src/main/java/ch/sdp/vibester/profile/ProfileDataProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ch.sdp.vibester.profile

class ProfileDataProvider(userID: String, users: List<UserProfile> = emptyList(), scoreboard: List<Int> = emptyList()) {
private lateinit var user: UserProfile
private val userID:Int = userID.toInt()
private lateinit var users: List<UserProfile>
private lateinit var scoreboard: List<Int>

init {
setUsers(users)
setScoreboard(scoreboard)
}

/**
* Hardcoded list will be changed to Firebase.
* Used for testing.
*/
private fun setScoreboard(scoreboard: List<Int>){
if(scoreboard.isEmpty()){
this.scoreboard = listOf(6,3,4,2,1,5)
}
else{this.scoreboard = scoreboard}
}

/**
* Hardcoded list will be changed to Firebase.
* Used for testing.
*/
private fun setUsers(users: List<UserProfile>){
if(users.isEmpty()){
this.users = listOf(
UserProfile("@lisa", "Lalisa Bon","bit.ly/3IUnyAF", 12, 8, 29),
UserProfile("@flowergirl", "Viktor Gerard", "bit.ly/3CxcRBR", 3, 15, 324),
UserProfile("@smartie", "Big Mountain", "bit.ly/3IZl6Ji", 115, 22, 62),
UserProfile("@swanlake", "Sleeping Beauty", "bit.ly/3tO0k8W", 32, 12, 71),
UserProfile("@lateevening", "Sleepy Bear", "bit.ly/3IUnyAF", 98, 6, 211),
UserProfile("@swenguy", "Code nonstop", "bit.ly/3sZhbXm", 64, 14, 111)
)
}
else{this.users = users}
}


/**
* Combine user data profile and user ranking for profile.
*/
fun getUserProfileData(): UserProfile{
user = getUserData()
user.ranking = getUserRanking()
return user
}

/**
* Retrieve profile data of user.
*/
private fun getUserData():UserProfile {
return users[userID]
}

/**
* Retrieve ranking from the scoreboard.
*/
private fun getUserRanking(): Int {
return scoreboard[userID]
}

}
30 changes: 30 additions & 0 deletions app/src/main/java/ch/sdp/vibester/profile/ProfileSetup.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ch.sdp.vibester.profile

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import ch.sdp.vibester.R
const val EXTRA_ID = "userProfile"

class ProfileSetup: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_profile)
val bundle = intent.extras;
val user: UserProfile = bundle?.getSerializable(EXTRA_ID) as UserProfile
setupProfile(user)
}

fun setupProfile(user: UserProfile){
findViewById<TextView>(R.id.handle).text = user.handle
findViewById<TextView>(R.id.username).text = user.username
findViewById<TextView>(R.id.totalGames).text = user.totalGames.toString()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

findViewById<TextView>(R.id.correctSongs).text = user.correctSongs.toString()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

findViewById<TextView>(R.id.bestScore).text = user.bestScore.toString()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

findViewById<TextView>(R.id.ranking).text = user.ranking.toString()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

/* TODO: add functionality to display the image
findViewById<ImageView>(R.id.avatar).loadImg(user.image)*/
}
}

12 changes: 12 additions & 0 deletions app/src/main/java/ch/sdp/vibester/profile/UserProfile.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ch.sdp.vibester.profile
//import kotlinx.serialization.Serializable
import java.io.Serializable

data class UserProfile (
var handle: String = "",
var username: String = "",
var image: String = "",
var totalGames: Int = 0,
var bestScore: Int = 0,
var correctSongs: Int = 0,
var ranking: Int = 0): Serializable{}
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/table_shape.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/purple_200"/>
<corners android:radius="70px"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
Loading