refresh
This commit is contained in:
commit
1f1ac760ca
@ -2,10 +2,14 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
<<<<<<< HEAD
|
||||||
<!--<link rel="stylesheet" type="text/css" href="themes/*">
|
<!--<link rel="stylesheet" type="text/css" href="themes/*">
|
||||||
<link rel="stylesheet" type="text/css" href="styles/*">-->
|
<link rel="stylesheet" type="text/css" href="styles/*">-->
|
||||||
<link rel="stylesheet" type="text/css" href="style/output.css">
|
<link rel="stylesheet" type="text/css" href="style/output.css">
|
||||||
|
=======
|
||||||
|
>>>>>>> 444601f0cb9165b77f4c460bdf72f1cb567eb544
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" type="text/css" href="themes/Dark.css">
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-black">
|
<body class="bg-black">
|
||||||
|
|
||||||
@ -14,10 +18,10 @@
|
|||||||
<div class="theme-dropdown">
|
<div class="theme-dropdown">
|
||||||
<label for="theme-select"> </label>
|
<label for="theme-select"> </label>
|
||||||
<select id="theme-select">
|
<select id="theme-select">
|
||||||
<option value="Dark">Dark</option>
|
<option value="Dark.css">Dark</option>
|
||||||
<option value="Lava">Lava</option>
|
<option value="Lava.css">Lava</option>
|
||||||
<option value="Midnight">Midnight</option>
|
<option value="Midnight.css">Midnight</option>
|
||||||
<option value="Solar">Solar</option>
|
<option value="Solar.css">Solar</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="currency-dropdown">
|
<div class="currency-dropdown">
|
||||||
@ -82,4 +86,5 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
20
app/src/main/assets/scripts/selectTheme.js
Normal file
20
app/src/main/assets/scripts/selectTheme.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Function to change the theme based on the selected option
|
||||||
|
function changeTheme() {
|
||||||
|
console.log("changeTheme() called"); // Add this line
|
||||||
|
var themeSelect = document.getElementById("theme-select");
|
||||||
|
var selectedTheme = themeSelect.value;
|
||||||
|
|
||||||
|
// Construct the theme CSS file path based on the selected theme
|
||||||
|
var themeCSSFile = "themes/" + selectedTheme + ".css";
|
||||||
|
|
||||||
|
// Set the theme CSS file as the stylesheet link's href
|
||||||
|
var styleSheet = document.querySelector('link[href^="themes/"]');
|
||||||
|
styleSheet.href = themeCSSFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add an event listener to the theme dropdown to change the theme on selection change
|
||||||
|
document.getElementById("theme-select").addEventListener("change", changeTheme);
|
||||||
|
|
||||||
|
// Initial theme setup when the page loads
|
||||||
|
console.log("Initial theme setup"); // Add this line
|
||||||
|
changeTheme(); // This line was missing in your previous code
|
@ -10,6 +10,7 @@ import java.io.IOException
|
|||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var webView: WebView
|
private lateinit var webView: WebView
|
||||||
|
private lateinit var currentThemeCSSCode: String
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@ -26,17 +27,42 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Clear the WebView cache (optional)
|
// Clear the WebView cache (optional)
|
||||||
webView.clearCache(true)
|
webView.clearCache(true)
|
||||||
|
|
||||||
// Load the HTML content from the "app.html" file
|
// Initialize with the default theme
|
||||||
|
currentThemeCSSCode = loadThemeCSS("themes/Dark.css")
|
||||||
|
loadWebViewWithTheme(currentThemeCSSCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to load WebView with the specified CSS theme code
|
||||||
|
private fun loadWebViewWithTheme(cssCode: String) {
|
||||||
|
val assetManager = assets
|
||||||
|
|
||||||
|
// Load the HTML content
|
||||||
val htmlContent = try {
|
val htmlContent = try {
|
||||||
// Load the HTML content from the "app.html" file
|
assetManager.open("app.html").bufferedReader().use { it.readText() }
|
||||||
assets.open("app.html").bufferedReader().use { it.readText() }
|
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
// If loading HTML fails, set some default content
|
|
||||||
"<html><body><h1>Error loading HTML</h1></body></html>"
|
"<html><body><h1>Error loading HTML</h1></body></html>"
|
||||||
}
|
}
|
||||||
|
|
||||||
val assetManager = assets
|
// Load all styles from the 'styles' directory
|
||||||
|
val styleFiles = listOf(
|
||||||
|
"styles/settings.css",
|
||||||
|
"styles/bitcoinPrice.css",
|
||||||
|
"styles/exchange.css",
|
||||||
|
"styles/fiatToSats.css",
|
||||||
|
"styles/satsToFiat.css"
|
||||||
|
)
|
||||||
|
|
||||||
|
val styleContents = styleFiles.map { fileName ->
|
||||||
|
try {
|
||||||
|
assetManager.open(fileName).bufferedReader().use { it.readText() }
|
||||||
|
} catch (e: IOException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
"/* Error loading style: $fileName */"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the JavaScript code
|
||||||
val scriptFiles = listOf(
|
val scriptFiles = listOf(
|
||||||
"scripts/selectTheme.js",
|
"scripts/selectTheme.js",
|
||||||
"scripts/viewBitcoinPrice.js",
|
"scripts/viewBitcoinPrice.js",
|
||||||
@ -54,6 +80,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
val cssFiles = listOf(
|
val cssFiles = listOf(
|
||||||
"style/output.css"
|
"style/output.css"
|
||||||
//"themes/Dark.css",
|
//"themes/Dark.css",
|
||||||
@ -76,13 +103,18 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> 444601f0cb9165b77f4c460bdf72f1cb567eb544
|
||||||
val javaScriptCode = scriptContents.joinToString("\n")
|
val javaScriptCode = scriptContents.joinToString("\n")
|
||||||
|
|
||||||
// Combine the HTML, CSS, and JavaScript code
|
// Combine the HTML, CSS, and JavaScript code
|
||||||
val finalHtmlContent = """
|
val finalHtmlContent = """
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<style type="text/css">$cssCode</style>
|
<style type="text/css">
|
||||||
|
${styleContents.joinToString("\n")}
|
||||||
|
$cssCode
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
$htmlContent
|
$htmlContent
|
||||||
@ -94,6 +126,21 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Define the base URL for resolving relative paths (e.g., image source)
|
// Define the base URL for resolving relative paths (e.g., image source)
|
||||||
val baseUrl = "file:///android_asset/"
|
val baseUrl = "file:///android_asset/"
|
||||||
|
|
||||||
|
// Load the WebView with the HTML content and selected theme
|
||||||
webView.loadDataWithBaseURL(null, finalHtmlContent, "text/html", "UTF-8", null)
|
webView.loadDataWithBaseURL(null, finalHtmlContent, "text/html", "UTF-8", null)
|
||||||
|
|
||||||
|
// Update the current theme CSS code
|
||||||
|
currentThemeCSSCode = cssCode
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to load CSS content from a file
|
||||||
|
private fun loadThemeCSS(cssFile: String): String {
|
||||||
|
val assetManager = assets
|
||||||
|
return try {
|
||||||
|
assetManager.open(cssFile).bufferedReader().use { it.readText() }
|
||||||
|
} catch (e: IOException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
"/* Error loading $cssFile */"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user