Skip to content

Commit

Permalink
fix: NPE on ProductEditNutritionFactsFragment.kt init
Browse files Browse the repository at this point in the history
Closes #4073
  • Loading branch information
VaiTon committed Jun 25, 2021
1 parent 7293db1 commit 78ac2b3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
Expand Up @@ -678,10 +678,10 @@ class ProductEditNutritionFactsFragment : ProductEditFragment() {
}

private val isDataPerServing: Boolean
get() = viewModel.isDataPerServing.value!!
get() = viewModel.dataFormat.value == R.id.per_serving

private val isDataPer100g: Boolean
get() = viewModel.isDataPer100g.value!!
get() = viewModel.dataFormat.value == R.id.for100g_100ml

private val referenceValueInGram: Float
get() {
Expand Down
Expand Up @@ -2,7 +2,6 @@ package openfoodfacts.github.scrachx.openfood.features.product.edit.nutrition

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.map
import dagger.hilt.android.lifecycle.HiltViewModel
import openfoodfacts.github.scrachx.openfood.R
import openfoodfacts.github.scrachx.openfood.models.Product
Expand All @@ -15,8 +14,6 @@ class ProductEditNutritionViewModel @Inject constructor() : ViewModel() {

val noNutritionFactsChecked = MutableLiveData<Boolean>()

val dataFormat = MutableLiveData<Int>()
val dataFormat = MutableLiveData(R.id.for100g_100ml)

val isDataPerServing = dataFormat.map { it == R.id.per_serving }
val isDataPer100g = dataFormat.map { it == R.id.for100g_100ml }
}
Expand Up @@ -6,6 +6,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import io.reactivex.Single
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.rx2.await
import kotlinx.coroutines.rx2.rxSingle
import kotlinx.coroutines.withContext
import openfoodfacts.github.scrachx.openfood.BuildConfig
import openfoodfacts.github.scrachx.openfood.utils.Utils
Expand All @@ -30,7 +31,7 @@ class TaxonomiesManager @Inject constructor(
* @return The timestamp of the last changes date of the taxonomy.json on the server
* or [TAXONOMY_NO_INTERNET] if there is no connection to the server.
*/
private fun getLastModifiedDateFromServer(taxonomy: Taxonomy): Single<Long> = Single.fromCallable {
private fun getLastModifiedDateFromServer(taxonomy: Taxonomy): Single<Long> = rxSingle(Dispatchers.IO) {
var lastModifiedDate: Long
val taxoUrl = URL(BuildConfig.OFWEBSITE + taxonomy.jsonUrl)
try {
Expand All @@ -43,7 +44,7 @@ class TaxonomiesManager @Inject constructor(
lastModifiedDate = TAXONOMY_NO_INTERNET
}
Log.i(LOG_TAG, "Last modified date for taxonomy \"$taxonomy\" is $lastModifiedDate")
return@fromCallable lastModifiedDate
return@rxSingle lastModifiedDate
}

/**
Expand Down
Expand Up @@ -143,7 +143,6 @@
android:id="@+id/for100g_100ml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/for_100g_100ml" />

<RadioButton
Expand Down

0 comments on commit 78ac2b3

Please sign in to comment.