Author: Adam Pioterek <adam.pioterek@protonmail.ch>
vm messages
app/src/main/java/ml/adamsprogs/bimba/ProviderProxy.kt | 9 app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt | 29 app/src/main/java/ml/adamsprogs/bimba/datasources/VmClient.kt | 12 app/src/main/res/drawable/ic_message.xml | 9 app/src/main/res/layout/activity_stop.xml | 93 + app/src/main/res/layout/banner.xml | 57 + app/src/main/res/values-de/strings.xml | 3 app/src/main/res/values-it/strings.xml | 3 app/src/main/res/values-nl/strings.xml | 3 app/src/main/res/values-pl/strings.xml | 3 app/src/main/res/values/strings.xml | 4 todo | 2
diff --git a/app/src/main/java/ml/adamsprogs/bimba/ProviderProxy.kt b/app/src/main/java/ml/adamsprogs/bimba/ProviderProxy.kt index a782388d35c50c2fa78fb11c4647f24924c1d637..99225e0e49c57da0143579fe0ecda2b31459456e 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/ProviderProxy.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/ProviderProxy.kt @@ -85,6 +85,15 @@ } } } + fun getVmMessage(shed: String, callback: (String?) -> Unit) { + GlobalScope.launch { + val message = vmClient.getMessage(shed) + launch(Dispatchers.Main) { + callback(message) + } + } + } + fun subscribeForDepartures(stopSegments: Set<StopSegment>, listener: OnDeparturesReadyListener, context: Context): String { stopSegments.forEach { val intent = Intent(context, VmService::class.java) diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt index 84301031315bd5576bb5771f81dff3248510976f..2e0129cd1f3e89e7c1bfcc7cc0eee5458afab98c 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt @@ -1,16 +1,21 @@ package ml.adamsprogs.bimba.activities +import android.content.DialogInterface import android.content.Intent import android.content.IntentFilter +import android.os.Build import android.os.Bundle +import android.text.Html import android.view.Menu import android.view.MenuItem import android.view.View import android.widget.AdapterView +import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.core.content.res.ResourcesCompat import com.google.android.material.snackbar.Snackbar import kotlinx.android.synthetic.main.activity_stop.* +import kotlinx.android.synthetic.main.banner.* import ml.adamsprogs.bimba.* import ml.adamsprogs.bimba.collections.FavouriteStorage import ml.adamsprogs.bimba.datasources.TimetableDownloader @@ -88,6 +93,30 @@ updateFabVisibility(dy) super.onScrolled(recyclerView, dx, dy) } }) + + if (stopCode != "") + providerProxy.getVmMessage(stopCode) { message -> + if (message != null) { + val rendered = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY) + } else { + @Suppress("DEPRECATION") + Html.fromHtml(message) + } + + banner.visibility = View.VISIBLE + banner_text.text = rendered + banner_more.setOnClickListener { + AlertDialog.Builder(context) + .setPositiveButton(context.getText(android.R.string.ok)) + { dialog: DialogInterface, _: Int -> dialog.cancel() } + .setCancelable(true) + .setMessage(rendered) + .create().show() + } + } + } prepareOnDownloadListener() subscribeForDepartures() diff --git a/app/src/main/java/ml/adamsprogs/bimba/datasources/VmClient.kt b/app/src/main/java/ml/adamsprogs/bimba/datasources/VmClient.kt index 0eafd504f6eb3869d774306310a0e7e6b22c6330..e13f32e35c89ab8748581eff7e4eb1beb25e2e7c 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/datasources/VmClient.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/datasources/VmClient.kt @@ -139,4 +139,16 @@ Plate.ID(direction["lineName"].asString, symbol, direction["direction"].asString) } }.toSet()) } + + suspend fun getMessage(shed: String): String? { + val (_, response) = makeRequest("findMessagesForBollard", """{"symbol": "$shed"}""") + + if (!response.has("success")) + return null + + if (response["success"].asJsonArray.size() == 0) + return null + + return response["success"].asJsonArray[0].asJsonObject["content"].asString + } } diff --git a/app/src/main/res/drawable/ic_message.xml b/app/src/main/res/drawable/ic_message.xml new file mode 100644 index 0000000000000000000000000000000000000000..d2876bfad9b41c533cbcab6156b7585e326a5644 --- /dev/null +++ b/app/src/main/res/drawable/ic_message.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="#FF000000" + android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM18,14L6,14v-2h12v2zM18,11L6,11L6,9h12v2zM18,8L6,8L6,6h12v2z"/> +</vector> diff --git a/app/src/main/res/layout/activity_stop.xml b/app/src/main/res/layout/activity_stop.xml index baf078918f5baf2a93b57ddfa86ed2b14d42b34e..05d71ed05e8009e70dd887dd6b58283de8f2448e 100644 --- a/app/src/main/res/layout/activity_stop.xml +++ b/app/src/main/res/layout/activity_stop.xml @@ -8,6 +8,47 @@ android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="ml.adamsprogs.bimba.activities.StopActivity"> + <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="@dimen/appbar_padding_top" + android:theme="@style/AppTheme.AppBarOverlay"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + android:layout_weight="1" + android:background="?attr/colorPrimary" + app:layout_scrollFlags="scroll|enterAlways" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:title="@string/app_name"> + + </androidx.appcompat.widget.Toolbar> + + <Spinner + android:id="@+id/dateSpinner" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginLeft="8dp" + android:layout_marginEnd="8dp" + android:layout_marginRight="8dp" + android:layout_marginBottom="8dp" + android:layout_weight="1" + android:visibility="gone" /> + </com.google.android.material.appbar.AppBarLayout> + + <include + android:visibility="gone" + android:id="@+id/banner" + layout="@layout/banner" + android:layout_height="120dp" + android:layout_width="match_parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/appbar" /> <ImageView android:id="@+id/emptyStateIcon" @@ -17,13 +58,13 @@ android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" + android:contentDescription="@string/departures_empty_state_icon" + android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/appbar" - app:srcCompat="@drawable/ic_traffic" - android:visibility="gone" - android:contentDescription="@string/departures_empty_state_icon" /> + app:layout_constraintTop_toBottomOf="@+id/banner" + app:srcCompat="@drawable/ic_traffic" /> <TextView android:id="@+id/emptyStateText" @@ -33,9 +74,9 @@ android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:text="@string/no_departures" + android:visibility="gone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - android:visibility="gone" app:layout_constraintTop_toBottomOf="@+id/emptyStateIcon" /> <ProgressBar @@ -50,51 +91,18 @@ android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/appbar" /> - - <com.google.android.material.appbar.AppBarLayout - android:id="@+id/appbar" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingTop="@dimen/appbar_padding_top" - android:theme="@style/AppTheme.AppBarOverlay"> - - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar" - android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - android:layout_weight="1" - android:background="?attr/colorPrimary" - app:layout_scrollFlags="scroll|enterAlways" - app:popupTheme="@style/AppTheme.PopupOverlay" - app:title="@string/app_name"> - - </androidx.appcompat.widget.Toolbar> - - <Spinner - android:id="@+id/dateSpinner" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginBottom="8dp" - android:layout_marginEnd="8dp" - android:layout_marginLeft="8dp" - android:layout_marginRight="8dp" - android:layout_marginStart="8dp" - android:layout_weight="1" - android:visibility="gone" /> - - - </com.google.android.material.appbar.AppBarLayout> + app:layout_constraintTop_toBottomOf="@+id/banner" /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/departuresList" android:layout_width="0dp" android:layout_height="0dp" + android:layout_marginTop="8dp" android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/appbar" /> + app:layout_constraintTop_toBottomOf="@+id/banner" /> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fab" @@ -102,9 +110,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|bottom" android:layout_margin="@dimen/fab_margin" - android:layout_marginBottom="16dp" android:layout_marginEnd="16dp" + android:layout_marginBottom="16dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:srcCompat="@drawable/ic_favourite" /> + </androidx.constraintlayout.widget.ConstraintLayout> diff --git a/app/src/main/res/layout/banner.xml b/app/src/main/res/layout/banner.xml new file mode 100644 index 0000000000000000000000000000000000000000..bab4e0d40bb8ffa9eab44380fe4f7495be4acc00 --- /dev/null +++ b/app/src/main/res/layout/banner.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="120dp" + android:orientation="vertical"> + + <View + android:id="@+id/banner_separator" + android:layout_width="fill_parent" + android:layout_height="1dp" + android:background="#90909090" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintEnd_toStartOf="parent" + app:layout_constraintStart_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> + + <Button + android:id="@+id/banner_more" + style="@style/Widget.AppCompat.Button.Borderless.Colored" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:layout_marginBottom="8dp" + android:text="@string/more" + android:textAppearance="@style/TextAppearance.AppCompat.Button" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" /> + + <TextView + android:id="@+id/banner_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="16dp" + android:layout_marginTop="24dp" + android:layout_marginBottom="20dp" + android:ellipsize="end" + android:text="" + android:textAppearance="@style/TextAppearance.AppCompat.Body2" + app:layout_constraintBottom_toTopOf="@+id/banner_more" + app:layout_constraintStart_toEndOf="@+id/banner_icon" + app:layout_constraintTop_toTopOf="parent" /> + + <ImageView + android:id="@+id/banner_icon" + android:layout_width="40dp" + android:layout_height="40dp" + android:layout_marginStart="16dp" + android:layout_marginTop="8dp" + android:layout_marginBottom="8dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/ic_message" + android:contentDescription="@string/vm_message_icon" /> +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cd4e74e8f7c1bd2633436a5a744ffba86404fb05..48e08d445b8cf87419a49aa7b3d2b839a2538ba5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,7 +67,9 @@Sun <string name="summary_timetable_automatic_update">Automatically check for and download timetable updates</string> <string name="server_error">Server error</string> <string name="suggestion_row_image" translatable="false">suggestion row image</string> - <string name="nothing_found">Nothing found</string> + <string name="nothing_found">Not found</string> <string name="departures_empty_state_icon" translatable="false">departures empty state icon</string> <string name="in_a_moment">In a moment</string> + <string name="more">More</string> + <string name="vm_message_icon" translatable="false">vm message icon</string> </resources> diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 2aa35f26cd77104f979d8f986dd4469b12d46160..e45666bc1b5d4f67b6646206d6a314359479c076 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -52,4 +52,7 @@So. <string name="title_timetable_automatic_update">Automatische Updates</string> <string name="summary_timetable_automatic_update">Automatisch nach Fahrplanaktualisierungen suchen und diese herunterladen</string> <string name="server_error">Serverfehler</string> + <string name="nothing_found">Nicht gefunden</string> + <string name="in_a_moment">Gleich</string> + <string name="more">Mehr</string> </resources> diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 96a49332ee42d46b8a59b3170fcf498ed9af25f9..6a3c5754965e35da0716f027162c09739f645ae4 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -51,4 +51,7 @@dom <string name="summary_timetable_automatic_update">Controlla e scarica automaticamente gli aggiornamenti dell’orario</string> <string name="title_timetable_automatic_update">Aggiornamenti automatici</string> <string name="server_error">Errore del server</string> + <string name="nothing_found">Non trovato</string> + <string name="in_a_moment">In un momento</string> + <string name="more">Più</string> </resources> diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index afbe30f95d0afcd22d7b45bb8e25993b461c1f65..5722111696a88735ec67c0c2aff9eebd8ddc7252 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -53,4 +53,7 @@zo <string name="title_timetable_automatic_update">Automatische updates</string> <string name="summary_timetable_automatic_update">Automatisch controleren en download dienstregeling updates</string> <string name="server_error">Serverfout</string> + <string name="more">Meer</string> + <string name="in_a_moment">In een ogenblik</string> + <string name="nothing_found">Niet gevonden</string> </resources> diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 97fe20b5e0c8a07c43dbd43c33e58a095c0518db..0fc914f811da656b43c9cfe73dd1c435d79a56e1 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -52,4 +52,7 @@niedz. <string name="summary_timetable_automatic_update">Automatycznie sprawdzaj i pobieraj aktualizacje rozkładu</string> <string name="title_timetable_automatic_update">Automatyczne aktualizacje</string> <string name="server_error">Błąd servera</string> + <string name="nothing_found">Nie znaleziono</string> + <string name="in_a_moment">Za moment</string> + <string name="more">Więcej</string> </resources> \ No newline at end of file diff --git a/todo b/todo index 1e4199ff4600d6e80f16fef0c2d104e03b001001..3b10cd1dc188eb9fd7ed9924cf7063d187c750e7 100644 --- a/todo +++ b/todo @@ -14,4 +14,4 @@ v in a moment v departures sort (timeTill, onStop) : StopActivity v sort and limit search results - PEKA info -- check update (only in APK builds) +T check update (only in APK builds)