Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 124864fb authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Merge branch '238-auto_adapt_text_color' into 'main'

Add support for auto adapt text color in light mode for widget

See merge request e/privacy-central/privacycentralapp!54
parents aa2d6734 68f64614
Loading
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -31,9 +31,6 @@
    <MarkdownNavigatorCodeStyleSettings>
      <option name="RIGHT_MARGIN" value="72" />
    </MarkdownNavigatorCodeStyleSettings>
    <XML>
      <option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
    </XML>
    <codeStyleSettings language="Groovy">
      <indentOptions>
        <option name="CONTINUATION_INDENT_SIZE" value="4" />
+18 −0
Original line number Diff line number Diff line
@@ -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)
    }
}
+72 −5
Original line number Diff line number Diff line
@@ -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
            }
        )
    }
}
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2022 E FOUNDATION
  ~
  ~ This program is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ This program is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with this program.  If not, see <https://www.gnu.org/licenses/>.
  -->

<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:autoMirrored="true"
    android:height="24dp"
    android:width="24dp"
    android:viewportHeight="24.0"
    android:viewportWidth="24.0">
    <path android:fillColor="@color/on_surface_medium_emphasis_light"
          android:pathData="M9.71,18.71l-1.42,-1.42l5.3,-5.29l-5.3,-5.29l1.42,-1.42l6.7,6.71z"/>
</vector>
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2022 E FOUNDATION
  ~
  ~ This program is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ This program is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with this program.  If not, see <https://www.gnu.org/licenses/>.
  -->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
  <path
      android:pathData="M19.14,12.94C19.18,12.64 19.2,12.33 19.2,12C19.2,11.68 19.18,11.36 19.13,11.06L21.16,9.48C21.34,9.34 21.39,9.07 21.28,8.87L19.36,5.55C19.24,5.33 18.99,5.26 18.77,5.33L16.38,6.29C15.88,5.91 15.35,5.59 14.76,5.35L14.4,2.81C14.36,2.57 14.16,2.4 13.92,2.4H10.08C9.84,2.4 9.65,2.57 9.61,2.81L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33C5.02,5.25 4.77,5.33 4.65,5.55L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48L4.89,11.06C4.84,11.36 4.8,11.69 4.8,12C4.8,12.31 4.82,12.64 4.87,12.94L2.84,14.52C2.66,14.66 2.61,14.93 2.72,15.13L4.64,18.45C4.76,18.67 5.01,18.74 5.23,18.67L7.62,17.71C8.12,18.09 8.65,18.41 9.24,18.65L9.6,21.19C9.65,21.43 9.84,21.6 10.08,21.6H13.92C14.16,21.6 14.36,21.43 14.39,21.19L14.75,18.65C15.34,18.41 15.88,18.09 16.37,17.71L18.76,18.67C18.98,18.75 19.23,18.67 19.35,18.45L21.27,15.13C21.39,14.91 21.34,14.66 21.15,14.52L19.14,12.94ZM12,15.6C10.02,15.6 8.4,13.98 8.4,12C8.4,10.02 10.02,8.4 12,8.4C13.98,8.4 15.6,10.02 15.6,12C15.6,13.98 13.98,15.6 12,15.6Z"
      android:fillColor="@color/on_surface_disabled_light" />
</vector>
Loading