Compare commits
3 Commits
f7505e8ac5
...
804592872c
Author | SHA1 | Date | |
---|---|---|---|
804592872c | |||
2175806511 | |||
17839630fd |
@ -12,7 +12,7 @@ android {
|
|||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 33
|
targetSdk = 33
|
||||||
versionCode = 7
|
versionCode = 7
|
||||||
versionName = "0.1.7"
|
versionName = "0.2.0"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,23 @@ function updateBitcoinPrice(selectedCurrency) {
|
|||||||
function handleThemeChange() {
|
function handleThemeChange() {
|
||||||
var selectedTheme = document.getElementById("theme-select").value;
|
var selectedTheme = document.getElementById("theme-select").value;
|
||||||
document.documentElement.setAttribute("data-theme", selectedTheme);
|
document.documentElement.setAttribute("data-theme", selectedTheme);
|
||||||
|
savePreference("theme", selectedTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCurrencyChange() {
|
||||||
|
var selectedCurrency = document.getElementById("currency-select").value;
|
||||||
|
savePreference("currency", selectedCurrency);
|
||||||
|
}
|
||||||
|
|
||||||
|
function savePreference(key, value) {
|
||||||
|
if (typeof Android !== 'undefined' && Android !== null) {
|
||||||
|
Android.savePreference(key, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event listener for theme select change
|
// Event listener for theme select change
|
||||||
document.getElementById("theme-select").addEventListener("change", handleThemeChange);
|
document.getElementById("theme-select").addEventListener("change", handleThemeChange);
|
||||||
|
document.getElementById("currency-select").addEventListener("change", handleCurrencyChange);
|
||||||
|
|
||||||
|
|
||||||
//function refreshBitcoinPrice(selectedCurrency) {
|
//function refreshBitcoinPrice(selectedCurrency) {
|
||||||
@ -81,6 +94,20 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
updateSatsToDollarsConversion(selectedCurrency);
|
updateSatsToDollarsConversion(selectedCurrency);
|
||||||
updateFiatToSatsConversion(selectedCurrency)
|
updateFiatToSatsConversion(selectedCurrency)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const savedTheme = (typeof Android !== 'undefined' && Android !== null) ? Android.getPreference("theme") : null;
|
||||||
|
if (savedTheme) {
|
||||||
|
document.getElementById("theme-select").value = savedTheme;
|
||||||
|
document.documentElement.setAttribute("data-theme", savedTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
const savedCurrency = (typeof Android !== 'undefined' && Android !== null) ? Android.getPreference("currency") : null;
|
||||||
|
if (savedCurrency) {
|
||||||
|
document.getElementById("currency-select").value = savedCurrency;
|
||||||
|
updateBitcoinPrice(savedCurrency);
|
||||||
|
updateFiatToSatsConversion(savedCurrency);
|
||||||
|
updateSatsToDollarsConversion(savedCurrency);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ import android.os.Bundle
|
|||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.webkit.WebSettings
|
import android.webkit.WebSettings
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import android.content.Context
|
||||||
|
import android.webkit.JavascriptInterface
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@ -23,6 +25,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val webSettings: WebSettings = webView.settings
|
val webSettings: WebSettings = webView.settings
|
||||||
webSettings.javaScriptEnabled = true
|
webSettings.javaScriptEnabled = true
|
||||||
|
|
||||||
|
// Add JavaScript interface
|
||||||
|
webView.addJavascriptInterface(WebAppInterface(this), "Android")
|
||||||
|
|
||||||
// Clear the WebView cache (optional)
|
// Clear the WebView cache (optional)
|
||||||
webView.clearCache(true)
|
webView.clearCache(true)
|
||||||
|
|
||||||
@ -84,3 +89,20 @@ class MainActivity : AppCompatActivity() {
|
|||||||
webView.loadDataWithBaseURL(null, finalHtmlContent, "text/html", "UTF-8", null)
|
webView.loadDataWithBaseURL(null, finalHtmlContent, "text/html", "UTF-8", null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class WebAppInterface(private val context: Context) {
|
||||||
|
|
||||||
|
private val sharedPreferences = context.getSharedPreferences("AppPrefs", Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
fun savePreference(key: String, value: String) {
|
||||||
|
with(sharedPreferences.edit()) {
|
||||||
|
putString(key, value)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
fun getPreference(key: String): String? {
|
||||||
|
return sharedPreferences.getString(key, null)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user