mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 11:39:42 +01:00
pass java to javascript params with URLEncoder
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
5da43d1760
commit
04fb57df7a
@ -59,15 +59,6 @@
|
|||||||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" static="false" />
|
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" static="false" />
|
||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
|
||||||
<value>
|
|
||||||
<package name="" alias="false" withSubpackages="true" />
|
|
||||||
<package name="java" alias="false" withSubpackages="true" />
|
|
||||||
<package name="javax" alias="false" withSubpackages="true" />
|
|
||||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
|
||||||
<package name="" alias="true" withSubpackages="true" />
|
|
||||||
</value>
|
|
||||||
</option>
|
|
||||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
|
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
|
||||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
|
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
|
||||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
|
@ -17,22 +17,25 @@
|
|||||||
<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;
|
||||||
queryString = queryString.substring(1);
|
|
||||||
var params = queryString.split(",");
|
|
||||||
var lat = params[0]
|
|
||||||
var lon = params[1]
|
|
||||||
|
|
||||||
|
const urlParams = new URLSearchParams(queryString);
|
||||||
|
var lat = urlParams.get('lat')
|
||||||
|
var lon = urlParams.get('lon')
|
||||||
|
var name = urlParams.get('name')
|
||||||
|
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 }).setView([lat, lon], 13);
|
||||||
map.dragging.disable();
|
map.dragging.disable();
|
||||||
|
|
||||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
L.tileLayer(mapProviderUrl, {
|
||||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© ' + mapProviderAttribution
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
L.marker([lat, lon]).addTo(map);
|
L.marker([lat, lon]).addTo(map);
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -26,7 +26,7 @@ class LeafletWebView : AppCompatActivity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.webview.loadUrl("file:///android_asset/index.html?51.5263,13.0384");
|
binding.webview.loadUrl("file:///android_asset/leafletMapMessagePreview.html?51.5263,13.0384");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ package com.nextcloud.talk.adapters.messages
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
@ -14,6 +16,7 @@ import com.nextcloud.talk.R
|
|||||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||||
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 javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication::class)
|
@AutoInjector(NextcloudTalkApplication::class)
|
||||||
@ -71,10 +74,25 @@ 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 {
|
||||||
view?.loadUrl(url)
|
return if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) {
|
||||||
return true
|
view?.context?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
webview?.loadUrl("file:///android_asset/index.html?$lat,$lon,$name");
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
||||||
|
webview?.loadUrl(urlStringBuffer.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user