From f8149bf5eaa46727ff96ada6115a671ba31eb7e3 Mon Sep 17 00:00:00 2001 From: Leonard Date: Tue, 13 Feb 2024 14:19:39 +0100 Subject: [PATCH 1/2] Fixed KNMI pluim and added dark mode --- .../nlweer/ui/fragments/KnmiPluimFragment.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foss/cnugteren/nlweer/ui/fragments/KnmiPluimFragment.kt b/app/src/main/java/foss/cnugteren/nlweer/ui/fragments/KnmiPluimFragment.kt index 4c70127..4619c26 100644 --- a/app/src/main/java/foss/cnugteren/nlweer/ui/fragments/KnmiPluimFragment.kt +++ b/app/src/main/java/foss/cnugteren/nlweer/ui/fragments/KnmiPluimFragment.kt @@ -1,5 +1,6 @@ package foss.cnugteren.nlweer.ui.fragments +import android.graphics.Color import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -7,6 +8,7 @@ import android.view.ViewGroup import android.webkit.WebView import android.webkit.WebViewClient import androidx.fragment.app.Fragment +import androidx.preference.PreferenceManager import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import foss.cnugteren.nlweer.MainActivity import foss.cnugteren.nlweer.R @@ -25,14 +27,23 @@ class WebClientKnmiPluim : WebViewClient() { override fun onPageFinished(view: WebView, url: String) { view.loadUrl("javascript:(function() {" + "document.getElementsByClassName('breadcrumb')[0].style.display='none';" + + "document.getElementsByClassName('weather-small')[0].style.display='none';" + "document.getElementsByClassName('site-header')[0].style.display='none';" + "document.getElementsByClassName('site-footer')[0].style.display='none';" + "document.getElementsByClassName('morelinks')[0].style.display='none';" + "document.getElementsByClassName('columns')[0].style.display='none';" + - "document.getElementsByClassName('columns')[1].style.display='none';" + + "document.getElementsByClassName('columns')[2].style.display='none';" + "document.getElementsByClassName('columns')[3].style.display='none';" + "document.getElementsByClassName('chart-legend__wrp')[0].style.display='none';" + "}\n)()") + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(view.context) + val darkMode = sharedPreferences.getString("dark_mode", "dark_mode_no") + if (darkMode == "dark_mode_yes") { + view.setBackgroundColor(Color.parseColor("#2e2e2e")); // matches Android's dark mode colours + view.loadUrl( + "javascript:document.body.style.setProperty(\"color\", \"white\");" + ); + } } } From be07e8b18fcfb528bfeedb65fb0449c39d41875e Mon Sep 17 00:00:00 2001 From: Leonard Date: Tue, 13 Feb 2024 14:21:29 +0100 Subject: [PATCH 2/2] Remove unnecessary load --- .../foss/cnugteren/nlweer/ui/fragments/KnmiPluimFragment.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/foss/cnugteren/nlweer/ui/fragments/KnmiPluimFragment.kt b/app/src/main/java/foss/cnugteren/nlweer/ui/fragments/KnmiPluimFragment.kt index 4619c26..3d3fe53 100644 --- a/app/src/main/java/foss/cnugteren/nlweer/ui/fragments/KnmiPluimFragment.kt +++ b/app/src/main/java/foss/cnugteren/nlweer/ui/fragments/KnmiPluimFragment.kt @@ -40,9 +40,6 @@ class WebClientKnmiPluim : WebViewClient() { val darkMode = sharedPreferences.getString("dark_mode", "dark_mode_no") if (darkMode == "dark_mode_yes") { view.setBackgroundColor(Color.parseColor("#2e2e2e")); // matches Android's dark mode colours - view.loadUrl( - "javascript:document.body.style.setProperty(\"color\", \"white\");" - ); } } }