From d58c8163ef91839eb47ddf213971091051061b05 Mon Sep 17 00:00:00 2001 From: Shubhadeep Karmakar <99060332+ShubhadeepKarmakar@users.noreply.github.com> Date: Thu, 10 Aug 2023 08:43:36 +0530 Subject: [PATCH] Fix #4803 Failed to add Admin (or non-admin) Profile Picture. (#5118) ## Explanation - Fix #4803 val galleryIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) The above code (previous) is the explicit way to get images from gallery but is not working here. But the updated code below is less explicit but works fine, val galleryIntent = Intent(Intent.ACTION_GET_CONTENT).apply { type = "image/*" } ## Essential Checklist - [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".) - [x] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation. - [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide). - [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)). - [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop". - [x] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)). ## Screen Recording https://github.com/oppia/oppia-android/assets/99060332/b6379a06-e3e6-41eb-9bed-de6271dcd346 --------- Co-authored-by: Adhiambo Peres <59600948+adhiamboperes@users.noreply.github.com> --- .../ProfileProgressActivityPresenter.kt | 9 +++---- .../ProfileProgressFragmentTest.kt | 26 ++++++++++++------- 2 files changed, 20 insertions(+), 15 deletions(-) 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)) } }