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

Laurislopata/edit profile #82

Merged
merged 11 commits into from
Mar 17, 2022
Merged
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.firebase:firebase-auth-ktx:21.0.1'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20180813'
testImplementation 'org.robolectric:robolectric:4.6'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@ 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.action.ViewActions
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)
Expand Down Expand Up @@ -49,5 +40,59 @@ class ProfileSetupTest {
onView(withId(R.id.username)).check(matches(isDisplayed()))
// onView(withId(R.id.avatar)).check(matches(isDisplayed()))
}

@Test
fun checkEditProfile() {
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)

val newUsername = "newUser"
onView(withId(R.id.editUser)).perform(ViewActions.click())
onView(withId(0)).perform(ViewActions.typeText(newUsername), ViewActions.closeSoftKeyboard())
onView(withText("OK")).perform(ViewActions.click())
onView(withId(R.id.username)).check(matches(withText(newUsername)))

}

@Test
fun checkEditProfileClickCancel() {
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.editUser)).perform(ViewActions.click())
onView(withText("Cancel")).perform(ViewActions.click())
onView(withId(R.id.username)).check(matches(withText("username0")))
}

@Test
fun checkEditHandle() {
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)

val newUserHandle = "newHandle"
onView(withId(R.id.editHandle)).perform(ViewActions.click())
onView(withId(0)).perform(ViewActions.typeText(newUserHandle), ViewActions.closeSoftKeyboard())
onView(withText("OK")).perform(ViewActions.click())
onView(withId(R.id.handle)).check(matches(withText("newHandle")))

}

@Test
fun checkEditHandleClickCancel() {
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.editHandle)).perform(ViewActions.click())
onView(withText("Cancel")).perform(ViewActions.click())
onView(withId(R.id.handle)).check(matches(withText("user0")))
}

}
100 changes: 50 additions & 50 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
<?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"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<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="ch.sdp.vibester.GamescreenActivity"
android:exported="false" />
<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=".Register"
android:exported="true" />
<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" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<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=".GamescreenActivity"
android:exported="false" />
<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=".Register"
android:exported="true" />
<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
Expand Up @@ -2,7 +2,7 @@ package ch.sdp.vibester.profile

class ProfileDataProvider(userID: String, users: List<UserProfile> = emptyList(), scoreboard: List<Int> = emptyList()) {
Copy link
Owner

Choose a reason for hiding this comment

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

doc ?

private lateinit var user: UserProfile
private val userID:Int = userID.toInt()
private val userID: Int = userID.toInt()
private lateinit var users: List<UserProfile>
private lateinit var scoreboard: List<Int>

Expand Down Expand Up @@ -53,7 +53,7 @@ class ProfileDataProvider(userID: String, users: List<UserProfile> = emptyList()
/**
* Retrieve profile data of user.
*/
private fun getUserData():UserProfile {
private fun getUserData(): UserProfile {
return users[userID]
}

Expand Down
37 changes: 35 additions & 2 deletions app/src/main/java/ch/sdp/vibester/profile/ProfileSetup.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package ch.sdp.vibester.profile

import android.content.DialogInterface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import android.text.InputType
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import ch.sdp.vibester.R
const val EXTRA_ID = "userProfile"

Expand All @@ -14,9 +18,38 @@ class ProfileSetup: AppCompatActivity() {
val bundle = intent.extras;
val user: UserProfile = bundle?.getSerializable(EXTRA_ID) as UserProfile
setupProfile(user)

val editUsername = findViewById<Button>(R.id.editUser)
val editHandle = findViewById<Button>(R.id.editHandle)

editUsername.setOnClickListener {
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 2 locations. Consider refactoring.

showDialog("Change username", "Enter new username", 0, R.id.username)
}

editHandle.setOnClickListener {
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 2 locations. Consider refactoring.

showDialog("Change handle", "Enter new handle", 0, R.id.handle)
}
}

private fun showDialog(title: String, hint: String, id: Int, textId: Int) {
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder.setTitle(title)

val input = EditText(this)
input.hint = hint
input.inputType = InputType.TYPE_CLASS_TEXT
input.id = id

builder.setView(input)
builder.setPositiveButton("OK", DialogInterface.OnClickListener { _, _ ->
findViewById<TextView>(textId).text = input.text.toString()
})
builder.setNegativeButton("Cancel") { dialog, _ -> dialog.cancel() }
builder.show()
}

fun setupProfile(user: UserProfile){

private 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()
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
android:textColor="#000"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/username"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -42,11 +43,13 @@
android:id="@+id/username"
android:layout_width="200dp"
android:layout_height="30dp"
android:layout_marginBottom="109dp"
android:fontFamily="monospace"
android:textAlignment="center"
android:textColor="#000"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/profileStatistics"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
Expand Down Expand Up @@ -161,4 +164,30 @@

</TableLayout>

<Button
android:id="@+id/editUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_marginBottom="27dp"
android:text="@string/editUsername"
app:layout_constraintBottom_toTopOf="@+id/profileStatistics"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.937"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/username"
app:layout_constraintVertical_bias="0.3" />

<Button
android:id="@+id/editHandle"
android:layout_width="148dp"
android:layout_height="43dp"
android:layout_marginStart="67dp"
android:layout_marginTop="22dp"
android:layout_marginBottom="35dp"
android:text="@string/editHandle"
app:layout_constraintBottom_toTopOf="@+id/profileStatistics"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/username" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<string name="createAcc">Create Account</string>
<string name="logIn">Log in</string>
<string name="logInGoogle">Log in with Google</string>
<string name="editUsername">Edit Username</string>
<string name="editHandle">Edit Handle</string>

<string-array name="nb_players">
<item>One</item>
Expand Down