summaryrefslogtreecommitdiff
path: root/app/src/main/java/foundation
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/foundation')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt18
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt77
2 files changed, 90 insertions, 5 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt
index 6fd9470..048b58c 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt
@@ -20,6 +20,7 @@ package foundation.e.privacycentralapp
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
+import android.os.Bundle
import foundation.e.privacycentralapp.domain.usecases.GetQuickPrivacyStateUseCase
import foundation.e.privacycentralapp.domain.usecases.TrackersStatisticsUseCase
import foundation.e.privacycentralapp.widget.State
@@ -71,6 +72,9 @@ class Widget : AppWidgetProvider() {
private var state: StateFlow<State> = MutableStateFlow(State())
+ private const val DARK_TEXT_KEY = "foundation.e.blisslauncher.WIDGET_OPTION_DARK_TEXT"
+ var isDarkText = false
+
private fun initState(
getPrivacyStateUseCase: GetQuickPrivacyStateUseCase,
trackersStatisticsUseCase: TrackersStatisticsUseCase,
@@ -135,4 +139,18 @@ class Widget : AppWidgetProvider() {
}
}
}
+
+ @FlowPreview
+ override fun onAppWidgetOptionsChanged(
+ context: Context,
+ appWidgetManager: AppWidgetManager,
+ appWidgetId: Int,
+ newOptions: Bundle?
+ ) {
+ super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions)
+ if (newOptions != null) {
+ isDarkText = newOptions.getBoolean(DARK_TEXT_KEY)
+ }
+ render(context, state.value, appWidgetManager)
+ }
}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
index ca93617..f95083e 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
@@ -27,6 +27,7 @@ import android.view.View
import android.widget.RemoteViews
import foundation.e.privacycentralapp.R
import foundation.e.privacycentralapp.Widget
+import foundation.e.privacycentralapp.Widget.Companion.isDarkText
import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState
import foundation.e.privacycentralapp.extensions.dpToPxF
import foundation.e.privacycentralapp.main.MainActivity
@@ -49,6 +50,7 @@ fun render(
appWidgetManager: AppWidgetManager,
) {
val views = RemoteViews(context.packageName, R.layout.widget)
+ applyDarkText(context, state, views)
views.apply {
val openPIntent = PendingIntent.getActivity(
context,
@@ -59,11 +61,6 @@ fun render(
setOnClickPendingIntent(R.id.settings_btn, openPIntent)
setOnClickPendingIntent(R.id.widget_container, openPIntent)
- setImageViewResource(
- R.id.state_icon,
- if (state.quickPrivacyState.isEnabled()) R.drawable.ic_shield_on_white
- else R.drawable.ic_shield_off_white
- )
setTextViewText(
R.id.state_label,
context.getString(
@@ -268,3 +265,73 @@ private const val REQUEST_CODE_DASHBOARD = 1
private const val REQUEST_CODE_TOGGLE = 2
private const val REQUEST_CODE_TRACKERS = 3
private const val REQUEST_CODE_HIGHLIGHT = 100
+
+@FlowPreview
+fun applyDarkText(context: Context, state: State, views: RemoteViews) {
+ views.apply {
+ listOf(
+ R.id.state_label,
+ R.id.graph_legend_blocked,
+ R.id.graph_legend_allowed,
+
+ )
+ .forEach {
+ setTextColor(
+ it,
+ context.getColor(if (isDarkText) R.color.on_surface_disabled_light else R.color.on_primary_medium_emphasis)
+ )
+ }
+ setTextColor(
+ R.id.widget_title,
+ context.getColor(if (isDarkText) R.color.on_surface_medium_emphasis_light else R.color.on_surface_high_emphasis)
+ )
+ listOf(
+ R.id.state_trackers,
+ R.id.state_geolocation,
+ R.id.state_ip_address,
+ R.id.graph_legend,
+ R.id.graph_view_trackers_btn
+ )
+ .forEach {
+ setTextColor(
+ it,
+ context.getColor(if (isDarkText) R.color.on_surface_medium_emphasis_light else R.color.on_primary_high_emphasis)
+ )
+ }
+
+ listOf(
+ R.id.trackers_label,
+ R.id.geolocation_label,
+ R.id.ip_address_label,
+ R.id.graph_empty
+
+ )
+ .forEach {
+ setTextColor(
+ it,
+ context.getColor(if (isDarkText) R.color.on_surface_disabled_light else R.color.on_primary_disabled)
+ )
+ }
+ setTextViewCompoundDrawables(
+ R.id.graph_view_trackers_btn,
+ 0,
+ 0,
+ if (isDarkText) R.drawable.ic_chevron_right_24dp_light else R.drawable.ic_chevron_right_24dp,
+ 0
+ )
+ setImageViewResource(
+ R.id.settings_btn,
+ if (isDarkText) R.drawable.ic_settings_light else R.drawable.ic_settings
+ )
+ setImageViewResource(
+ R.id.state_icon,
+ if (isDarkText) {
+ if (state.quickPrivacyState.isEnabled()) R.drawable.ic_shield_on_light
+ else R.drawable.ic_shield_off_light
+ } else {
+ if (state.quickPrivacyState.isEnabled()) R.drawable.ic_shield_on_white
+ else R.drawable.ic_shield_off_white
+ }
+ )
+ }
+}