Fixed an NPE in the PolarViewFragment

This commit is contained in:
Arty Bishop committed 2020-02-16 18:40:00 +00:00
1 parent 220f13d22a
commit 27b1da1174
5 files changed
+28 -16

No files matched your search

@@ -65,7 +65,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
val debugMessage: LiveData<String> = _debugMessage
private val _satPassList = MutableLiveData<MutableList<SatPass>>()
val passSatList: LiveData<MutableList<SatPass>> = _satPassList
val satPassList: LiveData<MutableList<SatPass>> = _satPassList
private val _gsp = MutableLiveData<GroundStationPosition>()
val gsp: LiveData<GroundStationPosition> = _gsp
@@ -96,7 +96,7 @@ class MapViewFragment : Fragment() {
private fun setupComponents() {
val delay = viewModel.delay
gsp = viewModel.gsp.value ?: GroundStationPosition(0.0, 0.0, 0.0)
satPassList = viewModel.passSatList.value ?: emptyList()
satPassList = viewModel.satPassList.value ?: emptyList()
if (satPassList.isNotEmpty()) {
satPassList = satPassList.distinctBy { it.tle }
@@ -115,7 +115,7 @@ class PassListFragment : Fragment() {
}
private fun setupObservers() {
viewModel.passSatList.observe(viewLifecycleOwner, Observer {
viewModel.satPassList.observe(viewLifecycleOwner, Observer {
satPassList = it
satPassAdapter.setList(satPassList)
if (satPassList.isNotEmpty()) {
@@ -82,9 +82,6 @@ class PolarViewFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val delay = viewModel.delay
satPass = viewModel.passSatList.value!![args.satPassIndex]
mainActivity.supportActionBar?.title = satPass.tle.name
polarViewFrame = view.findViewById(R.id.polar_view_frame)
transRecycler = view.findViewById(R.id.polar_recycler)
@@ -94,11 +91,22 @@ class PolarViewFragment : Fragment() {
polarAltitude = view.findViewById(R.id.polar_altitude)
noTransFound = view.findViewById(R.id.polar_no_trans)
polarView = PolarView(mainActivity, delay)
polarViewFrame.addView(polarView)
service.scheduleAtFixedRate({ polarView.invalidate() }, delay, delay, TimeUnit.MILLISECONDS)
viewModel.satPassList.value?.let {
val refreshRate = viewModel.delay
satPass = it[args.satPassIndex]
mainActivity.supportActionBar?.title = satPass.tle.name
setupTransRecycler()
polarView = PolarView(mainActivity, refreshRate)
polarViewFrame.addView(polarView)
service.scheduleAtFixedRate(
{ polarView.invalidate() },
refreshRate,
refreshRate,
TimeUnit.MILLISECONDS
)
setupTransRecycler()
}
}
private fun setupTransRecycler() {
@@ -136,9 +136,11 @@ class SatPassAdapter(val viewModel: MainViewModel) :
progressBar.progress = satPass.progress
itemView.setOnClickListener {
val satPassIndex = viewModel.passSatList.value!!.indexOf(satPass)
val action = PassListFragmentDirections.actionPassToPolar(satPassIndex)
it.findNavController().navigate(action)
viewModel.satPassList.value?.let {
val satPassIndex = it.indexOf(satPass)
val action = PassListFragmentDirections.actionPassToPolar(satPassIndex)
itemView.findNavController().navigate(action)
}
}
}
}
@@ -162,9 +164,11 @@ class SatPassAdapter(val viewModel: MainViewModel) :
String.format(context.getString(R.string.pat_elevation), satPass.pass.maxEl)
itemView.setOnClickListener {
val satPassIndex = viewModel.passSatList.value!!.indexOf(satPass)
val action = PassListFragmentDirections.actionPassToPolar(satPassIndex)
it.findNavController().navigate(action)
viewModel.satPassList.value?.let {
val satPassIndex = it.indexOf(satPass)
val action = PassListFragmentDirections.actionPassToPolar(satPassIndex)
itemView.findNavController().navigate(action)
}
}
}
}