Browse Source

wip. show leaflet inside webview in message

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 4 years ago
parent
commit
5da43d1760

+ 5 - 5
app/src/main/assets/index.html

@@ -20,19 +20,19 @@
 
             var queryString = window.location.search;
             queryString = queryString.substring(1);
-            var coords = queryString.split(",");
+            var params = queryString.split(",");
+            var lat = params[0]
+            var lon = params[1]
 
 
-            var map = L.map('map', { zoomControl: false }).setView([coords[0], coords[1]], 13);
+            var map = L.map('map', { zoomControl: false }).setView([lat, lon], 13);
             map.dragging.disable();
 
             L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                 attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
             }).addTo(map);
 
-            L.marker([coords[0], coords[1]]).addTo(map)
-                .bindPopup('popup')
-                .openPopup();
+            L.marker([lat, lon]).addTo(map);
         </script>
     </body>
 </html>

+ 34 - 8
app/src/main/java/com/nextcloud/talk/adapters/messages/LocationMessageViewHolder.kt

@@ -4,6 +4,8 @@ import android.annotation.SuppressLint
 import android.content.Context
 import android.util.Log
 import android.view.View
+import android.webkit.WebView
+import android.webkit.WebViewClient
 import android.widget.TextView
 import autodagger.AutoInjector
 import butterknife.BindView
@@ -20,10 +22,19 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
 
     private val TAG = "LocationMessageViewHolder"
 
+    var lon : String? = ""
+    var lat : String? = ""
+    var name : String? = ""
+    var id : String? = ""
+
     @JvmField
     @BindView(R.id.locationText)
     var messageText: TextView? = null
 
+    @JvmField
+    @BindView(R.id.webview)
+    var webview: WebView? = null
+
     @JvmField
     @Inject
     var context: Context? = null
@@ -35,20 +46,35 @@ class LocationMessageViewHolder(incomingView: View) : MessageHolders
         )
     }
 
-    @SuppressLint("SetTextI18n")
+    @SuppressLint("SetTextI18n", "SetJavaScriptEnabled")
     override fun onBind(message: ChatMessage) {
         super.onBind(message)
-        if (message.messageType == ChatMessage.MessageType.SINGLE_NC_GEOLOCATION_MESSAGE) {
-            Log.d(TAG, "handle geolocation here")
-            messageText!!.text = "geolocation..."
-        }
+        // if (message.messageType == ChatMessage.MessageType.SINGLE_NC_GEOLOCATION_MESSAGE) {
+        //     Log.d(TAG, "handle geolocation here")
+        //     messageText!!.text = "geolocation..."
+        // }
         if (message.messageParameters != null && message.messageParameters.size > 0) {
             for (key in message.messageParameters.keys) {
                 val individualHashMap: Map<String, String> = message.messageParameters[key]!!
-                val lon = individualHashMap["longitude"]
-                val lat = individualHashMap["latitude"]
-                Log.d(TAG, "lon $lon lat $lat")
+                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")
+                }
+            }
+        }
+
+
+        webview?.settings?.javaScriptEnabled = true
+
+        webview?.webViewClient = object : WebViewClient() {
+            override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
+                view?.loadUrl(url)
+                return true
             }
         }
+        webview?.loadUrl("file:///android_asset/index.html?$lat,$lon,$name");
     }
 }

+ 13 - 14
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -77,7 +77,6 @@ import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
 import com.facebook.imagepipeline.image.CloseableImage
 import com.google.android.flexbox.FlexboxLayout
 import com.nextcloud.talk.R
-import com.nextcloud.talk.activities.LeafletWebView
 import com.nextcloud.talk.activities.MagicCallActivity
 import com.nextcloud.talk.adapters.messages.LocationMessageViewHolder
 import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder
@@ -821,19 +820,19 @@ class ChatController(args: Bundle) :
     fun showShareLocationScreen() {
         Log.d(TAG, "showShareLocationScreen")
 
-        // val bundle = Bundle()
-        // bundle.putBoolean(KEY_NEW_CONVERSATION, true)
-        // router.pushController(
-        //     RouterTransaction.with(LocationController(bundle))
-        //         .pushChangeHandler(HorizontalChangeHandler())
-        //         .popChangeHandler(HorizontalChangeHandler())
-        // )
-
-        val leafletIntent = Intent(context, LeafletWebView::class.java)
-        leafletIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
-        // fullScreenImageIntent.putExtra("FILE_NAME", filename)
-        // fullScreenImageIntent.putExtra("IS_GIF", isGif(mimetype))
-        context!!.startActivity(leafletIntent)
+        val bundle = Bundle()
+        // bundle.putBoolean(, true)
+        router.pushController(
+            RouterTransaction.with(LocationController(bundle))
+                .pushChangeHandler(HorizontalChangeHandler())
+                .popChangeHandler(HorizontalChangeHandler())
+        )
+
+        // val leafletIntent = Intent(context, LeafletWebView::class.java)
+        // leafletIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+        // // fullScreenImageIntent.putExtra("FILE_NAME", filename)
+        // // fullScreenImageIntent.putExtra("IS_GIF", isGif(mimetype))
+        // context!!.startActivity(leafletIntent)
     }
 
     private fun showConversationInfoScreen() {

+ 7 - 1
app/src/main/res/layout/item_custom_location_message.xml

@@ -22,7 +22,7 @@
 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="200dp"
     xmlns:tools="http://schemas.android.com/tools"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_marginStart="16dp"
@@ -30,6 +30,12 @@
     android:layout_marginEnd="16dp"
     android:layout_marginBottom="8dp">
 
+        <WebView
+            android:id="@+id/webview"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            />
+
         <TextView
             android:id="@+id/locationText"
             android:layout_width="wrap_content"