diff --git a/app/src/main/java/org/oppia/android/app/profileprogress/ProfileProgressActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/profileprogress/ProfileProgressActivityPresenter.kt index fb77053a250..562e38f3d9f 100644 --- a/app/src/main/java/org/oppia/android/app/profileprogress/ProfileProgressActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/profileprogress/ProfileProgressActivityPresenter.kt @@ -1,7 +1,6 @@ package org.oppia.android.app.profileprogress import android.content.Intent -import android.provider.MediaStore import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar @@ -37,9 +36,9 @@ class ProfileProgressActivityPresenter @Inject constructor( R.id.profile_progress_activity_toolbar ) as Toolbar activity.setSupportActionBar(toolbar) - activity.supportActionBar!!.setTitle(R.string.profile) - activity.supportActionBar!!.setDisplayShowHomeEnabled(true) - activity.supportActionBar!!.setDisplayHomeAsUpEnabled(true) + (activity.supportActionBar ?: return).setTitle(R.string.profile) + (activity.supportActionBar ?: return).setDisplayShowHomeEnabled(true) + (activity.supportActionBar ?: return).setDisplayHomeAsUpEnabled(true) toolbar.setNavigationOnClickListener { activity.finish() } @@ -52,7 +51,7 @@ class ProfileProgressActivityPresenter @Inject constructor( } fun openGalleryIntent() { - val galleryIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) + val galleryIntent = Intent(Intent.ACTION_GET_CONTENT).apply { type = "image/*" } activity.startActivityForResult(galleryIntent, GALLERY_INTENT_RESULT_CODE) } diff --git a/app/src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt index 15d869c6bcc..9568acdecff 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt @@ -8,7 +8,6 @@ import android.content.Context import android.content.Intent import android.content.res.Resources import android.net.Uri -import android.provider.MediaStore import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.widget.ConstraintLayout @@ -24,8 +23,8 @@ import androidx.test.espresso.intent.Intents.intended import androidx.test.espresso.intent.Intents.intending import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent -import androidx.test.espresso.intent.matcher.IntentMatchers.hasData import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra +import androidx.test.espresso.intent.matcher.IntentMatchers.hasType import androidx.test.espresso.matcher.RootMatchers.isDialog import androidx.test.espresso.matcher.ViewMatchers.isClickable import androidx.test.espresso.matcher.ViewMatchers.isDisplayed @@ -342,8 +341,8 @@ class ProfileProgressFragmentTest { @Test fun testProfileProgressFragment_imageSelectAvatar_checkGalleryIntent() { val expectedIntent: Matcher = allOf( - hasAction(Intent.ACTION_PICK), - hasData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI) + hasAction(Intent.ACTION_GET_CONTENT), + hasType("image/*") ) val activityResult = createGalleryPickActivityResultStub() intending(expectedIntent).respondWith(activityResult) @@ -360,24 +359,31 @@ class ProfileProgressFragmentTest { @Test fun testProfileProgressFragment_imageSelectAvatar_configChange_checkGalleryIntent() { val expectedIntent: Matcher = allOf( - hasAction(Intent.ACTION_PICK), - hasData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI) + hasAction(Intent.ACTION_GET_CONTENT), + hasType("image/*") ) val activityResult = createGalleryPickActivityResultStub() intending(expectedIntent).respondWith(activityResult) launch(createProfileProgressActivityIntent(internalProfileId)).use { + onView(isRoot()).perform(orientationLandscape()) testCoroutineDispatchers.runCurrent() clickProfileProgressItem(itemPosition = 0, targetViewId = R.id.profile_edit_image) verifyTextInDialog(context.getString(R.string.profile_progress_edit_dialog_title)) onView(withText(R.string.profile_picture_edit_alert_dialog_choose_from_library)) .perform(click()) - testCoroutineDispatchers.runCurrent() intended(expectedIntent) - onView(isRoot()).perform(orientationLandscape()) + } + } + + @Test + fun testFragment_imageSelectAvatar_configChange_profilePictureDialogIsVisible() { + launch(createProfileProgressActivityIntent(internalProfileId)).use { testCoroutineDispatchers.runCurrent() - intended(expectedIntent) clickProfileProgressItem(itemPosition = 0, targetViewId = R.id.profile_edit_image) - // The dialog should still be open after a configuration change. + verifyTextInDialog(context.getString(R.string.profile_progress_edit_dialog_title)) + testCoroutineDispatchers.runCurrent() + onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() verifyTextInDialog(context.getString(R.string.profile_progress_edit_dialog_title)) } }