Archived
Removed requireContext() calls to combat recent crash wave
This commit is contained in:
+2
-2
@@ -10,8 +10,8 @@ android {
|
||||
applicationId "com.denizd.substitutionplan"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 29
|
||||
versionCode 43
|
||||
versionName "2.4.0"
|
||||
versionCode 44
|
||||
versionName "2.4.1"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.denizd.substitutionplan.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -24,6 +25,12 @@ internal class FoodFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FoodLayoutBinding
|
||||
private lateinit var snackBarContainer: CoordinatorLayout
|
||||
private lateinit var mContext: Context
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
mContext = context
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
binding = FoodLayoutBinding.inflate(inflater, container, false)
|
||||
@@ -37,7 +44,7 @@ internal class FoodFragment : Fragment() {
|
||||
|
||||
binding.recyclerView.apply {
|
||||
hasFixedSize()
|
||||
layoutManager = GridLayoutManager(requireContext(), 1)
|
||||
layoutManager = GridLayoutManager(mContext, 1)
|
||||
adapter = mAdapter
|
||||
}
|
||||
|
||||
@@ -64,7 +71,7 @@ internal class FoodFragment : Fragment() {
|
||||
viewModel.refresh { result, error ->
|
||||
val snackBar = Snackbar.make(snackBarContainer, result, Snackbar.LENGTH_LONG)
|
||||
if (error) {
|
||||
snackBar.setBackgroundTint(ContextCompat.getColor(requireContext(), R.color.colorError))
|
||||
snackBar.setBackgroundTint(ContextCompat.getColor(mContext, R.color.colorError))
|
||||
}
|
||||
snackBar.show()
|
||||
binding.swipeRefreshLayout.isRefreshing = false
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.denizd.substitutionplan.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
@@ -28,6 +29,12 @@ internal open class PlanFragment : Fragment() {
|
||||
internal var substitutionPlan: LiveData<List<Substitution>>? = null
|
||||
internal lateinit var binding: PlanBinding
|
||||
private lateinit var snackBarContainer: CoordinatorLayout
|
||||
private lateinit var mContext: Context
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
mContext = context
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
binding = PlanBinding.inflate(inflater, container, false)
|
||||
@@ -36,7 +43,7 @@ internal open class PlanFragment : Fragment() {
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
binding.recyclerView.layoutManager = GridLayoutManager(requireContext(), viewModel.getGridColumnCount(newConfig))
|
||||
binding.recyclerView.layoutManager = GridLayoutManager(mContext, viewModel.getGridColumnCount(newConfig))
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@@ -53,7 +60,7 @@ internal open class PlanFragment : Fragment() {
|
||||
|
||||
binding.recyclerView.apply {
|
||||
hasFixedSize()
|
||||
layoutManager = GridLayoutManager(requireContext(), viewModel.getGridColumnCount(resources.configuration))
|
||||
layoutManager = GridLayoutManager(mContext, viewModel.getGridColumnCount(resources.configuration))
|
||||
adapter = mAdapter
|
||||
}
|
||||
|
||||
@@ -76,7 +83,7 @@ internal open class PlanFragment : Fragment() {
|
||||
viewModel.refresh { result, error ->
|
||||
val snackBar = Snackbar.make(snackBarContainer, result, Snackbar.LENGTH_LONG)
|
||||
if (error) {
|
||||
snackBar.setBackgroundTint(ContextCompat.getColor(requireContext(), R.color.colorError)) // TODO check if requireContext() is dangerous ;(
|
||||
snackBar.setBackgroundTint(ContextCompat.getColor(mContext, R.color.colorError)) // TODO check if mContext is dangerous ;(
|
||||
}
|
||||
snackBar.show()
|
||||
binding.swipeRefreshLayout.isRefreshing = false
|
||||
|
||||
@@ -209,7 +209,7 @@ internal class SettingsFragment : Fragment(), View.OnClickListener, View.OnLongC
|
||||
viewModel.forceRefresh { result, error ->
|
||||
val snackBar = Snackbar.make(snackBarContainer, result, Snackbar.LENGTH_LONG)
|
||||
if (error) {
|
||||
snackBar.setBackgroundTint(ContextCompat.getColor(requireContext(), R.color.colorError))
|
||||
snackBar.setBackgroundTint(ContextCompat.getColor(mContext, R.color.colorError))
|
||||
}
|
||||
snackBar.show()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user