Author: Adam <git@apiote.xyz>
add searching by Open Location Code (plus code)
app/build.gradle | 6 app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt | 27 app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt | 9 app/src/main/res/values/strings.xml | 4
diff --git a/app/build.gradle b/app/build.gradle index 5ec9492ed133920795d8120614fa262639c75918..60e003d89ab7c2204cef0a159394409af656d8a8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,10 +53,14 @@ implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.core:core-splashscreen:1.0.1' implementation 'com.google.openlocationcode:openlocationcode:1.0.4' implementation 'org.osmdroid:osmdroid-android:6.1.16' - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3' implementation 'org.yaml:snakeyaml:2.0' implementation "androidx.activity:activity:1.7.1" + implementation 'com.google.openlocationcode:openlocationcode:1.0.4' + implementation project(path: ':fruchtfleisch') + + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3' + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt index 64ff4d6313c66b393f81b3b3cef4238b498227f3..d7435e1883b3960daa21fe8f5dbb1eaf3150e220 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt @@ -21,6 +21,7 @@ import androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupWithNavController import com.google.android.material.bottomnavigation.BottomNavigationView +import com.google.openlocationcode.OpenLocationCode import xyz.apiote.bimba.czwek.R import xyz.apiote.bimba.czwek.dashboard.ui.home.HomeFragment import xyz.apiote.bimba.czwek.dashboard.ui.map.MapFragment @@ -161,7 +162,31 @@ } } fun onSearchClicked(text: CharSequence?) { - showResults(ResultsActivity.Mode.MODE_SEARCH, text.toString()) + if (OpenLocationCode.isValidCode(text.toString())) { + val olc = OpenLocationCode(text.toString()) + if (!olc.isFull) { + Toast.makeText(this, getString(R.string.code_is_not_full), Toast.LENGTH_LONG).show() + return + } + val area = olc.decode() + showResults(olc.code, area.centerLatitude, area.centerLongitude) + } else { + showResults(ResultsActivity.Mode.MODE_SEARCH, text.toString()) + } + } + + private fun showResults(query: String, centerLatitude: Double, centerLongitude: Double) { + /* todo [3.1] (ux,low) animation + https://developer.android.com/guide/fragments/animate + https://github.com/raheemadamboev/fab-explosion-animation-app + */ + val intent = Intent(this, ResultsActivity::class.java).apply { + putExtra("mode", ResultsActivity.Mode.MODE_POSITION) + putExtra("query", query) + putExtra("lat", centerLatitude) + putExtra("lon", centerLongitude) + } + startActivity(intent) } private fun showResults(mode: ResultsActivity.Mode, query: String = "") { 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 0bb34efb22825f913e597157e6d40d025455559b..7a1fd06fc1660a786c460a43c62f0c99380809be 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 @@ -24,7 +24,7 @@ import java.io.InputStream class ResultsActivity : AppCompatActivity(), LocationListener { enum class Mode { - MODE_LOCATION, MODE_SEARCH + MODE_LOCATION, MODE_SEARCH, MODE_POSITION } private var _binding: ActivityResultsBinding? = null @@ -65,6 +65,13 @@ when (intent.extras?.get("mode")) { Mode.MODE_LOCATION -> { supportActionBar?.title = getString(R.string.stops_nearby) locate() + } + Mode.MODE_POSITION -> { + val query = intent.extras?.getString("query") + val lat = intent.extras?.getDouble("lat") + val lon = intent.extras?.getDouble("lon") + supportActionBar?.title = getString(R.string.stops_near_code, query) + getQueryablesByLocation(Server.get(this), PositionV1(lat!!, lon!!)) } Mode.MODE_SEARCH -> { val query = intent.extras?.getString("query")!! diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dc1fabe61fcce23886a57900cd2a55d6ab034a2d..3254f20c981d230bde33e2f2c049458a0222176b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,7 +4,7 @@Home <string name="title_map">Map</string> <string name="title_voyage">Voyage</string> <string name="home_fab_description">GPS icon</string> - <string name="search_placeholder">Search stops and lines</string> + <string name="search_placeholder">Search stops or plus codes</string> <!-- and lines --> <string name="title_activity_results">Results</string> <string name="cont">Continue</string> <string name="save">Save</string> @@ -84,4 +84,6 @@Servers <string name="title_cities">Cities</string> <string name="error_url">Malformed URL provided</string> <string name="error_traffic_spec">Cannot verify traffic server</string> + <string name="stops_near_code">Stops near %1$s</string> + <string name="code_is_not_full">Code is not full</string> </resources> \ No newline at end of file