-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support taking a new photo when prompted to upload an image (#3954)
<!-- Note: This checklist is a reminder of our shared engineering expectations. The items in Bold are required If your PR involves UI changes: 1. Upload screenshots or screencasts that illustrate the changes before / after 2. Add them under the UI changes section (feel free to add more columns if needed) If your PR does not involve UI changes, you can remove the **UI changes** section At a minimum, make sure your changes are tested in API 23 and one of the more recent API levels available. --> Task/Issue URL: https://app.asana.com/0/488551667048375/1206005059663926/f ### Description When encountering webpages which allow users to upload an image, currently the only option is to choose an existing image from the gallery. With this PR, users will have the ability to choose between uploading an existing image from their gallery or taking a new photo from the camera and uploading that. Translations will follow separately. ### Steps to test this PR #### Happy path, camera - [x] Visit https://cdrussell.w3spaces.com and click the **Choose File** button - [x] Choose **Take Photo** - [x] Grant camera permission when prompted - [x] Take a photo - [x] Verify it appears on the demo webpage #### Happy path, gallery - [x] Visit https://cdrussell.w3spaces.com and click the **Choose File** button - [x] Choose **Photo Library** - [x] Verify you see the standard file chooser as you would just now in `develop` and that you can select an image (nothing has changed about this flow) #### Alt path, cancel image capture - [x] Visit https://cdrussell.w3spaces.com and click the **Choose File** button - [x] Choose **Take Photo** - [x] (assuming you still have camera permission from previous test; accept permission if needed) - [x] When the camera app loads, cancel without taking an image - [x] Choose **Take Photo** again to sense-check the flow can be repeated after cancellation #### Alt path, refusing camera permission - [x] Clear camera permissions if granted, manually or using `adb shell pm reset-permissions` - [x] Visit https://cdrussell.w3spaces.com and click the **Choose File** button - [x] Choose **Take Photo** - [x] **Refuse** camera permission - [x] Verify nothing else shown to user (just quietly returned to website with no dialogs showing) - [x] Choose **Take Photo** again, and again refuse permission when prompted - [x] Verify this time the permission rationale prompt shows explaining why we'd need this permission to do what the user is asking - [x] Click on the **Open Settings** button and verify it takes you to the right place to alter system permissions for the app #### Alt path, uploading a non-image file - [x] Visit https://cdrussell.w3spaces.com/other.html - [x] Tap the third button (`video/*` upload type) - [x] Verify you are not given the option to use the camera (only supporting images at the moment) ### UI changes <img width=50% src="https://github.com/duckduckgo/Android/assets/1336281/9b6c64d6-20cd-43aa-b0b0-2f039d96dcc7" /> <hr/> <hr/> <img width=50% src="https://github.com/duckduckgo/Android/assets/1336281/0905276b-80a9-4790-8a12-7859c3edafac" />
- Loading branch information
Showing
12 changed files
with
758 additions
and
10 deletions.
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
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
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/duckduckgo/app/browser/camera/CameraHardwareChecker.kt
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2023 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.app.browser.camera | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageManager.FEATURE_CAMERA_ANY | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import javax.inject.Inject | ||
|
||
interface CameraHardwareChecker { | ||
fun hasCameraHardware(): Boolean | ||
} | ||
|
||
@ContributesBinding(AppScope::class) | ||
class CameraHardwareCheckerImpl @Inject constructor( | ||
private val context: Context, | ||
) : CameraHardwareChecker { | ||
|
||
override fun hasCameraHardware(): Boolean { | ||
return with(context.packageManager) { | ||
kotlin.runCatching { hasSystemFeature(FEATURE_CAMERA_ANY) }.getOrDefault(false) | ||
} | ||
} | ||
} |
Oops, something went wrong.