mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
open geolink on click + minor refactoring
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
04fb57df7a
commit
7540e57dd8
@ -14,28 +14,29 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<div id="map" ></div>
|
||||
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
|
||||
<script>
|
||||
var queryString = window.location.search;
|
||||
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
var lat = urlParams.get('lat')
|
||||
var lon = urlParams.get('lon')
|
||||
var name = urlParams.get('name')
|
||||
var locationLat = urlParams.get('locationLat')
|
||||
var locationLon = urlParams.get('locationLon')
|
||||
var locationGeoLink = urlParams.get('locationGeoLink')
|
||||
var mapProviderUrl = urlParams.get('mapProviderUrl')
|
||||
var mapProviderAttribution = urlParams.get('mapProviderAttribution')
|
||||
|
||||
var map = L.map('map', { zoomControl: false }).setView([lat, lon], 13);
|
||||
var map = L.map('map', {
|
||||
zoomControl: false,
|
||||
scrollWheelZoom: false
|
||||
}).setView([locationLat, locationLon], 13);
|
||||
map.dragging.disable();
|
||||
|
||||
L.tileLayer(mapProviderUrl, {
|
||||
attribution: '© ' + mapProviderAttribution
|
||||
}).addTo(map);
|
||||
|
||||
L.marker([lat, lon]).addTo(map);
|
||||
|
||||
|
||||
L.marker([locationLat, locationLon]).addTo(map);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -5,15 +5,18 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import autodagger.AutoInjector
|
||||
import butterknife.BindView
|
||||
import butterknife.ButterKnife
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage
|
||||
import com.stfalcon.chatkit.messages.MessageHolders
|
||||
import java.net.URLEncoder
|
||||
@ -25,10 +28,13 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
|
||||
|
||||
private val TAG = "LocationMessageViewHolder"
|
||||
|
||||
var lon : String? = ""
|
||||
var lat : String? = ""
|
||||
var name : String? = ""
|
||||
var id : String? = ""
|
||||
var mapProviderUrl: String = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
var mapProviderAttribution: String = "OpenStreetMap contributors"
|
||||
|
||||
var locationLon: String? = ""
|
||||
var locationLat: String? = ""
|
||||
var locationName: String? = ""
|
||||
var locationGeoLink: String? = ""
|
||||
|
||||
@JvmField
|
||||
@BindView(R.id.locationText)
|
||||
@ -49,9 +55,10 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
|
||||
)
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n", "SetJavaScriptEnabled")
|
||||
@SuppressLint("SetTextI18n", "SetJavaScriptEnabled", "ClickableViewAccessibility")
|
||||
override fun onBind(message: ChatMessage) {
|
||||
super.onBind(message)
|
||||
sharedApplication!!.componentApplication.inject(this)
|
||||
// if (message.messageType == ChatMessage.MessageType.SINGLE_NC_GEOLOCATION_MESSAGE) {
|
||||
// Log.d(TAG, "handle geolocation here")
|
||||
// messageText!!.text = "geolocation..."
|
||||
@ -60,11 +67,10 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
|
||||
for (key in message.messageParameters.keys) {
|
||||
val individualHashMap: Map<String, String> = message.messageParameters[key]!!
|
||||
if (individualHashMap["type"] == "geo-location") {
|
||||
lon = individualHashMap["longitude"]
|
||||
lat = individualHashMap["latitude"]
|
||||
name = individualHashMap["name"]
|
||||
id = individualHashMap["id"]
|
||||
Log.d(TAG, "lon $lon lat $lat name $name id $id")
|
||||
locationLon = individualHashMap["longitude"]
|
||||
locationLat = individualHashMap["latitude"]
|
||||
locationName = individualHashMap["name"]
|
||||
locationGeoLink = individualHashMap["id"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -74,7 +80,8 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
|
||||
|
||||
webview?.webViewClient = object : WebViewClient() {
|
||||
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
|
||||
return if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) {
|
||||
return if (url != null && (url.startsWith("http://") || url.startsWith("https://"))
|
||||
) {
|
||||
view?.context?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
||||
true
|
||||
} else {
|
||||
@ -84,15 +91,38 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
|
||||
}
|
||||
|
||||
val urlStringBuffer = StringBuffer("file:///android_asset/leafletMapMessagePreview.html")
|
||||
urlStringBuffer.append("?mapProviderUrl=" + URLEncoder.encode("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}" +
|
||||
".png"))
|
||||
urlStringBuffer.append("&mapProviderAttribution=" + URLEncoder.encode("<a href=\"https://www.openstreetmap" +
|
||||
".org/copyright\">OpenStreetMap</a> contributors"))
|
||||
urlStringBuffer.append("&lat=" + URLEncoder.encode(lat))
|
||||
urlStringBuffer.append("&lon=" + URLEncoder.encode(lon))
|
||||
urlStringBuffer.append("&name=" + URLEncoder.encode(name))
|
||||
|
||||
urlStringBuffer.append("?mapProviderUrl=" + URLEncoder.encode(mapProviderUrl))
|
||||
urlStringBuffer.append("&mapProviderAttribution=" + URLEncoder.encode(mapProviderAttribution))
|
||||
urlStringBuffer.append("&locationLat=" + URLEncoder.encode(locationLat))
|
||||
urlStringBuffer.append("&locationLon=" + URLEncoder.encode(locationLon))
|
||||
urlStringBuffer.append("&locationName=" + URLEncoder.encode(locationName))
|
||||
urlStringBuffer.append("&locationGeoLink=" + URLEncoder.encode(locationGeoLink))
|
||||
|
||||
webview?.loadUrl(urlStringBuffer.toString())
|
||||
|
||||
webview?.setOnTouchListener(object : View.OnTouchListener {
|
||||
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
|
||||
when (event?.action) {
|
||||
MotionEvent.ACTION_UP -> openGeoLink()
|
||||
}
|
||||
|
||||
return v?.onTouchEvent(event) ?: true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun openGeoLink() {
|
||||
if (!locationGeoLink.isNullOrEmpty()) {
|
||||
val geoLinkWithMarker = addMarkerToGeoLink(locationGeoLink!!)
|
||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(geoLinkWithMarker))
|
||||
context!!.startActivity(browserIntent)
|
||||
} else {
|
||||
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
|
||||
Log.e(TAG, "locationGeoLink was null or empty")
|
||||
}
|
||||
}
|
||||
|
||||
private fun addMarkerToGeoLink(locationGeoLink: String): String {
|
||||
return locationGeoLink.replace("geo:", "geo:0,0?q=")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user