This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Upgrade of Profile_Activity Layout + image in search user activity #301
Merged
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
61fb303
refactor profile activity xml
MaximeZmt c152187
upload final version
MaximeZmt 6ebbc2b
Merge branch 'main' into maximezmt/updateUI
MaximeZmt 2c15061
upload final version 2
MaximeZmt df322bd
update profileActivity
MaximeZmt 4bf6d0d
small update
MaximeZmt 798c235
update search user
MaximeZmt debc08f
update test
MaximeZmt 200bd88
update user profile adapter test
MaximeZmt 34eb85f
test updated
MaximeZmt bb10773
awful conflict merging ;(
MaximeZmt de56a4f
first test patch
MaximeZmt 84e26c7
first test patch 2
MaximeZmt 960e448
first test patch 3
MaximeZmt da08fed
first test patch 4
MaximeZmt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,13 @@ package ch.sdp.vibester.activity | |
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.core.widget.ImageViewCompat | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.action.ViewActions.scrollTo | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.intent.Intents | ||
import androidx.test.espresso.intent.matcher.IntentMatchers | ||
|
@@ -24,6 +26,7 @@ import dagger.hilt.android.testing.HiltAndroidRule | |
import dagger.hilt.android.testing.HiltAndroidTest | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import net.glxn.qrgen.core.scheme.Url | ||
import org.hamcrest.CoreMatchers.not | ||
import org.junit.After | ||
import org.junit.Before | ||
|
@@ -154,7 +157,7 @@ class ProfileActivityTest { | |
createMockImageGetter() | ||
|
||
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent) | ||
onView(withId(R.id.profile_returnToMain)).perform(click()) | ||
onView(withId(R.id.profile_returnToMain)).perform(scrollTo(), click()) | ||
Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name)) | ||
} | ||
// FIXME failing test | ||
|
@@ -237,8 +240,8 @@ class ProfileActivityTest { | |
createMockImageGetter() | ||
|
||
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent) | ||
onView(withId(R.id.editUser)).perform(click()) | ||
onView(withText("Cancel")).perform(click()) | ||
onView(withId(R.id.editUser)).perform(scrollTo(), click()) | ||
onView(withText("Cancel")).perform(scrollTo(), click()) | ||
|
||
onView(withId(R.id.username)).check(matches(withText("Lalisa Bon"))) | ||
} | ||
|
@@ -276,9 +279,32 @@ class ProfileActivityTest { | |
createMockImageGetter() | ||
|
||
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent) | ||
onView(withId(R.id.showQRCode)).perform(click()) | ||
|
||
onView(withId(R.id.showQRCode)).perform(click()) | ||
onView(withId(R.id.qrCode)).check(matches(isDisplayed())) | ||
|
||
onView(withId(R.id.qrCode_returnToProfile)).perform(click()) | ||
onView(withId(R.id.myCardView)).check(matches(isDisplayed())) | ||
|
||
onView(withId(R.id.logout)).perform(scrollTo(), click()) | ||
onView(withId(R.id.fragment)).check(matches(isDisplayed())) | ||
} | ||
|
||
@Test | ||
fun checkChangeImage() { | ||
val inputProfile = User( "Lalisa Bon", R.string.test_profile_image.toString(), "[email protected]", 12, 8,"VvPB47tQCLdjz3YebilS6h5EXdJ3") | ||
val ctx = ApplicationProvider.getApplicationContext() as Context | ||
val intent = Intent(ctx, ProfileActivity::class.java) | ||
|
||
createMockDataGetter(inputProfile) | ||
createMockAuthenticator() | ||
createMockImageGetter() | ||
|
||
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent) | ||
|
||
onView(withId(R.id.myCardView)).perform(click()) | ||
onView(withText("NO")).perform(click()) | ||
onView(withId(R.id.myCardView)).check(matches(isDisplayed())) | ||
} | ||
// FIXME failing test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package ch.sdp.vibester.profile | |
import androidx.recyclerview.widget.RecyclerView | ||
import ch.sdp.vibester.auth.FireBaseAuthenticator | ||
import ch.sdp.vibester.database.DataGetter | ||
import ch.sdp.vibester.database.ImageGetter | ||
import ch.sdp.vibester.user.User | ||
import ch.sdp.vibester.user.UserProfileAdapter | ||
import org.hamcrest.CoreMatchers | ||
|
@@ -17,7 +18,7 @@ class UserProfileAdapterTest { | |
val user2 = User("test2", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]") | ||
val users: MutableList<User> = arrayListOf() | ||
users.addAll(listOf(user1, user2)) | ||
val userProfileViewHolder: RecyclerView.Adapter<UserProfileAdapter.UserProfileViewHolder> = UserProfileAdapter(users, FireBaseAuthenticator(), DataGetter()) | ||
val userProfileViewHolder: RecyclerView.Adapter<UserProfileAdapter.UserProfileViewHolder> = UserProfileAdapter(users, FireBaseAuthenticator(), DataGetter(), ImageGetter()) | ||
MatcherAssert.assertThat(userProfileViewHolder.itemCount, CoreMatchers.equalTo(2)) | ||
} | ||
|
||
|
@@ -27,7 +28,7 @@ class UserProfileAdapterTest { | |
val user2 = User("test2", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]") | ||
val users: MutableList<User> = arrayListOf() | ||
users.addAll(listOf(user1, user2)) | ||
val userProfileViewHolder: RecyclerView.Adapter<UserProfileAdapter.UserProfileViewHolder> = UserProfileAdapter(users, FireBaseAuthenticator(), DataGetter()) | ||
val userProfileViewHolder: RecyclerView.Adapter<UserProfileAdapter.UserProfileViewHolder> = UserProfileAdapter(users, FireBaseAuthenticator(), DataGetter(), ImageGetter()) | ||
val defaultType = 0 | ||
MatcherAssert.assertThat( | ||
userProfileViewHolder.getItemViewType(0), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import android.view.Window | |
import android.widget.* | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.cardview.widget.CardView | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import ch.sdp.vibester.R | ||
import ch.sdp.vibester.api.BitmapGetterApi | ||
|
@@ -89,6 +90,9 @@ class ProfileActivity : AppCompatActivity() { | |
findViewById<ImageView>(R.id.avatar).setOnClickListener { | ||
showGeneralDialog( "Do you want to change your profile picture?", false) | ||
} | ||
findViewById<CardView>(R.id.myCardView).setOnClickListener { | ||
showGeneralDialog( "Do you want to change your profile picture?", false) | ||
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. can we test this? |
||
} | ||
} | ||
/** | ||
* A function that updates the image in the database. | ||
|
@@ -149,7 +153,8 @@ class ProfileActivity : AppCompatActivity() { | |
private fun setShowQrCodeBtnListener() { | ||
findViewById<ImageView>(R.id.showQRCode).setOnClickListener { | ||
setLayoutVisibility(findViewById<ConstraintLayout>(R.id.QrCodePage), true) | ||
setLayoutVisibility(findViewById<RelativeLayout>(R.id.profileContent), false) | ||
setLayoutVisibility(findViewById<ScrollView>(R.id.profileContent), false) | ||
setLayoutVisibility(findViewById<FloatingActionButton>(R.id.profile_returnToMain), false) | ||
} | ||
} | ||
|
||
|
@@ -159,7 +164,8 @@ class ProfileActivity : AppCompatActivity() { | |
private fun setQrCodeToProfileBtnListener() { | ||
findViewById<FloatingActionButton>(R.id.qrCode_returnToProfile).setOnClickListener { | ||
setLayoutVisibility(findViewById<ConstraintLayout>(R.id.QrCodePage), false) | ||
setLayoutVisibility(findViewById<RelativeLayout>(R.id.profileContent), true) | ||
setLayoutVisibility(findViewById<ScrollView>(R.id.profileContent), true) | ||
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. can we test this? |
||
setLayoutVisibility(findViewById<FloatingActionButton>(R.id.profile_returnToMain), true) | ||
} | ||
} | ||
|
||
|
@@ -271,7 +277,7 @@ class ProfileActivity : AppCompatActivity() { | |
* A function that downloads an image and sets it. | ||
* @param imageURI URI of the image | ||
*/ | ||
private fun setImage(imageURI: Uri) { | ||
fun setImage(imageURI: Uri) { | ||
CoroutineScope(Dispatchers.Main).launch { | ||
val task = async(Dispatchers.IO) { | ||
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. Identical blocks of code found in 2 locations. Consider refactoring. |
||
try { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.launch | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Inject | ||
|
||
|
||
/** | ||
|
@@ -29,11 +30,13 @@ class UserProfileAdapter constructor( | |
val users: MutableList<User>, | ||
private val authenticator: FireBaseAuthenticator, | ||
val dataGetter: DataGetter, | ||
val imageGetter: ImageGetter | ||
): | ||
RecyclerView.Adapter<UserProfileAdapter.UserProfileViewHolder>() { | ||
|
||
private val currentUser = authenticator.getCurrUser() | ||
private var userFriends: Array<String> = arrayOf() | ||
private val imageSize = 100 | ||
|
||
init{ | ||
if (currentUser != null) { dataGetter.getUserData(currentUser.uid, this::setFriends) } | ||
|
@@ -84,7 +87,9 @@ class UserProfileAdapter constructor( | |
*/ | ||
fun bind(user: User) { | ||
itemView.findViewById<TextView>(R.id.search_user_username).text = user.username | ||
itemView.findViewById<ImageView>(R.id.profile_image).loadImg(user.image) | ||
|
||
imageGetter.fetchImage("profileImg/${user.uid}", this::setImage) | ||
//itemView.findViewById<ImageView>(R.id.profile_image).loadImg(user.image) | ||
val addFriendBtn = itemView.findViewById<Button>(R.id.addFriendBtn) | ||
|
||
if(userFriends.isNotEmpty() && user.uid in userFriends){ | ||
|
@@ -100,6 +105,27 @@ class UserProfileAdapter constructor( | |
} | ||
} | ||
|
||
|
||
private fun setImage(imageURI: Uri) { | ||
CoroutineScope(Dispatchers.Main).launch { | ||
val task = async(Dispatchers.IO) { | ||
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. Identical blocks of code found in 2 locations. Consider refactoring. |
||
try { | ||
val bit = BitmapGetterApi.download(imageURI.toString()) | ||
bit.get(10, TimeUnit.SECONDS) | ||
} catch (e: Exception){ | ||
null | ||
} | ||
} | ||
val bm = task.await() | ||
|
||
if (bm != null) { | ||
val avatar = itemView.findViewById<ImageView>(R.id.profile_image) | ||
avatar.setImageBitmap(Bitmap.createScaledBitmap(bm, imageSize, imageSize, false)) | ||
} | ||
} | ||
} | ||
|
||
|
||
private fun changeBtnToImage(){ | ||
itemView.findViewById<Button>(R.id.addFriendBtn).visibility = View.INVISIBLE | ||
itemView.findViewById<ImageView>(R.id.addedFriendIcon).visibility = View.VISIBLE | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Similar blocks of code found in 2 locations. Consider refactoring.