Skip to content
Snippets Groups Projects
Commit 89aae99c authored by Diego Fernando Nieto's avatar Diego Fernando Nieto
Browse files

Android TV: Fix the license fragment UI

parent adadbfd9
No related branches found
No related tags found
No related merge requests found
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()
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment