diff --git a/app/build.gradle b/app/build.gradle index e4bc9985d..b065e67ab 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -101,7 +101,7 @@ dependencies { implementation 'de.hdodenhof:circleimageview:3.1.0' implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.appcompat:appcompat:1.4.1' - implementation 'com.google.android.gms:play-services-auth:20.1.0' + implementation 'com.google.android.gms:play-services-auth:20.2.0' implementation ('com.github.bumptech.glide:glide:4.13.0', { exclude group: 'com.android.support' }) @@ -116,6 +116,9 @@ dependencies { testImplementation "io.mockk:mockk:1.12.3" androidTestImplementation "io.mockk:mockk-android:1.12.3" + implementation 'com.journeyapps:zxing-android-embedded:4.3.0' + implementation 'com.google.zxing:core:3.4.1' + implementation 'com.github.kenglxn.QRGen:android:2.6.0' } tasks.withType(Test) { diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt index e7a6d8c7c..b60ccb3cf 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt @@ -10,8 +10,7 @@ import androidx.test.espresso.action.ViewActions.click 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.withId -import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.espresso.matcher.ViewMatchers.* import androidx.test.ext.junit.runners.AndroidJUnit4 import ch.sdp.vibester.R import ch.sdp.vibester.TestMode @@ -22,6 +21,7 @@ import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest import io.mockk.every import io.mockk.mockk +import org.hamcrest.CoreMatchers.not import org.junit.After import org.junit.Before import org.junit.Rule @@ -77,7 +77,7 @@ class ProfileActivityTest { } @Test - fun clickBackToMain(){ + fun clickBackToMain() { val ctx = ApplicationProvider.getApplicationContext() as Context val intent = Intent(ctx, ProfileActivity::class.java) intent.putExtra("isUnitTest", true) @@ -88,6 +88,33 @@ class ProfileActivityTest { Intents.intended(IntentMatchers.hasComponent(WelcomeActivity::class.java.name)) } + @Test + fun shouldShowQrCode() { + val ctx = ApplicationProvider.getApplicationContext() as Context + val intent = Intent(ctx, ProfileActivity::class.java) + intent.putExtra("isUnitTest", true) + + val scn: ActivityScenario = ActivityScenario.launch(intent) + + onView(withId(R.id.showQRCode)).perform(click()) + onView(withId(R.id.QrCodePage)).check(matches(isDisplayed())) + onView(withId(R.id.profileContent)).check(matches(not(isDisplayed()))) + onView(withId(R.id.qrCode)).check(matches(isDisplayed())) + } + + @Test + fun clickBackToProfile() { + val ctx = ApplicationProvider.getApplicationContext() as Context + val intent = Intent(ctx, ProfileActivity::class.java) + intent.putExtra("isUnitTest", true) + + val scn: ActivityScenario = ActivityScenario.launch(intent) + onView(withId(R.id.showQRCode)).perform(click()) + onView(withId(R.id.qrCode_returnToProfile)).perform(click()) + onView(withId(R.id.QrCodePage)).check(matches(not(isDisplayed()))) + onView(withId(R.id.profileContent)).check(matches(isDisplayed())) + } + @Test fun checkEditProfile() { @@ -102,14 +129,13 @@ class ProfileActivityTest { val scn: ActivityScenario = ActivityScenario.launch(intent) val newUsername = "Lalisa Bon idomesniu" - onView(withId(R.id.editUser)).perform(ViewActions.click()) + onView(withId(R.id.editUser)).perform(click()) onView(withId(0)).perform( ViewActions.typeText(newUsername), ViewActions.closeSoftKeyboard() ) - onView(withText("OK")).perform(ViewActions.click()) + onView(withText("OK")).perform(click()) onView(withId(R.id.username)).check(matches(withText(newUsername))) - } @Test @@ -124,9 +150,24 @@ class ProfileActivityTest { val scn: ActivityScenario = ActivityScenario.launch(intent) - onView(withId(R.id.editUser)).perform(ViewActions.click()) - onView(withText("Cancel")).perform(ViewActions.click()) + onView(withId(R.id.editUser)).perform(click()) + onView(withText("Cancel")).perform(click()) onView(withId(R.id.username)).check(matches(withText("Lalisa Bon"))) } + @Test + fun checkQrCodeGenerator() { + val inputProfile = User( "Lalisa Bon","bit.ly/3IUnyAF", "lisa@test.com", 12, 8, 29, 0, "VvPB47tQCLdjz3YebilS6h5EXdJ3") + val ctx = ApplicationProvider.getApplicationContext() as Context + val intent = Intent(ctx, ProfileActivity::class.java) + intent.putExtra("isUnitTest", true) + intent.putExtra("userTestProfile", inputProfile) + + createMockInvocation(inputProfile) + + val scn: ActivityScenario = ActivityScenario.launch(intent) + onView(withId(R.id.showQRCode)).perform(click()) + onView(withId(R.id.qrCode)).check(matches(isDisplayed())) + } + } diff --git a/app/src/main/assets/logo.png b/app/src/main/assets/logo.png new file mode 100644 index 000000000..8cb7069c7 Binary files /dev/null and b/app/src/main/assets/logo.png differ diff --git a/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt index 303b81256..42f3a2d6f 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt @@ -1,9 +1,11 @@ package ch.sdp.vibester.activity -import android.graphics.Bitmap +import android.graphics.* import android.os.Bundle import android.text.InputType import android.util.Log +import android.view.View.GONE +import android.view.View.VISIBLE import android.view.Window import android.widget.Button import android.widget.EditText @@ -11,6 +13,7 @@ import android.widget.ImageView import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.constraintlayout.widget.ConstraintLayout import ch.sdp.vibester.R import ch.sdp.vibester.api.BitmapGetterApi import ch.sdp.vibester.auth.FireBaseAuthenticator @@ -19,11 +22,16 @@ import ch.sdp.vibester.helper.IntentSwitcher import ch.sdp.vibester.user.User import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.firebase.auth.FirebaseAuth +import com.google.zxing.BarcodeFormat +import com.google.zxing.EncodeHintType +import com.google.zxing.qrcode.QRCodeWriter +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.launch +import net.glxn.qrgen.android.MatrixToImageWriter import java.util.concurrent.TimeUnit import javax.inject.Inject @@ -32,7 +40,6 @@ class ProfileActivity : AppCompatActivity() { @Inject lateinit var dataGetter: DataGetter - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -41,41 +48,65 @@ class ProfileActivity : AppCompatActivity() { setContentView(R.layout.activity_profile) - val editUsername = findViewById