Skip to content

Commit

Permalink
revert: try to make things work (#4508)
Browse files Browse the repository at this point in the history
* Revert "chore: fixed tests"

This reverts commit b32d11a.

* Revert "fix: NPE at ProductSearchActivity"

This reverts commit 8bd9aee.

* Revert "fix: NPE in ProductEditActivity#getUpdatedFieldsMap"

This reverts commit 0ff12f6.

* Revert "ref: moved image management activities into subpackages"

This reverts commit 41fa689.

* Revert "ref: use livedata instead of state flow in ProductPhotosFragment"

This reverts commit ca6a775.

* Revert "fix: delete wrong translations & fix null error (#4501)"

This reverts commit 1bf2517.

* Revert "build(deps): bump androidx.preference from 1.1.1. to 1.2.0"

This reverts commit dd160ff.

* Revert "build: update gradle plugin org.sonarqube from 3.0 to 3.3"

This reverts commit 4ca98ba.

* Revert "Revert "build: update gradle plugin org.sonarqube from 3.0 to 3.3""

This reverts commit dacc755

* Revert "Revert "build(deps): bump androidx.preference from 1.1.1. to 1.2.0""

This reverts commit 11ff269

* Revert "Revert "fix: delete wrong translations & fix null error (#4501)""

This reverts commit 9b25706

* Revert "Revert "ref: use livedata instead of state flow in ProductPhotosFragment""

This reverts commit f2c125c

* Revert "Revert "Revert "ref: use livedata instead of state flow in ProductPhotosFragment"""

This reverts commit ddf63fa
  • Loading branch information
VaiTon committed Mar 2, 2022
1 parent 2e592c5 commit f17cf09
Show file tree
Hide file tree
Showing 45 changed files with 433 additions and 495 deletions.
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@
android:value=".features.MainActivity" />
</activity>

<activity android:name=".features.images.manage.ImagesManageActivity" />
<activity android:name=".features.ImagesManageActivity" />

<activity android:name=".features.images.zoom.ImageZoomActivity" />
<activity android:name=".features.ImageZoomActivity" />

<activity android:name=".features.images.select.ImagesSelectActivity" />
<activity android:name=".features.ImagesSelectActivity" />

<activity
android:name=".features.scanhistory.ScanHistoryActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package openfoodfacts.github.scrachx.openfood.analytics

import openfoodfacts.github.scrachx.openfood.models.Barcode

sealed class AnalyticsEvent(val category: String, val action: String, val name: String?, val value: Float?) {

object ProductSearch : AnalyticsEvent("search", "completed", null, null)

object ProductSearchStart : AnalyticsEvent("search", "started", null, null)

data class ScannedBarcode(val barcode: Barcode) : AnalyticsEvent("scanner", "scanned", barcode.b, null)
data class ScannedBarcode(val barcode: String) : AnalyticsEvent("scanner", "scanned", barcode, null)

data class ScannedBarcodeResultExpanded(val barcode: Barcode?) : AnalyticsEvent("scanner", "result-expanded", barcode?.b, null)
data class ScannedBarcodeResultExpanded(val barcode: String?) : AnalyticsEvent("scanner", "result-expanded", barcode, null)

data class AllergenAlertCreated(val allergenTag: String) : AnalyticsEvent("allergen-alerts", "created", allergenTag, null)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package openfoodfacts.github.scrachx.openfood.features

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
Expand All @@ -9,8 +10,6 @@ import androidx.annotation.CheckResult
import androidx.core.app.ActivityOptionsCompat
import androidx.fragment.app.Fragment
import openfoodfacts.github.scrachx.openfood.R
import openfoodfacts.github.scrachx.openfood.features.images.manage.ImagesManageActivity
import openfoodfacts.github.scrachx.openfood.features.images.zoom.ImageZoomActivity
import openfoodfacts.github.scrachx.openfood.images.IMAGE_URL
import openfoodfacts.github.scrachx.openfood.images.ImageSize
import openfoodfacts.github.scrachx.openfood.images.createImageBundle
Expand Down Expand Up @@ -97,7 +96,7 @@ object FullScreenActivityOpener {
mImageFront: View,
language: String
) {
client.getProductStateWithImages(product.barcode).product?.let { newProduct ->
client.getProductImages(product.code).product?.let { newProduct ->
val imageUrl = newProduct.getSelectedImage(language, imageType, ImageSize.DISPLAY)
if (!imageUrl.isNullOrBlank()) {
openForUrl(activity, client, newProduct, imageType, imageUrl, mImageFront, language)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package openfoodfacts.github.scrachx.openfood.features.images.zoom
package openfoodfacts.github.scrachx.openfood.features

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewTreeObserver
import android.widget.Toast
import androidx.activity.viewModels
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.github.chrisbanes.photoview.PhotoViewAttacher
import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso
Expand All @@ -18,6 +16,7 @@ import openfoodfacts.github.scrachx.openfood.R
import openfoodfacts.github.scrachx.openfood.databinding.ActivityZoomImageBinding
import openfoodfacts.github.scrachx.openfood.features.shared.BaseActivity
import openfoodfacts.github.scrachx.openfood.images.IMAGE_URL
import java.util.*
import javax.inject.Inject

/**
Expand All @@ -28,8 +27,6 @@ class ImageZoomActivity : BaseActivity() {
private var _binding: ActivityZoomImageBinding? = null
private val binding get() = _binding!!

private val viewModel: ImageZoomViewModel by viewModels()

@Inject
lateinit var picasso: Picasso

Expand All @@ -47,25 +44,14 @@ class ImageZoomActivity : BaseActivity() {
ActivityCompat.postponeEnterTransition(this)

supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.setTitle(R.string.imageFullscreen)

viewModel.isRefreshing.observe(this) { refreshing ->
if (refreshing) {
binding.progressBar.isVisible = true
binding.textInfo.setTextColor(ContextCompat.getColor(this, R.color.white))
binding.textInfo.setText(R.string.txtLoading)
} else {
binding.progressBar.isVisible = false
binding.textInfo.isVisible = false
}
}

val imageUrl = intent.getStringExtra(IMAGE_URL)
loadImage(imageUrl)
loadImage(intent.getStringExtra(IMAGE_URL))
}


override fun onResume() {
supportActionBar!!.setTitle(R.string.imageFullscreen)
binding.toolbar.setTitle(R.string.imageFullscreen)
super.onResume()
}

Expand All @@ -83,32 +69,43 @@ class ImageZoomActivity : BaseActivity() {
private fun loadImage(imageUrl: String?) {
if (imageUrl.isNullOrEmpty()) {
binding.imageViewFullScreen.setImageDrawable(null)
viewModel.isRefreshing.postValue(false)
stopRefresh()
} else {
viewModel.isRefreshing.postValue(true)
startRefresh(getString(R.string.txtLoading))
picasso
.load(imageUrl)
.into(binding.imageViewFullScreen, object : Callback {
override fun onSuccess() {
// Activity could have been destroyed while we load the image
if (isFinishing) return
attacher.update()
scheduleStartPostponedTransition(binding.imageViewFullScreen)
binding.imageViewFullScreen.visibility = View.VISIBLE
viewModel.isRefreshing.postValue(false)
}

override fun onError(ex: Exception) {
// Activity could have been destroyed while we load the image
if (isFinishing) return
binding.imageViewFullScreen.visibility = View.VISIBLE
Toast.makeText(this@ImageZoomActivity, resources.getString(R.string.txtConnectionError), Toast.LENGTH_LONG).show()
viewModel.isRefreshing.postValue(false)
}
})
.load(imageUrl)
.into(binding.imageViewFullScreen, object : Callback {
override fun onSuccess() {
// Activity could have been destroyed while we load the image
if (isFinishing) return
attacher.update()
scheduleStartPostponedTransition(binding.imageViewFullScreen)
binding.imageViewFullScreen.visibility = View.VISIBLE
stopRefresh()
}

override fun onError(ex: Exception) {
// Activity could have been destroyed while we load the image
if (isFinishing) return
binding.imageViewFullScreen.visibility = View.VISIBLE
Toast.makeText(this@ImageZoomActivity, resources.getString(R.string.txtConnectionError), Toast.LENGTH_LONG).show()
stopRefresh()
}
})
}
}

private fun stopRefresh() {
binding.progressBar.visibility = View.GONE
binding.textInfo.visibility = View.GONE
}


private fun startRefresh(text: String) {
binding.progressBar.visibility = View.VISIBLE
binding.textInfo.setTextColor(ContextCompat.getColor(this, R.color.white))
binding.textInfo.text = text
}

/**
* For scheduling a postponed transition after the proper measures of the view are done
Expand All @@ -126,8 +123,8 @@ class ImageZoomActivity : BaseActivity() {

companion object {
fun start(
context: Context,
imageUrl: String
context: Context,
imageUrl: String
) = context.startActivity(Intent(context, ImageZoomActivity::class.java).apply {
putExtra(IMAGE_URL, imageUrl)
})
Expand Down

0 comments on commit f17cf09

Please sign in to comment.