Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in EditOverviewFragment #4298

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,7 +39,6 @@ import com.hootsuite.nachos.validator.ChipifyingNachoValidator
import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import kotlinx.coroutines.rx2.awaitSingleOrNull
import openfoodfacts.github.scrachx.openfood.AppFlavors.OBF
import openfoodfacts.github.scrachx.openfood.AppFlavors.OFF
Expand Down Expand Up @@ -575,7 +574,7 @@ class EditOverviewFragment : ProductEditFragment() {
loadFrontImage(languageCode)
val fields = "ingredients_text_$languageCode,product_name_$languageCode"

lifecycleScope.launch {
lifecycleScope.launchWhenResumed {
binding.name.setText(getString(R.string.txtLoading))
binding.name.isActivated = false

Expand All @@ -588,7 +587,7 @@ class EditOverviewFragment : ProductEditFragment() {
Log.e(EditOverviewFragment::class.simpleName, "Error retrieving product state from server api.", err)
binding.name.setText(StringUtils.EMPTY)
binding.name.isActivated = true
return@launch
return@launchWhenResumed
}

if (productState.status != 1L) {
Expand All @@ -598,7 +597,7 @@ class EditOverviewFragment : ProductEditFragment() {
)
binding.name.setText(StringUtils.EMPTY)
binding.name.isActivated = true
return@launch
return@launchWhenResumed
}
val product = productState.product!!
if (product.getProductName(languageCode) != null) {
Expand Down Expand Up @@ -635,8 +634,8 @@ class EditOverviewFragment : ProductEditFragment() {
// Image found, download it if necessary and edit it
isFrontImagePresent = true
if (photoFile == null) {
lifecycleScope.launch {
val uri = download(requireContext(), frontImageUrl!!, client).awaitSingleOrNull() ?: return@launch
lifecycleScope.launchWhenResumed {
val uri = download(requireContext(), frontImageUrl!!, client).awaitSingleOrNull() ?: return@launchWhenResumed

photoFile = uri.toFile()
cropRotateImage(uri, getString(R.string.set_img_front))
Expand Down