-
Notifications
You must be signed in to change notification settings - Fork 0
kamila/user_profile #51
Changes from all commits
217d1ee
57063e9
7e72d82
8152aff
b4304d0
23f7a4b
58771e4
7b0caa2
9dc3a2c
0c58e9a
83e8501
105008f
5c98286
58908bc
5a8e10f
7640664
5967ac3
a694ddd
f7ca742
9656e42
53e94ec
d3c2bb6
e4ee052
4373d3e
fca142b
eadf01b
58e7850
374ca59
e2b6707
fc2f215
7213c32
4bd4966
845cd8d
cf4d198
3024d3a
51d3685
6c05f11
87644b0
0e46952
d53c95b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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())) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,42 @@ | ||
<?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=".MusicTemporary" | ||
android:exported="false" /> | ||
<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=".profile.ProfileSetup" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MusicTemporary" | ||
android:exported="false" /> | ||
<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> | ||
|
||
</manifest> |
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) | ||
} |
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] | ||
} | ||
|
||
} |
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)*/ | ||
} | ||
} | ||
|
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{} |
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> |
There was a problem hiding this comment.
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?