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>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="map"></div>
|
<div id="map" ></div>
|
||||||
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
|
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var queryString = window.location.search;
|
var queryString = window.location.search;
|
||||||
|
|
||||||
const urlParams = new URLSearchParams(queryString);
|
const urlParams = new URLSearchParams(queryString);
|
||||||
var lat = urlParams.get('lat')
|
var locationLat = urlParams.get('locationLat')
|
||||||
var lon = urlParams.get('lon')
|
var locationLon = urlParams.get('locationLon')
|
||||||
var name = urlParams.get('name')
|
var locationGeoLink = urlParams.get('locationGeoLink')
|
||||||
var mapProviderUrl = urlParams.get('mapProviderUrl')
|
var mapProviderUrl = urlParams.get('mapProviderUrl')
|
||||||
var mapProviderAttribution = urlParams.get('mapProviderAttribution')
|
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();
|
map.dragging.disable();
|
||||||
|
|
||||||
L.tileLayer(mapProviderUrl, {
|
L.tileLayer(mapProviderUrl, {
|
||||||
attribution: '© ' + mapProviderAttribution
|
attribution: '© ' + mapProviderAttribution
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
L.marker([lat, lon]).addTo(map);
|
L.marker([locationLat, locationLon]).addTo(map);
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -5,15 +5,18 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.webkit.WebViewClient
|
import android.webkit.WebViewClient
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
import autodagger.AutoInjector
|
import autodagger.AutoInjector
|
||||||
import butterknife.BindView
|
import butterknife.BindView
|
||||||
import butterknife.ButterKnife
|
import butterknife.ButterKnife
|
||||||
import com.nextcloud.talk.R
|
import com.nextcloud.talk.R
|
||||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||||
|
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
|
||||||
import com.nextcloud.talk.models.json.chat.ChatMessage
|
import com.nextcloud.talk.models.json.chat.ChatMessage
|
||||||
import com.stfalcon.chatkit.messages.MessageHolders
|
import com.stfalcon.chatkit.messages.MessageHolders
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
@ -25,10 +28,13 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
|
|||||||
|
|
||||||
private val TAG = "LocationMessageViewHolder"
|
private val TAG = "LocationMessageViewHolder"
|
||||||
|
|
||||||
var lon : String? = ""
|
var mapProviderUrl: String = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||||
var lat : String? = ""
|
var mapProviderAttribution: String = "OpenStreetMap contributors"
|
||||||
var name : String? = ""
|
|
||||||
var id : String? = ""
|
var locationLon: String? = ""
|
||||||
|
var locationLat: String? = ""
|
||||||
|
var locationName: String? = ""
|
||||||
|
var locationGeoLink: String? = ""
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@BindView(R.id.locationText)
|
@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) {
|
override fun onBind(message: ChatMessage) {
|
||||||
super.onBind(message)
|
super.onBind(message)
|
||||||
|
sharedApplication!!.componentApplication.inject(this)
|
||||||
// if (message.messageType == ChatMessage.MessageType.SINGLE_NC_GEOLOCATION_MESSAGE) {
|
// if (message.messageType == ChatMessage.MessageType.SINGLE_NC_GEOLOCATION_MESSAGE) {
|
||||||
// Log.d(TAG, "handle geolocation here")
|
// Log.d(TAG, "handle geolocation here")
|
||||||
// messageText!!.text = "geolocation..."
|
// messageText!!.text = "geolocation..."
|
||||||
@ -60,11 +67,10 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
|
|||||||
for (key in message.messageParameters.keys) {
|
for (key in message.messageParameters.keys) {
|
||||||
val individualHashMap: Map<String, String> = message.messageParameters[key]!!
|
val individualHashMap: Map<String, String> = message.messageParameters[key]!!
|
||||||
if (individualHashMap["type"] == "geo-location") {
|
if (individualHashMap["type"] == "geo-location") {
|
||||||
lon = individualHashMap["longitude"]
|
locationLon = individualHashMap["longitude"]
|
||||||
lat = individualHashMap["latitude"]
|
locationLat = individualHashMap["latitude"]
|
||||||
name = individualHashMap["name"]
|
locationName = individualHashMap["name"]
|
||||||
id = individualHashMap["id"]
|
locationGeoLink = individualHashMap["id"]
|
||||||
Log.d(TAG, "lon $lon lat $lat name $name id $id")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,7 +80,8 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
|
|||||||
|
|
||||||
webview?.webViewClient = object : WebViewClient() {
|
webview?.webViewClient = object : WebViewClient() {
|
||||||
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
|
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)))
|
view?.context?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
@ -84,15 +91,38 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
|
|||||||
}
|
}
|
||||||
|
|
||||||
val urlStringBuffer = StringBuffer("file:///android_asset/leafletMapMessagePreview.html")
|
val urlStringBuffer = StringBuffer("file:///android_asset/leafletMapMessagePreview.html")
|
||||||
urlStringBuffer.append("?mapProviderUrl=" + URLEncoder.encode("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}" +
|
urlStringBuffer.append("?mapProviderUrl=" + URLEncoder.encode(mapProviderUrl))
|
||||||
".png"))
|
urlStringBuffer.append("&mapProviderAttribution=" + URLEncoder.encode(mapProviderAttribution))
|
||||||
urlStringBuffer.append("&mapProviderAttribution=" + URLEncoder.encode("<a href=\"https://www.openstreetmap" +
|
urlStringBuffer.append("&locationLat=" + URLEncoder.encode(locationLat))
|
||||||
".org/copyright\">OpenStreetMap</a> contributors"))
|
urlStringBuffer.append("&locationLon=" + URLEncoder.encode(locationLon))
|
||||||
urlStringBuffer.append("&lat=" + URLEncoder.encode(lat))
|
urlStringBuffer.append("&locationName=" + URLEncoder.encode(locationName))
|
||||||
urlStringBuffer.append("&lon=" + URLEncoder.encode(lon))
|
urlStringBuffer.append("&locationGeoLink=" + URLEncoder.encode(locationGeoLink))
|
||||||
urlStringBuffer.append("&name=" + URLEncoder.encode(name))
|
|
||||||
|
|
||||||
|
|
||||||
webview?.loadUrl(urlStringBuffer.toString())
|
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