|
@@ -27,6 +27,7 @@ import androidx.core.view.WindowInsetsCompat
|
|
|
import androidx.core.view.updateLayoutParams
|
|
|
import androidx.core.view.updatePadding
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
+import com.google.openlocationcode.OpenLocationCode
|
|
|
import kotlinx.coroutines.MainScope
|
|
|
import kotlinx.coroutines.Runnable
|
|
|
import kotlinx.coroutines.launch
|
|
@@ -42,7 +43,7 @@ import xyz.apiote.bimba.czwek.settings.feeds.FeedsSettings
|
|
|
|
|
|
class ResultsActivity : AppCompatActivity(), LocationListener, SensorEventListener {
|
|
|
enum class Mode {
|
|
|
- MODE_LOCATION, MODE_SEARCH, MODE_POSITION
|
|
|
+ MODE_LOCATION, MODE_SEARCH, MODE_POSITION, MODE_SHORT_CODE_LOCATION, MODE_SHORT_CODE
|
|
|
}
|
|
|
|
|
|
private var _binding: ActivityResultsBinding? = null
|
|
@@ -54,6 +55,7 @@ class ResultsActivity : AppCompatActivity(), LocationListener, SensorEventListen
|
|
|
private var runnable = Runnable {}
|
|
|
private var gravity: FloatArray? = null
|
|
|
private var geomagnetic: FloatArray? = null
|
|
|
+ private var shortOLC: OpenLocationCode? = null
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
enableEdgeToEdge()
|
|
@@ -88,6 +90,30 @@ class ResultsActivity : AppCompatActivity(), LocationListener, SensorEventListen
|
|
|
locate()
|
|
|
}
|
|
|
|
|
|
+ Mode.MODE_SHORT_CODE_LOCATION -> {
|
|
|
+ val query = intent.extras?.getString("query")
|
|
|
+ getString(R.string.stops_near_code, query)
|
|
|
+ shortOLC = OpenLocationCode(query)
|
|
|
+ locate()
|
|
|
+ }
|
|
|
+
|
|
|
+ Mode.MODE_SHORT_CODE -> {
|
|
|
+ val query = intent.extras?.getString("query")
|
|
|
+ val split = query!!.trim().split(" ")
|
|
|
+ val code = split.first().trim(',').trim()
|
|
|
+ val freePart = split.drop(1).joinToString(" ")
|
|
|
+ val location = findPlace(this, freePart)
|
|
|
+ if (location == null) {
|
|
|
+ showError(Error(0, R.string.error_geocoding, R.drawable.geocoding))
|
|
|
+ } else {
|
|
|
+ val area = OpenLocationCode(code).recover(location.latitude, location.longitude).decode()
|
|
|
+ getQueryablesByLocation(Location(null).apply {
|
|
|
+ latitude = area.centerLatitude
|
|
|
+ longitude = area.centerLongitude
|
|
|
+ }, this)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Mode.MODE_POSITION -> {
|
|
|
val query = intent.extras?.getString("query")
|
|
|
val lat = intent.extras?.getDouble("lat")
|
|
@@ -142,7 +168,15 @@ class ResultsActivity : AppCompatActivity(), LocationListener, SensorEventListen
|
|
|
|
|
|
override fun onLocationChanged(location: Location) {
|
|
|
handler.removeCallbacks(runnable)
|
|
|
- getQueryablesByLocation(location, this, true)
|
|
|
+ val area = shortOLC?.recover(location.latitude, location.longitude)?.decode()
|
|
|
+ if (area != null) {
|
|
|
+ getQueryablesByLocation(Location(null).apply {
|
|
|
+ latitude = area.centerLatitude
|
|
|
+ longitude = area.centerLongitude
|
|
|
+ }, this, false)
|
|
|
+ } else {
|
|
|
+ getQueryablesByLocation(location, this, true)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {}
|
|
@@ -155,7 +189,7 @@ class ResultsActivity : AppCompatActivity(), LocationListener, SensorEventListen
|
|
|
if (success) {
|
|
|
val orientation = FloatArray(3)
|
|
|
SensorManager.getOrientation(r, orientation)
|
|
|
- adapter.update((orientation[0]*180/Math.PI).toFloat())
|
|
|
+ adapter.update((orientation[0] * 180 / Math.PI).toFloat())
|
|
|
}
|
|
|
}
|
|
|
}
|