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