Author: Adam Evyčędo <git@apiote.xyz>
use new methods to get intent extras
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt index a7ad251fbb4db18f91b304d48f0b9cb94c77ae54..2aded60740f242cfb8b7ac4283a21791bf8abc9e 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt @@ -9,6 +9,7 @@ import android.location.Location import android.location.LocationListener import android.location.LocationManager import android.net.ConnectivityManager +import android.os.Build import android.os.Bundle import android.os.Handler import android.os.Looper @@ -54,8 +55,9 @@ setSupportActionBar(binding.topAppBar) WindowCompat.setDecorFitsSystemWindows(window, false) - @Suppress("DEPRECATION") // fixme later getSerializable in API>=33 - when (intent.extras?.get("mode")) { + + + when (getMode()) { Mode.MODE_LOCATION -> { supportActionBar?.title = getString(R.string.stops_nearby) locate() @@ -77,6 +79,15 @@ } } } + private fun getMode():Mode { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + intent.extras!!.getSerializable("mode", Mode::class.java)!! + } else { + @Suppress("DEPRECATION") + intent.extras!!.get("mode") as Mode + } + } + private fun locate() { try { val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager @@ -102,8 +113,7 @@ } override fun onResume() { super.onResume() - @Suppress("DEPRECATION") // fixme later getSerializable in API>=33 - if (intent.extras?.get("mode") == Mode.MODE_LOCATION) { + if (getMode() == Mode.MODE_LOCATION) { locate() } } @@ -176,8 +186,7 @@ R.drawable.error_search ) ) } else { - @Suppress("DEPRECATION") // fixme later getSerializable in API>=33 - if (queryables.size == 1 && intent.extras?.get("mode") == Mode.MODE_SEARCH) { + if (queryables.size == 1 && getMode() == Mode.MODE_SEARCH) { adapter.click(0) } binding.resultsOverlay.visibility = View.GONE diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/search/ui/LineGraphFragment.kt b/app/src/main/java/xyz/apiote/bimba/czwek/search/ui/LineGraphFragment.kt index 8f696948dbf562ac6ebca1e6bcc89397167826d2..88c8d402f9f5bd10433e93faf71794962ea269a3 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/search/ui/LineGraphFragment.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/search/ui/LineGraphFragment.kt @@ -9,6 +9,7 @@ import android.content.Intent import android.content.res.TypedArray import android.graphics.CornerPathEffect import android.graphics.Paint +import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -69,11 +70,15 @@ pathEffect = CornerPathEffect(10f) })) binding.recycler.adapter = adapter pageViewModel.let { - val lineGraph = arguments?.getParcelable("graph") as LineGraph? + val lineGraph = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + arguments?.getParcelable("graph", LineGraph::class.java) + } else { + @Suppress("DEPRECATION") + arguments?.getParcelable("graph") as LineGraph? + } it.setupGraphView(lineGraph!!) it.data.observe(viewLifecycleOwner) { graph -> adapter.submitGraph(graph) - // adapter.notifyDataSetChanged() } }