Skip to content

Commit

Permalink
fix: do not try to refresh if activity is not ProductViewActivity
Browse files Browse the repository at this point in the history
Fixes OPENFOODFACTS-ANDROID-3GP
  • Loading branch information
VaiTon committed May 29, 2021
1 parent 71309c7 commit 32e9f0d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
Expand Up @@ -226,6 +226,7 @@ class ProductEditActivity : BaseActivity() {
if (productState == null && offlineSavedProduct == null && mEditProduct == null) {
Toast.makeText(this, R.string.error_adding_product, Toast.LENGTH_SHORT).show()
finish()
return
}
setupViewPager(binding.viewpager)
}
Expand Down
Expand Up @@ -63,6 +63,9 @@ class ProductEditPhotosFragment : ProductEditFragment() {
@Inject
lateinit var localeManager: LocaleManager

@Inject
lateinit var picasso: Picasso

private val photoReceiverHandler by lazy {
PhotoReceiverHandler(sharedPreferences) { newPhotoFile ->
photoFile = newPhotoFile
Expand Down Expand Up @@ -93,24 +96,26 @@ class ProductEditPhotosFragment : ProductEditFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.btnAddOtherImage.setOnClickListener { addOtherImage() }
binding.btnAdd.setOnClickListener { next() }

val bundle = arguments
if (bundle != null) {
val product = bundle.getSerializable("product") as Product?
val offlineSavedProduct = bundle.getSerializable("edit_offline_product") as OfflineSavedProduct?
val editionMode = bundle.getBoolean(ProductEditActivity.KEY_IS_EDITING)
if (product != null) {
code = product.code
}
if (editionMode && product != null) {
binding.btnAdd.setText(R.string.save_edits)
} else if (offlineSavedProduct != null) {
code = offlineSavedProduct.barcode
}
} else {
if (bundle == null) {
Toast.makeText(activity, R.string.error_adding_product_photos, Toast.LENGTH_SHORT).show()
requireActivity().finish()
error("Cannot start fragment without arguments.")
}

val product = bundle.getSerializable("product") as Product?
val offlineSavedProduct = bundle.getSerializable("edit_offline_product") as OfflineSavedProduct?
val editing = bundle.getBoolean(ProductEditActivity.KEY_IS_EDITING)
if (product != null) {
code = product.code
}
if (editing && product != null) {
binding.btnAdd.setText(R.string.save_edits)
} else if (offlineSavedProduct != null) {
code = offlineSavedProduct.barcode
}
}

Expand Down Expand Up @@ -162,8 +167,7 @@ class ProductEditPhotosFragment : ProductEditFragment() {
scaleType = ImageView.ScaleType.FIT_CENTER
layoutParams = lp
}
Picasso.get()
.load(photoFile!!)
picasso.load(photoFile!!)
.resize(requireContext().dpsToPixel(100), requireContext().dpsToPixel(100))
.centerInside()
.into(imageView)
Expand Down
Expand Up @@ -836,7 +836,7 @@ class SummaryProductFragment : BaseFragment(), ISummaryProductPresenter.View {
}

private val editProductLauncher = registerForActivityResult(ProductEditActivity.EditProductContract())
{ isOk -> if (isOk) (activity as ProductViewActivity).onRefresh() }
{ isOk -> if (isOk) (activity as? ProductViewActivity)?.onRefresh() }

private fun editProduct() = editProductLauncher.launch(product)

Expand Down

0 comments on commit 32e9f0d

Please sign in to comment.