Skip to content

Commit

Permalink
Environment tab: if the camera permission is missing, once granted, t…
Browse files Browse the repository at this point in the history
…he camera app should be launched (#4609)
  • Loading branch information
g123k committed Mar 25, 2022
1 parent 6cb1e4f commit 3f4d9bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Expand Up @@ -80,7 +80,7 @@ class EnvironmentProductFragment : BaseFragment() {
super.onViewCreated(view, savedInstanceState)
val langCode = localeManager.getLanguage()
productState = requireProductState()
binding.imageViewPackaging.setOnClickListener { openFullScreen() }
binding.imageViewPackaging.setOnClickListener { openFullScreenImage() }

// If Battery Level is low and the user has checked the Disable Image in Preferences , then set isLowBatteryMode to true
if (requireContext().isDisableImageLoad() && requireContext().isBatteryLevelLow()) {
Expand Down Expand Up @@ -172,7 +172,7 @@ class EnvironmentProductFragment : BaseFragment() {
refreshTagsPrompt()
}

private fun openFullScreen() {
private fun openFullScreenImage() {
val imageUrl = mUrlImage
val product = productState.product
if (imageUrl != null && product != null) {
Expand All @@ -194,6 +194,8 @@ class EnvironmentProductFragment : BaseFragment() {

private fun newPackagingImage() = doChooseOrTakePhotos()

override fun doOnPhotosPermissionGranted() = doChooseOrTakePhotos()

private fun loadPackagingPhoto(photoFile: File) {
// Create a new instance of ProductImage so we can load to server
val image = ProductImage(productState.product!!.code, ProductImageField.PACKAGING, photoFile, localeManager.getLanguage())
Expand Down
Expand Up @@ -93,10 +93,9 @@ abstract class BaseFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener,
protected fun doChooseOrTakePhotos() {
if (canTakePhotos()) {
EasyImage.openCamera(this, 0)
return
} else {
cameraPermissionRequestLauncher.launch(Manifest.permission.CAMERA)
}
// Ask for permissions
cameraPermissionRequestLauncher.launch(Manifest.permission.CAMERA)
}

protected open fun doOnPhotosPermissionGranted() = Unit
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_environment_product.xml
Expand Up @@ -22,7 +22,6 @@
android:orientation="vertical"
android:paddingBottom="@dimen/nav_bar_height">


<openfoodfacts.github.scrachx.openfood.features.shared.views.TipBox
android:id="@+id/packagingImagetipBox"
android:layout_width="match_parent"
Expand Down

0 comments on commit 3f4d9bb

Please sign in to comment.