Skip to content

Commit

Permalink
fix: not working language selection (#4192)
Browse files Browse the repository at this point in the history
* ref: general refactor to use kotlin inline for building

fix: not working language selection

* fix: clicking profile in drawer crashes the app

* fix: wrong serving regex crashes the app

* chore: removed unused method

* fix: tests
  • Loading branch information
VaiTon committed Aug 29, 2021
1 parent 0b1f856 commit 7caa086
Show file tree
Hide file tree
Showing 43 changed files with 1,034 additions and 787 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle.kts
Expand Up @@ -154,9 +154,11 @@ dependencies {
}

// UI Component : Material Drawer
// https://github.com/mikepenz/MaterialDrawer/commit/3b2cb1db4c3b6afe639b0f3c21c03c1de68648a3
// TODO: We need minSdk 16 to update
implementation("com.mikepenz:materialdrawer:7.0.0") { isTransitive = true }

//DO NOT UPDATE : RecyclerViewCacheUtil removed, needs rework
// DO NOT UPDATE : RecyclerViewCacheUtil removed, needs rework
implementation("com.mikepenz:fastadapter-commons:3.3.1@aar")

// UI Component : Font Icons
Expand Down
Expand Up @@ -11,6 +11,7 @@ import kotlinx.coroutines.test.runBlockingTest
import openfoodfacts.github.scrachx.openfood.models.DaoSession
import openfoodfacts.github.scrachx.openfood.models.entities.allergen.Allergen
import openfoodfacts.github.scrachx.openfood.models.entities.allergen.AllergenName
import openfoodfacts.github.scrachx.openfood.utils.getAppPreferences
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
Expand Down Expand Up @@ -50,8 +51,9 @@ class ProductRepositoryTest {

@Test
fun testGetAllergens() = runBlockingTest {
val mSettings = instance.getSharedPreferences("prefs", 0)
val isDownloadActivated = mSettings.getBoolean(Taxonomy.Allergens.getDownloadActivatePreferencesId(), false)
val appPrefs = instance.getAppPreferences()

val isDownloadActivated = appPrefs.getBoolean(Taxonomy.Allergens.getDownloadActivatePreferencesId(), false)
val allergens = productRepository.reloadAllergensFromServer()
assertNotNull(allergens)
if (!isDownloadActivated) {
Expand Down
Expand Up @@ -22,6 +22,6 @@ object AppFlavors {
const val OBF = "obf"

@JvmStatic
fun isFlavors(vararg flavors: String) = flavors.contains(BuildConfig.FLAVOR_versionCode)
fun isFlavors(vararg flavors: String) = BuildConfig.FLAVOR_versionCode in flavors

}
Expand Up @@ -96,7 +96,7 @@ class ImagesManageActivity : BaseActivity() {

private var lastViewedImage: File? = null
private lateinit var attacher: PhotoViewAttacher
private val settings by lazy { getSharedPreferences("prefs", 0) }
private val settings by lazy { getAppPreferences() }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -185,7 +185,7 @@ class ImagesManageActivity : BaseActivity() {
4 -> startShowCase(getString(R.string.title_edit_photo), getString(R.string.content_edit_photo), R.id.btnEditImage, 5)
5 -> startShowCase(getString(R.string.title_unselect_photo), getString(R.string.content_unselect_photo), R.id.btnUnselectImage, 6)
6 -> startShowCase(getString(R.string.title_exit), getString(R.string.content_exit), R.id.btn_done, 7)
7 -> settings!!.edit { putBoolean(getString(R.string.check_first_time), false) }
7 -> settings.edit { putBoolean(getString(R.string.check_first_time), false) }
}
}
.build()
Expand Down

Large diffs are not rendered by default.

This file was deleted.

Expand Up @@ -21,6 +21,8 @@ import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
Expand All @@ -39,6 +41,7 @@ import openfoodfacts.github.scrachx.openfood.repositories.ProductRepository
import openfoodfacts.github.scrachx.openfood.utils.LocaleManager
import openfoodfacts.github.scrachx.openfood.utils.NavigationDrawerListener
import openfoodfacts.github.scrachx.openfood.utils.NavigationDrawerListener.NavigationDrawerType
import openfoodfacts.github.scrachx.openfood.utils.getAppPreferences
import openfoodfacts.github.scrachx.openfood.utils.isNetworkConnected
import javax.inject.Inject

Expand All @@ -64,7 +67,7 @@ class AllergensAlertFragment : NavigationBaseFragment() {
private var allergensFromDao: List<AllergenName>? = null

private lateinit var adapter: AllergensAdapter
private val mSettings by lazy { requireActivity().getSharedPreferences("prefs", 0) }
private val mSettings by lazy { requireActivity().getAppPreferences() }
private val dataObserver by lazy { AllergensObserver() }
private val appLang: String by lazy { localeManager.getLanguage() }

Expand Down Expand Up @@ -208,20 +211,19 @@ class AllergensAlertFragment : NavigationBaseFragment() {
* Data observer of the Recycler Views
*/
internal inner class AllergensObserver : AdapterDataObserver() {
override fun onChanged() = setAppropriateView()
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) = setAppropriateView()
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) = setAppropriateView()
override fun onChanged() = updateView()
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) = updateView()
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) = updateView()

private fun setAppropriateView() {
private fun updateView() {
val isListEmpty = adapter.itemCount == 0
binding.emptyAllergensView.visibility = if (isListEmpty) View.VISIBLE else View.GONE
binding.allergensRecycle.visibility = if (isListEmpty) View.GONE else View.VISIBLE

binding.emptyAllergensView.isVisible = isListEmpty
binding.allergensRecycle.isGone = isListEmpty
}
}

companion object {

@JvmStatic
fun newInstance() = AllergensAlertFragment().apply { arguments = Bundle() }
}
}
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -46,9 +47,8 @@ class AnalyticsUsageDialogFragment : BottomSheetDialogFragment() {
}

private fun saveAnalyticsReportingPref(value: Boolean) {
sharedPreferences
.edit()
.putBoolean(getString(R.string.pref_analytics_reporting_key), value)
.apply()
sharedPreferences.edit {
putBoolean(getString(R.string.pref_analytics_reporting_key), value)
}
}
}
Expand Up @@ -45,7 +45,7 @@ class CategoryListFragment : BaseFragment() {

binding.fastScroller.setRecyclerView(binding.recycler)
binding.recycler.viewTreeObserver.addOnGlobalLayoutListener {
if (this.viewModel.shownCategories.isEmpty()) {
if (viewModel.shownCategories.isEmpty()) {
binding.fastScroller.visibility = View.GONE
} else {
binding.fastScroller.visibility = View.VISIBLE
Expand Down Expand Up @@ -79,12 +79,13 @@ class CategoryListFragment : BaseFragment() {
searchView.setSearchableInfo(searchManager.getSearchableInfo(requireActivity().componentName))
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
val suggestions = SearchRecentSuggestions(
context,
SearchSuggestionProvider.AUTHORITY,
SearchSuggestionProvider.MODE
)
suggestions.saveRecentQuery(query, null)

SearchRecentSuggestions(
context,
SearchSuggestionProvider.AUTHORITY,
SearchSuggestionProvider.MODE
).saveRecentQuery(query, null)

return false
}

Expand Down
Expand Up @@ -139,7 +139,7 @@ class LoginActivity : BaseActivity() {
null
}
} ?: return@launch
val pref = this@LoginActivity.getSharedPreferences("login", 0)
val pref = this@LoginActivity.getLoginPreferences()
if (isHtmlNotValid(htmlNoParsed)) {
loadingSnackbar.dismiss()

Expand Down

0 comments on commit 7caa086

Please sign in to comment.