Close StopInfoWindow on click on map

Upgrade dependencies
This commit is contained in:
oupson 2022-02-18 01:38:53 +01:00
parent 5802c52b97
commit 6e8660a7be
7 changed files with 42 additions and 16 deletions

View File

@ -44,10 +44,10 @@ android {
dependencies { dependencies {
implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.4.0' implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2' implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'androidx.preference:preference-ktx:1.2.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

View File

@ -3,7 +3,9 @@ package fr.oupson.taotoolbox.activities
import android.Manifest import android.Manifest
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteDatabase
import android.graphics.* import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.MenuItem import android.view.MenuItem
@ -26,10 +28,12 @@ import fr.oupson.taotoolbox.windows.StopInfoWindow
import kotlinx.coroutines.* import kotlinx.coroutines.*
import org.json.JSONArray import org.json.JSONArray
import org.osmdroid.config.Configuration import org.osmdroid.config.Configuration
import org.osmdroid.events.MapEventsReceiver
import org.osmdroid.tileprovider.tilesource.XYTileSource import org.osmdroid.tileprovider.tilesource.XYTileSource
import org.osmdroid.util.GeoPoint import org.osmdroid.util.GeoPoint
import org.osmdroid.views.CustomZoomButtonsController import org.osmdroid.views.CustomZoomButtonsController
import org.osmdroid.views.overlay.CopyrightOverlay import org.osmdroid.views.overlay.CopyrightOverlay
import org.osmdroid.views.overlay.MapEventsOverlay
import org.osmdroid.views.overlay.Marker import org.osmdroid.views.overlay.Marker
import org.osmdroid.views.overlay.Polyline import org.osmdroid.views.overlay.Polyline
import org.osmdroid.views.overlay.compass.CompassOverlay import org.osmdroid.views.overlay.compass.CompassOverlay
@ -84,7 +88,6 @@ class MainActivity : AppCompatActivity() {
binding.loadingProgressBar.visibility = View.VISIBLE binding.loadingProgressBar.visibility = View.VISIBLE
binding.map.setTileSource( binding.map.setTileSource(
XYTileSource( XYTileSource(
"osm fr", 1, 19, 256, ".png", "osm fr", 1, 19, 256, ".png",
@ -143,7 +146,6 @@ class MainActivity : AppCompatActivity() {
binding.map.overlays.add(compassOverlay) binding.map.overlays.add(compassOverlay)
binding.map.apply { binding.map.apply {
controller.setZoom(15.0) controller.setZoom(15.0)
controller.animateTo(GeoPoint(47.90250000, 1.90888889)) controller.animateTo(GeoPoint(47.90250000, 1.90888889))
@ -153,10 +155,22 @@ class MainActivity : AppCompatActivity() {
} }
} }
private suspend fun buildMarkerOverlays(db: SQLiteDatabase) { private suspend fun buildMarkerOverlays(db: SQLiteDatabase) {
val infoWindow = StopInfoWindow(binding.map, taoRestApi) val infoWindow = StopInfoWindow(binding.map, taoRestApi)
val mapEventsOverlay = MapEventsOverlay(object : MapEventsReceiver {
override fun singleTapConfirmedHelper(p: GeoPoint?): Boolean {
infoWindow.close()
return true
}
override fun longPressHelper(p: GeoPoint?): Boolean {
return false
}
})
binding.map.overlays.add(0, mapEventsOverlay)
val cursor = db.query( val cursor = db.query(
StopEntry.TABLE_NAME, StopEntry.TABLE_NAME,
arrayOf( arrayOf(
@ -274,6 +288,7 @@ class MainActivity : AppCompatActivity() {
permissions: Array<String?>, permissions: Array<String?>,
grantResults: IntArray grantResults: IntArray
) { ) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when (requestCode) { when (requestCode) {
REQUEST_PERMISSIONS_REQUEST_CODE -> { REQUEST_PERMISSIONS_REQUEST_CODE -> {
val res = grantResults.getOrNull(0) val res = grantResults.getOrNull(0)

View File

@ -65,6 +65,7 @@ class RealTimeAdapter(
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
scheduleImageView.setImageBitmap(btm) scheduleImageView.setImageBitmap(btm)
} }
} }
} }
} }

View File

@ -1,6 +1,7 @@
package fr.oupson.taotoolbox.windows package fr.oupson.taotoolbox.windows
import android.widget.TextView import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import fr.oupson.common.api.RealtimeStopArea import fr.oupson.common.api.RealtimeStopArea
@ -44,11 +45,20 @@ class StopInfoWindow(
titleTextView.text = item.title titleTextView.text = item.title
GlobalScope.launch(windowsContext) { GlobalScope.launch(windowsContext) {
val realtime = taoRestApi.getRealtimeByStopArea(id) try {
val realtime = taoRestApi.getRealtimeByStopArea(id)
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
realtimeList.set(realtime) realtimeList.set(realtime)
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
}
} catch (e: Exception) {
e.printStackTrace()
Toast.makeText(
titleTextView.context,
"Failed to retrieve data", // TODO
Toast.LENGTH_SHORT
).show()
} }
} }
} }

View File

@ -7,7 +7,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.0.4' classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

View File

@ -33,8 +33,8 @@ android {
dependencies { dependencies {
implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.4.0' implementation 'com.google.android.material:material:1.5.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip