Skip to content

Commit

Permalink
Fix #4803 Failed to add Admin (or non-admin) Profile Picture. (#5118)
Browse files Browse the repository at this point in the history
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## 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
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [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 <[email protected]>
  • Loading branch information
ShubhadeepKarmakar and adhiamboperes authored Aug 10, 2023
1 parent c225110 commit d58c816
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
}
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -342,8 +341,8 @@ class ProfileProgressFragmentTest {
@Test
fun testProfileProgressFragment_imageSelectAvatar_checkGalleryIntent() {
val expectedIntent: Matcher<Intent> = 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)
Expand All @@ -360,24 +359,31 @@ class ProfileProgressFragmentTest {
@Test
fun testProfileProgressFragment_imageSelectAvatar_configChange_checkGalleryIntent() {
val expectedIntent: Matcher<Intent> = 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<ProfileProgressActivity>(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<ProfileProgressActivity>(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))
}
}
Expand Down

0 comments on commit d58c816

Please sign in to comment.