Author: Adam <git@apiote.xyz>
catch peka.poznan.pl/vm link
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3dda5bd2202ae415c42e7a46cbf35e869f85359d..78208146a9ce930e23e743c01737f00d953ae327 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,7 +32,18 @@ </activity> <activity android:name=".departures.DeparturesActivity" - android:exported="false" /> + android:exported="true" > + <intent-filter> + <action android:name="android.intent.action.VIEW"/> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data android:scheme="http" /> + <data android:scheme="https" /> + <data android:host="www.peka.poznan.pl" /> + <data android:pathPrefix="/vm"/> + </intent-filter> + </activity> <activity android:name=".search.ResultsActivity" android:exported="false" diff --git a/app/src/main/java/ml/adamsprogs/bimba/departures/DeparturesActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/departures/DeparturesActivity.kt index 54dc07e30d23a1cb9bcf32ce8fd19ddb029082d4..c25caad89efb5b316e5fe2e7a84c149c0f698e59 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/departures/DeparturesActivity.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/departures/DeparturesActivity.kt @@ -1,6 +1,7 @@ package ml.adamsprogs.bimba.departures import android.content.Context +import android.content.Intent import android.content.SharedPreferences import androidx.appcompat.app.AppCompatActivity import android.os.Bundle @@ -33,7 +34,7 @@ _binding = ActivityDeparturesBinding.inflate(layoutInflater) setContentView(binding.root) binding.collapsingLayout.apply { - title = intent?.extras?.getString("name") + title = getName() val tf = ResourcesCompat.getFont(this@DeparturesActivity, R.font.railway) setCollapsedTitleTypeface(tf) setExpandedTitleTypeface(tf) @@ -50,25 +51,43 @@ preferences = getSharedPreferences("shp", MODE_PRIVATE) // todo check every 30s + getDepartures() + } + private fun getName(): String { + return when (intent?.action) { + Intent.ACTION_VIEW -> getCode() + null -> intent?.extras?.getString("name") ?: "" + else -> "" + } + } + + private fun getCode(): String { + return when (intent?.action) { + Intent.ACTION_VIEW -> intent?.data?.getQueryParameter("przystanek") ?: "" + null -> intent?.extras?.getString("code") ?: "" + else -> "" + } + } + + private fun getDepartures() { + val host = preferences.getString("host", "bimba.apiote.xyz")!! MainScope().launch { - intent?.extras?.getString("code")?.let { - val departuresStream = getDepartures( - Server( - host, preferences.getString("token", "")!!, - preferences.getString("${host}_feeds", "")!! - ), it, null - ) - if (departuresStream == null) { - // todo show empty state - Toast.makeText( - this@DeparturesActivity as Context, - "Couldn't get response", - Toast.LENGTH_SHORT - ).show() - } else { - updateItems(unmarshallDepartureResponse(departuresStream)) - } + val departuresStream = getDepartures( + Server( + host, preferences.getString("token", "")!!, + preferences.getString("${host}_feeds", "")!! + ), getCode() + ) + if (departuresStream == null) { + // todo(error-handling) show empty state + Toast.makeText( + this@DeparturesActivity as Context, + "Couldn't get response", + Toast.LENGTH_SHORT + ).show() + } else { + updateItems(unmarshallDepartureResponse(departuresStream)) } } } @@ -90,6 +109,9 @@ private fun updateItems(response: DeparturesSuccess) { binding.departuresProgress.visibility = View.GONE binding.departuresRecycler.visibility = View.VISIBLE adapter.update(response.departures) + binding.collapsingLayout.apply { + title = response.stop.name + } // todo alerts // todo stop info }