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

Commit fe20f3a9 authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

feat(widget):1965: MR review, improve naming.

parent 14bcd6be
Loading
Loading
Loading
Loading
Loading
+8 −5
Original line number Original line Diff line number Diff line
@@ -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 leaksLabel = context.getString(R.string.widget_data_blocked_trackers_secondary)
        val countStr = numberFormatter.format(state.blockedCallsCount).toString()
        val countStr = numberFormatter.format(state.blockedCallsCount).toString()
        if (countStr.length > DATA_BLOCKED_TWO_LINES_DIGIT_THRESHOLD &&
        if (shouldSplitLeaksCountInTwoLines(countStr, leaksLabel)) {
            (countStr.length + leaksLabel.length) > DATA_BLOCKED_TWO_LINES_GLOBAL_THRESHOLD
        ) {
            setTextViewText(R.id.data_blocked_trackers_number, countStr)
            setTextViewText(R.id.data_blocked_trackers_number, countStr)
            setTextViewText(R.id.data_blocked_trackers_secondary, leaksLabel)
            setTextViewText(R.id.data_blocked_trackers_secondary, leaksLabel)
            setViewVisibility(R.id.data_blocked_trackers_number, VISIBLE)
            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 NARROW_MAXWIDTH_DP_BREAKPOINT = 240


private const val DATA_BLOCKED_TWO_LINES_DIGIT_THRESHOLD = 3
private const val DATA_BLOCKED_TWO_LINES_THRESHOLD_DIGITS = 3
private const val DATA_BLOCKED_TWO_LINES_GLOBAL_THRESHOLD = 14
private const val DATA_BLOCKED_TWO_LINES_THRESHOLD_LABEL = 14


private fun buildLayout(context: Context, appWidgetManager: AppWidgetManager, widgetId: Int): RemoteViews {
private fun buildLayout(context: Context, appWidgetManager: AppWidgetManager, widgetId: Int): RemoteViews {
    val width = appWidgetManager.getAppWidgetOptions(widgetId)
    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 {
private fun buildDataSecondarySpan(context: Context, isDarkText: Boolean, countStr: String, @StringRes secondaryRes: Int): CharSequence {
    val primaryColor = context.getColor(
    val primaryColor = context.getColor(
        if (isDarkText) {
        if (isDarkText) {