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 89707fabab187401133e7a083ff66da7b104ef08..1d685506119be9ce3232528be778093649612560 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,19 @@ 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 (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)
+ } 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 +160,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_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)
.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)
@@ -182,15 +192,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,10 +215,20 @@ 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)
+ }
}
}
+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) {
diff --git a/app/src/main/res/layout/widget_large.xml b/app/src/main/res/layout/widget_large.xml
index 1f1015e7a53db9d51619ea3f4694c8ab14ff797f..b836eac6f04a3f966981a42cf0959516c13b5722 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 @@