Author: Adam Evyčędo <git@apiote.xyz>
persist departure bottom sheet between screen change
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt index 98a5390c76d36966e06f346bfacb09333416b276..0f51af73cb0cdf09a9ec701a42a8192b6e230560 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt @@ -13,8 +13,6 @@ import android.net.NetworkRequest import android.os.Build import android.os.Bundle import android.os.CountDownTimer -import android.os.Handler -import android.os.Looper import android.text.format.DateUtils import android.text.format.DateUtils.MINUTE_IN_MILLIS import android.view.View @@ -49,9 +47,6 @@ private val binding get() = _binding!! private lateinit var adapter: BimbaDeparturesAdapter - private val handler = Handler(Looper.getMainLooper()) - - private var openBottomSheet: DepartureBottomSheet? = null private lateinit var snackbar: Snackbar private lateinit var viewModel: DeparturesViewModel @@ -133,7 +128,7 @@ t >= viewModel.startTime && t <= viewModel.endTime }, stopDepartures.stop ) - openBottomSheet?.departureID()?.let { adapter.get(it) }?.let { openBottomSheet?.update(it) } + viewModel.openBottomSheet?.departureID()?.let { adapter.get(it) }?.let { viewModel.openBottomSheet?.update(it) } val lines = stopDepartures.departures.map { it.vehicle.Line.name }.sortedWith { s1, s2 -> val s1n = s1.toIntOrNull() @@ -252,8 +247,8 @@ ) adapter = BimbaDeparturesAdapter(layoutInflater, this, listOf()) { DepartureBottomSheet(it).apply { show(supportFragmentManager, DepartureBottomSheet.TAG) - openBottomSheet = this - setOnCancel { openBottomSheet = null } + viewModel.openBottomSheet = this + setOnCancel { viewModel.openBottomSheet = null } } } binding.departuresRecycler.adapter = adapter @@ -284,9 +279,11 @@ override fun onResume() { super.onResume() getDepartures() + viewModel.openBottomSheet?.show(supportFragmentManager, DepartureBottomSheet.TAG) } override fun onPause() { + viewModel.openBottomSheet?.dismiss() super.onPause() countdown.cancel() } diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesViewModel.kt b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesViewModel.kt index 3bcbc042905b39dda17cd10d5adec093fa03c315..6f2272afe8fe7a9dec1164df13fc8273aa438fb4 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesViewModel.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesViewModel.kt @@ -33,6 +33,7 @@ val error: LiveData= _error var requestedItemsNumber = 12 var allItemsRequested = false private var feed: FeedInfo? = null + var openBottomSheet: DepartureBottomSheet? = null private lateinit var code: String // TODO observe in activity, maybe refreshing and not getting departures is enough val linesFilter = mutableMapOf<String, Boolean>()