[Android] Fix commit link + other webview improvements

Nicolas Pomepuy git at videolan.org
Tue Sep 10 15:30:34 CEST 2019


vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue Sep 10 12:04:48 2019 +0200| [7e41d7d3de2f55f794633e061ef42698f5f011db] | committer: Geoffrey Métais

Fix commit link + other webview improvements

(cherry picked from commit f2697e19e97c9290235845ec9d9207b7a3ef3d1e)

> https://code.videolan.org/videolan/vlc-android/commit/7e41d7d3de2f55f794633e061ef42698f5f011db
---

 vlc-android/assets/licence.htm                     |  5 ++-
 vlc-android/assets/licence_dark.css                |  2 +-
 vlc-android/assets/licence_light.css               |  2 +-
 .../src/org/videolan/vlc/gui/AboutFragment.kt      | 48 +++++++++++++++-------
 4 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/vlc-android/assets/licence.htm b/vlc-android/assets/licence.htm
index ab9821b57..55b5c5ae2 100644
--- a/vlc-android/assets/licence.htm
+++ b/vlc-android/assets/licence.htm
@@ -14,7 +14,10 @@
       <h2>License</h2>
         <p>VLC for Android is licensed under the <a href="#gpl">GNU General Public License, version 3 or later</a> (herein referred to as GPL).</p>
       <h2>Sources</h2>
-        <p>The sources to this application can be retrieved at <a href="https://code.videolan.org/videolan/vlc-android/tree/!COMMITID!">https://code.videolan.org/videolan/vlc-android/tree/!COMMITID!</a>.</p>
+        <p>The sources to this application can be retrieved at <a
+                href="https://code.videolan.org/videolan/vlc-android/tree/!COMMITID!"
+                id="revision_link">https://code.videolan.org/videolan/vlc-android/tree/!COMMITID!</a>.
+        </p>
       <h2>Libraries</h2>
         <p>Some VLC plugins use external libraries that make extensive use of the following persons' or companies' code:</p>
         <ul>
diff --git a/vlc-android/assets/licence_dark.css b/vlc-android/assets/licence_dark.css
index f13165282..3598a939a 100644
--- a/vlc-android/assets/licence_dark.css
+++ b/vlc-android/assets/licence_dark.css
@@ -1 +1 @@
-html,body{color:#fafafa;background:#323232;}a:link {color: #ff7d00;}
\ No newline at end of file
+html,body{color:#fafafa;background:#323232;}a:link {color: #ff7d00;}a:visited {color: #ffca7d;}
\ No newline at end of file
diff --git a/vlc-android/assets/licence_light.css b/vlc-android/assets/licence_light.css
index 39634dc78..0344b503b 100644
--- a/vlc-android/assets/licence_light.css
+++ b/vlc-android/assets/licence_light.css
@@ -1 +1 @@
-html,body{color:#212121;background:#fafafa;}a:link {color: #ff7d00;}
\ No newline at end of file
+html,body{color:#212121;background:#fafafa;}a:link {color: #ff7d00;}a:visited {color: #ff610a;}
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.kt b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.kt
index dec548662..ed48d6bf0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.kt
@@ -41,7 +41,6 @@ import org.videolan.tools.coroutineScope
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.gui.audio.AudioPagerAdapter
 import org.videolan.vlc.gui.helpers.UiTools
-import org.videolan.vlc.util.Util
 
 private const val TAG = "VLC/AboutFragment"
 private const val MODE_TOTAL = 2 // Number of audio browser modes
@@ -80,19 +79,21 @@ class AboutFragment : Fragment() {
             webView.webViewClient = object : WebViewClient() {
 
                 override fun onPageFinished(view: WebView, url: String) {
-
-                    // Inject CSS when page is done loading
-                    injectCSS(webView, when (context?.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)) {
-                        Configuration.UI_MODE_NIGHT_YES -> {
-                            "licence_dark.css"
-                        }
-                        Configuration.UI_MODE_NIGHT_NO -> {
-                            "licence_light.css"
-                        }
-                        else -> {
-                            "licence_light.css"
-                        }
-                    })
+                    if (url.startsWith("file:///android_asset")) {
+                        // Inject CSS when page is done loading
+                        injectCSS(webView, when (context?.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)) {
+                            Configuration.UI_MODE_NIGHT_YES -> {
+                                "licence_dark.css"
+                            }
+                            Configuration.UI_MODE_NIGHT_NO -> {
+                                "licence_light.css"
+                            }
+                            else -> {
+                                "licence_light.css"
+                            }
+                        })
+                        injectCommitRevision(webView, revision)
+                    }
                     super.onPageFinished(view, url)
                 }
             }
@@ -114,7 +115,24 @@ class AboutFragment : Fragment() {
                     "style.type = 'text/css';" +
                     // Tell the browser to BASE64-decode the string into your script !!!
                     "style.innerHTML = window.atob('" + encoded + "');" +
-                    "parent.appendChild(style)" +
+                    "parent.appendChild(style);" +
+                    "})()")
+            webView.settings.javaScriptEnabled = false
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
+    }
+
+    @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) {



More information about the Android mailing list