From da993549c20c480ca70515b47b9412287e4b15e2 Mon Sep 17 00:00:00 2001 From: jacquarg Date: Tue, 26 Mar 2024 19:32:35 +0100 Subject: [PATCH 1/3] =?UTF-8?q?feat(widget):=20#1965=20Split=20=E2=80=9Cnu?= =?UTF-8?q?mber=20+=20leaks=E2=80=9D=20in=20two=20lines=20when=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../e/advancedprivacy/widget/WidgetUI.kt | 41 +++++++++++++------ app/src/main/res/layout/widget_large.xml | 19 +++++++-- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt b/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt index 89707fab..bc0f23d4 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt @@ -29,6 +29,8 @@ import android.graphics.drawable.Icon import android.text.Spannable import android.text.SpannableString import android.text.style.ForegroundColorSpan +import android.view.View.GONE +import android.view.View.VISIBLE import android.widget.RemoteViews import androidx.annotation.StringRes import foundation.e.advancedprivacy.R @@ -77,15 +79,21 @@ fun render(context: Context, state: State, appWidgetManager: AppWidgetManager, w setOnClickPendingIntent(R.id.settings_btn, openPIntent) setOnClickPendingIntent(R.id.widget_container, openPIntent) - setTextViewText( - R.id.data_blocked_trackers_secondary, - buildDataSecondarySpan( - context, - isDarkText, - numberFormatter.format(state.blockedCallsCount).toString(), - R.string.widget_data_blocked_trackers_secondary + val leaksLabel = context.getString(R.string.widget_data_blocked_trackers_secondary) + val countStr = numberFormatter.format(state.blockedCallsCount).toString() + if (countStr.length > DATA_BLOCKED_TWO_LINES_DIGIT_THRESHOLD && + (countStr.length + leaksLabel.length) > DATA_BLOCKED_TWO_LINES_GLOBAL_THRESHOLD + ) { + setTextViewText(R.id.data_blocked_trackers_number, countStr) + setTextViewText(R.id.data_blocked_trackers_secondary, leaksLabel) + setViewVisibility(R.id.data_blocked_trackers_number, VISIBLE) + } else { + setViewVisibility(R.id.data_blocked_trackers_number, GONE) + setTextViewText( + R.id.data_blocked_trackers_secondary, + buildDataSecondarySpan(context, isDarkText, countStr, R.string.widget_data_blocked_trackers_secondary) ) - ) + } setTextViewText( R.id.data_apps_secondary, @@ -154,6 +162,10 @@ private const val REQUEST_CODE_TOGGLE_LOCATION = 5 private const val REQUEST_CODE_TOGGLE_IPSCRAMBLING = 6 private const val NARROW_MAXWIDTH_DP_BREAKPOINT = 240 + +private const val DATA_BLOCKED_TWO_LINES_DIGIT_THRESHOLD = 3 +private const val DATA_BLOCKED_TWO_LINES_GLOBAL_THRESHOLD = 14 + private fun buildLayout(context: Context, appWidgetManager: AppWidgetManager, widgetId: Int): RemoteViews { val width = appWidgetManager.getAppWidgetOptions(widgetId) .getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH) @@ -182,15 +194,13 @@ private fun applyDarkText(context: Context, isDarkText: Boolean, views: RemoteVi listOf( R.id.widget_title, R.id.data_blocked_trackers_primary, + R.id.data_blocked_trackers_number, R.id.data_apps_primary, R.id.trackers_control_label, R.id.fake_location_label, R.id.ipscrambling_label ).forEach { - setTextColor( - it, - primaryColor - ) + setTextColor(it, primaryColor) } listOf( @@ -207,7 +217,12 @@ private fun applyDarkText(context: Context, isDarkText: Boolean, views: RemoteVi // FFFFFF %60 val secondaryColor = context.getColor(if (isDarkText) R.color.on_surface_disabled_light else R.color.on_primary_medium_emphasis) - setTextColor(R.id.period_label, secondaryColor) + listOf( + R.id.period_label, + R.id.data_blocked_trackers_secondary + ).forEach { id -> + setTextColor(id, secondaryColor) + } } } diff --git a/app/src/main/res/layout/widget_large.xml b/app/src/main/res/layout/widget_large.xml index 1f1015e7..9e145aca 100644 --- a/app/src/main/res/layout/widget_large.xml +++ b/app/src/main/res/layout/widget_large.xml @@ -1,5 +1,5 @@ + @@ -119,7 +130,7 @@ Date: Fri, 29 Mar 2024 08:48:29 +0100 Subject: [PATCH 2/3] feat(widget):1965 - increase data blocks to respect paddings on 3 lines layout. --- app/src/main/res/layout/widget_large.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/widget_large.xml b/app/src/main/res/layout/widget_large.xml index 9e145aca..b836eac6 100644 --- a/app/src/main/res/layout/widget_large.xml +++ b/app/src/main/res/layout/widget_large.xml @@ -73,7 +73,7 @@ Date: Wed, 3 Apr 2024 19:23:39 +0200 Subject: [PATCH 3/3] feat(widget):1965: MR review, improve naming. --- .../foundation/e/advancedprivacy/widget/WidgetUI.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt b/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt index bc0f23d4..1d685506 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/widget/WidgetUI.kt @@ -81,9 +81,7 @@ fun render(context: Context, state: State, appWidgetManager: AppWidgetManager, w val leaksLabel = context.getString(R.string.widget_data_blocked_trackers_secondary) val countStr = numberFormatter.format(state.blockedCallsCount).toString() - if (countStr.length > DATA_BLOCKED_TWO_LINES_DIGIT_THRESHOLD && - (countStr.length + leaksLabel.length) > DATA_BLOCKED_TWO_LINES_GLOBAL_THRESHOLD - ) { + if (shouldSplitLeaksCountInTwoLines(countStr, leaksLabel)) { setTextViewText(R.id.data_blocked_trackers_number, countStr) setTextViewText(R.id.data_blocked_trackers_secondary, leaksLabel) setViewVisibility(R.id.data_blocked_trackers_number, VISIBLE) @@ -163,8 +161,8 @@ private const val REQUEST_CODE_TOGGLE_IPSCRAMBLING = 6 private const val NARROW_MAXWIDTH_DP_BREAKPOINT = 240 -private const val DATA_BLOCKED_TWO_LINES_DIGIT_THRESHOLD = 3 -private const val DATA_BLOCKED_TWO_LINES_GLOBAL_THRESHOLD = 14 +private const val DATA_BLOCKED_TWO_LINES_THRESHOLD_DIGITS = 3 +private const val DATA_BLOCKED_TWO_LINES_THRESHOLD_LABEL = 14 private fun buildLayout(context: Context, appWidgetManager: AppWidgetManager, widgetId: Int): RemoteViews { val width = appWidgetManager.getAppWidgetOptions(widgetId) @@ -226,6 +224,11 @@ private fun applyDarkText(context: Context, isDarkText: Boolean, views: RemoteVi } } +private fun shouldSplitLeaksCountInTwoLines(countStr: String, leaksLabel: String): Boolean { + return countStr.length > DATA_BLOCKED_TWO_LINES_THRESHOLD_DIGITS && + (countStr.length + leaksLabel.length) > DATA_BLOCKED_TWO_LINES_THRESHOLD_LABEL +} + private fun buildDataSecondarySpan(context: Context, isDarkText: Boolean, countStr: String, @StringRes secondaryRes: Int): CharSequence { val primaryColor = context.getColor( if (isDarkText) { -- GitLab