From 05104acbe9c1ac106cfc416bd966366088c642dc Mon Sep 17 00:00:00 2001
From: 0ceanSlim <89587889+0ceanSlim@users.noreply.github.com>
Date: Sat, 29 Jul 2023 18:34:00 -0400
Subject: [PATCH] css split from html, accounted for in MainActivity and
working
---
app/src/main/assets/index.html | 15 ++++++++
app/src/main/assets/script.js | 10 ++++++
app/src/main/assets/style.css | 35 +++++++++++++++++++
.../com/example/satsmonitor/MainActivity.kt | 29 ++++++++++++---
4 files changed, 84 insertions(+), 5 deletions(-)
create mode 100644 app/src/main/assets/index.html
create mode 100644 app/src/main/assets/script.js
create mode 100644 app/src/main/assets/style.css
diff --git a/app/src/main/assets/index.html b/app/src/main/assets/index.html
new file mode 100644
index 0000000..5781fde
--- /dev/null
+++ b/app/src/main/assets/index.html
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
Bitcoin Price Tracker
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/assets/script.js b/app/src/main/assets/script.js
new file mode 100644
index 0000000..b2cb2c0
--- /dev/null
+++ b/app/src/main/assets/script.js
@@ -0,0 +1,10 @@
+// Fetch the Bitcoin price from the CoinGecko API
+fetch('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd')
+ .then(response => response.json())
+ .then(data => {
+ const bitcoinPrice = data['bitcoin']['usd'];
+ // Update the Bitcoin price on the website
+ const bitcoinPriceElement = document.getElementById('bitcoin-price');
+ bitcoinPriceElement.textContent = '1 BTC = $' + bitcoinPrice.toFixed(2); // Display the Bitcoin price
+ })
+ .catch(error => console.error(error));
diff --git a/app/src/main/assets/style.css b/app/src/main/assets/style.css
new file mode 100644
index 0000000..0d95482
--- /dev/null
+++ b/app/src/main/assets/style.css
@@ -0,0 +1,35 @@
+/* CSS styles for the Bitcoin Price Tracker */
+body {
+ margin: 0;
+ padding: 0;
+ background: #252525;
+ color: #ffffff;
+ font-family: monospace, Arial;
+ font-size: 12px;
+ font-feature-settings: normal;
+ overflow-x: hidden;
+ text-align: center;
+}
+
+.bitcointodollars {
+ width: auto;
+ margin-left: 20px;
+ margin-right: 20px;
+ margin-top: 20px;
+ background-color: #252525;
+ border: 1px solid #ccc;
+ border-radius: 8px;
+ padding: 10px;
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
+}
+
+h1 {
+ color: #ff7500;
+}
+
+#bitcoin-price {
+ font-size: 24px;
+ font-weight: bold;
+ text-align: center;
+ margin: 10px;
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/satsmonitor/MainActivity.kt b/app/src/main/java/com/example/satsmonitor/MainActivity.kt
index c6ba584..c02e5ba 100644
--- a/app/src/main/java/com/example/satsmonitor/MainActivity.kt
+++ b/app/src/main/java/com/example/satsmonitor/MainActivity.kt
@@ -24,7 +24,7 @@ class MainActivity : AppCompatActivity() {
// Clear the WebView cache (optional)
webView.clearCache(true)
- // Load the HTML content from the "bitcoin_price_tracker.html" file
+ // Load the HTML content from the "index.html" file
val htmlContent = try {
assets.open("index.html").bufferedReader().use { it.readText() }
} catch (e: IOException) {
@@ -33,7 +33,7 @@ class MainActivity : AppCompatActivity() {
"Error loading HTML
"
}
- // Load the JavaScript code from the "bitcoin_price_tracker.js" file
+ // Load the JavaScript code from the "script.js" file
val javaScriptCode = try {
assets.open("script.js").bufferedReader().use { it.readText() }
} catch (e: IOException) {
@@ -42,9 +42,28 @@ class MainActivity : AppCompatActivity() {
""
}
- // Inject the JavaScript code into the HTML content
- val finalHtmlContent = "$htmlContent"
+ // Load the CSS code from the "style.css" file
+ val cssCode = try {
+ assets.open("style.css").bufferedReader().use { it.readText() }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ // If loading CSS fails, set an empty style
+ ""
+ }
+
+ // Combine the HTML, CSS, and JavaScript code
+ val finalHtmlContent = """
+
+
+
+
+
+ $htmlContent
+
+
+
+ """.trimIndent()
webView.loadDataWithBaseURL(null, finalHtmlContent, "text/html", "UTF-8", null)
}
-}
+}
\ No newline at end of file