Author: Adam Pioterek <adam.pioterek@protonmail.ch>
empty search results
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt index fc989f80021d22302dd3b2e0eaae97bc78aeec8c..7391042e6767d1b2b6820d472a9b7f3048a5582b 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt @@ -2,31 +2,43 @@ package ml.adamsprogs.bimba.activities import android.annotation.SuppressLint import android.app.Activity -import android.content.* -import android.os.* +import android.content.Context +import android.content.DialogInterface +import android.content.Intent +import android.content.IntentFilter +import android.os.Bundle import android.preference.PreferenceManager.getDefaultSharedPreferences import android.text.Editable -import androidx.appcompat.app.* import android.text.TextWatcher -import android.view.* +import android.view.ActionMode +import android.view.Menu +import android.view.MenuItem +import android.view.View import android.view.inputmethod.InputMethodManager -import kotlin.collections.ArrayList -import kotlinx.android.synthetic.main.activity_dash.* -import java.util.* -import java.text.* - -import ml.adamsprogs.bimba.models.* -import ml.adamsprogs.bimba.* -import ml.adamsprogs.bimba.datasources.* -import ml.adamsprogs.bimba.models.suggestions.* -import ml.adamsprogs.bimba.models.adapters.* -import ml.adamsprogs.bimba.collections.* - +import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity import com.google.android.material.navigation.NavigationView import com.google.android.material.snackbar.Snackbar import com.mancj.materialsearchbar.MaterialSearchBar import com.mancj.materialsearchbar.MaterialSearchBar.BUTTON_BACK import com.mancj.materialsearchbar.MaterialSearchBar.BUTTON_NAVIGATION +import kotlinx.android.synthetic.main.activity_dash.* +import ml.adamsprogs.bimba.* +import ml.adamsprogs.bimba.collections.FavouriteStorage +import ml.adamsprogs.bimba.datasources.TimetableDownloader +import ml.adamsprogs.bimba.datasources.VmService +import ml.adamsprogs.bimba.models.Departure +import ml.adamsprogs.bimba.models.Plate +import ml.adamsprogs.bimba.models.Timetable +import ml.adamsprogs.bimba.models.adapters.FavouritesAdapter +import ml.adamsprogs.bimba.models.adapters.SuggestionsAdapter +import ml.adamsprogs.bimba.models.suggestions.EmptySuggestion +import ml.adamsprogs.bimba.models.suggestions.GtfsSuggestion +import ml.adamsprogs.bimba.models.suggestions.LineSuggestion +import ml.adamsprogs.bimba.models.suggestions.StopSuggestion +import java.text.DateFormat +import java.util.* +import kotlin.collections.ArrayList class DashActivity : AppCompatActivity(), MessageReceiver.OnTimetableDownloadListener, FavouritesAdapter.OnMenuItemClickListener, FavouritesAdapter.ViewHolder.OnClickListener, ProviderProxy.OnDeparturesReadyListener, SuggestionsAdapter.OnSuggestionClickListener { @@ -100,6 +112,8 @@ if (searchView.isSearchEnabled) { searchView.clearSuggestions() searchView.updateLastSuggestions(listOf<GtfsSuggestion>()) providerProxy.getSuggestions(s.toString()) { suggestions -> + if(suggestions.isEmpty()) + suggestionsAdapter.addSuggestion(EmptySuggestion()) suggestions.forEach { if (it.name.contains(s as CharSequence, true)) { suggestionsAdapter.addSuggestion(it) diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/adapters/SuggestionsAdapter.kt b/app/src/main/java/ml/adamsprogs/bimba/models/adapters/SuggestionsAdapter.kt index 4f3a969d6d688d1db3201aa44f9d942b9fa0a743..4183ab57cfb227b61c4c0875ac5c32131c617d38 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/adapters/SuggestionsAdapter.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/adapters/SuggestionsAdapter.kt @@ -33,10 +33,10 @@ holder!!.root.setOnClickListener { onSuggestionClickListener.onSuggestionClickListener(suggestion) } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - holder.text.text = Html.fromHtml(suggestion.getBody(), Html.FROM_HTML_MODE_LEGACY) + holder.text.text = Html.fromHtml(suggestion.getBody(context), Html.FROM_HTML_MODE_LEGACY) } else { @Suppress("DEPRECATION") - holder.text.text = Html.fromHtml(suggestion.getBody()) + holder.text.text = Html.fromHtml(suggestion.getBody(context)) } holder.text.setTextColor(getColor(context, R.color.textDark)) diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/EmptySuggestion.kt b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/EmptySuggestion.kt new file mode 100644 index 0000000000000000000000000000000000000000..6d1ae4255e29b82a47db5d82c5261e273dad8f82 --- /dev/null +++ b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/EmptySuggestion.kt @@ -0,0 +1,37 @@ +package ml.adamsprogs.bimba.models.suggestions + +import android.content.Context +import ml.adamsprogs.bimba.R + +class EmptySuggestion : GtfsSuggestion("Empty") { + override fun equals(other: Any?): Boolean { + return other != null && other is EmptySuggestion + } + + override fun getIcon(): Int { + return R.drawable.ic_error_outline + } + + override fun getColour(): Int { + return 0xffffff + } + + override fun getBgColour(): Int { + return 0x000000 + } + + override fun getBody(context: Context): String { + return context.getString(R.string.nothing_found) + } + + override fun compareTo(other: GtfsSuggestion): Int { + return if (other is EmptySuggestion) + 0 + else + -1 + } + + override fun hashCode(): Int { + return name.hashCode() + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/GtfsSuggestion.kt b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/GtfsSuggestion.kt index da730c9e177b77109707e111e790a19a59f0f3ec..06338fb9e936e9f0580b142ef5995ed419508c5a 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/GtfsSuggestion.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/GtfsSuggestion.kt @@ -1,5 +1,7 @@ package ml.adamsprogs.bimba.models.suggestions +import android.content.Context + abstract class GtfsSuggestion(val name: String) : Comparable<GtfsSuggestion> { abstract fun getIcon(): Int @@ -7,5 +9,9 @@ abstract fun getColour(): Int abstract fun getBgColour(): Int - abstract fun getBody(): String + abstract fun getBody(context: Context): String + + abstract override fun equals(other: Any?): Boolean + + abstract override fun hashCode(): Int } \ No newline at end of file diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/LineSuggestion.kt b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/LineSuggestion.kt index 1014c31c25da4d8e854c5e035df24eba42fa9ea9..b6b11e162b21b5beb4d5b85e276fdcc156e4f408 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/LineSuggestion.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/LineSuggestion.kt @@ -1,5 +1,6 @@ package ml.adamsprogs.bimba.models.suggestions +import android.content.Context import ml.adamsprogs.bimba.R import ml.adamsprogs.bimba.models.gtfs.Route @@ -12,7 +13,7 @@ else -> R.drawable.ic_vehicle } } - override fun getBody(): String { + override fun getBody(context: Context): String { return name } diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/StopSuggestion.kt b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/StopSuggestion.kt index 708daa18b82fe5d4eb5d9b3b9cefd743d7852fb7..88c4f19b68dc32e2d87aee7437e21870d9fc7093 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/StopSuggestion.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/StopSuggestion.kt @@ -1,10 +1,11 @@ package ml.adamsprogs.bimba.models.suggestions +import android.content.Context import ml.adamsprogs.bimba.R class StopSuggestion(name: String, val zone: String) : GtfsSuggestion(name) { - override fun getBody(): String { + override fun getBody(context: Context): String { return name } diff --git a/app/src/main/res/drawable/ic_error_outline.xml b/app/src/main/res/drawable/ic_error_outline.xml new file mode 100644 index 0000000000000000000000000000000000000000..a07a0f90acf868ee9698d8f7b559545f4984939d --- /dev/null +++ b/app/src/main/res/drawable/ic_error_outline.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="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/> +</vector> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3d11bdcb2e8d2cba4cde3ca44df9e807a5b439e7..e4653b4fd15ae5c8ee399dd5e536d433ae6c48f0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,4 +67,5 @@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> </resources>