[Android] Android TV: Fix the license fragment UI

diegofn git at videolan.org
Fri Jun 5 10:16:40 CEST 2020


vlc-android | branch: master | diegofn <diegofn at me.com> | Sat May 23 13:07:25 2020 -0500| [62beb99877acf6bedfa2a67b538fa9be9607a97a] | committer: Nicolas Pomepuy

Android TV: Fix the license fragment UI

(cherry picked from commit 89aae99c959097bc9cbc7a9856070597e80f9723)

> https://code.videolan.org/videolan/vlc-android/commit/62beb99877acf6bedfa2a67b538fa9be9607a97a
---

 .../org/videolan/television/ui/LicenceActivity.kt  | 35 +++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt b/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt
index ef0a196f2..4df284ab4 100644
--- a/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt
@@ -1,9 +1,12 @@
 package org.videolan.television.ui
 
+import android.annotation.SuppressLint
+import android.content.res.Configuration
 import android.graphics.Color
 import android.os.Bundle
 import android.view.View
 import android.webkit.WebView
+import android.webkit.WebViewClient
 import androidx.fragment.app.FragmentActivity
 import org.videolan.resources.util.applyOverscanMargin
 import org.videolan.vlc.R
@@ -15,9 +18,39 @@ class LicenceActivity : FragmentActivity() {
         super.onCreate(savedInstanceState)
         val revision = getString(R.string.build_revision)
         val licence = WebView(this)
-        licence.loadData(Util.readAsset("licence.htm", "").replace("!COMMITID!", revision), "text/html", "UTF8")
+
+        licence.loadUrl("file:///android_asset/licence.htm")
+
+        licence.webViewClient = object : WebViewClient() {
+
+            override fun onPageFinished(view: WebView, url: String) {
+                if (url.startsWith("file:///android_asset")) {
+                    injectCommitRevision(view, revision)
+                }
+                super.onPageFinished(view, url)
+
+            }
+        }
+
         setContentView(licence)
         (licence.parent as View).setBackgroundColor(Color.LTGRAY)
         applyOverscanMargin(this)
     }
+
+    @SuppressLint("SetJavaScriptEnabled")
+    private fun injectCommitRevision(webView: WebView, revision: String) {
+        try {
+            webView.settings.javaScriptEnabled = true
+
+            webView.loadUrl("javascript:(function() {" +
+                    "var link = document.getElementById('revision_link');" +
+                    "var newLink = link.href.replace('!COMMITID!', '$revision');" +
+                    "link.setAttribute('href', newLink);" +
+                    "link.innerText = newLink;" +
+                    "})()")
+            webView.settings.javaScriptEnabled = false
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
+    }
 }



More information about the Android mailing list