From 11a0c7beeed4814046df462680b2917580b49ba5 Mon Sep 17 00:00:00 2001 From: 0ceanSlim <89587889+0ceanSlim@users.noreply.github.com> Date: Sat, 29 Jul 2023 12:34:46 -0400 Subject: [PATCH] pulled out html and javascript to their own respective files in assets folder under main --- .../com/example/satsmonitor/MainActivity.kt | 83 +++++-------------- 1 file changed, 22 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/com/example/satsmonitor/MainActivity.kt b/app/src/main/java/com/example/satsmonitor/MainActivity.kt index d3a35a4..c6ba584 100644 --- a/app/src/main/java/com/example/satsmonitor/MainActivity.kt +++ b/app/src/main/java/com/example/satsmonitor/MainActivity.kt @@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.webkit.WebView import android.webkit.WebSettings +import java.io.IOException class MainActivity : AppCompatActivity() { @@ -23,67 +24,27 @@ class MainActivity : AppCompatActivity() { // Clear the WebView cache (optional) webView.clearCache(true) - // Load the HTML content with the embedded script and CSS - val htmlContent = """ - - - - - -
-

Bitcoin Price Tracker

-
- -
- - """ + // Load the HTML content from the "bitcoin_price_tracker.html" file + val htmlContent = try { + assets.open("index.html").bufferedReader().use { it.readText() } + } catch (e: IOException) { + e.printStackTrace() + // If loading HTML fails, set some default content + "

Error loading HTML

" + } - webView.loadDataWithBaseURL(null, htmlContent, "text/html", "UTF-8", null) + // Load the JavaScript code from the "bitcoin_price_tracker.js" file + val javaScriptCode = try { + assets.open("script.js").bufferedReader().use { it.readText() } + } catch (e: IOException) { + e.printStackTrace() + // If loading JavaScript fails, set an empty script + "" + } + + // Inject the JavaScript code into the HTML content + val finalHtmlContent = "$htmlContent" + + webView.loadDataWithBaseURL(null, finalHtmlContent, "text/html", "UTF-8", null) } - - }