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

Commit 752ee597 authored by Romain Hunault's avatar Romain Hunault 🚴🏻
Browse files

Merge branch '5217_blocked_trackers' into 'main'

5217 - Display blocked trackers, 5216 : add leaks in tooltips

See merge request e/privacy-central/privacycentralapp!39
parents 250da848 11163943
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ quality-analysis:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    - if: '$CI_COMMIT_BRANCH == "master"'
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: never
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: never
@@ -57,7 +57,7 @@ build-debug:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    - if: '$CI_COMMIT_BRANCH == "master"'
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: never
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: never
@@ -73,7 +73,7 @@ test-debug:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    - if: '$CI_COMMIT_BRANCH == "master"'
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: never
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: never
+2 −2
Original line number Diff line number Diff line
@@ -112,8 +112,8 @@ dependencies {
    //googleImplementation project(":privacymodulesgoogle")
    // include the e specific version of the modules, just for the e flavor

    implementation 'foundation.e:privacymodule.trackerfilter:0.5.1'
    implementation 'foundation.e:privacymodule.api:0.6.0'
    implementation 'foundation.e:privacymodule.trackerfilter:0.6.0'
    implementation 'foundation.e:privacymodule.api:1.0.0'
    e29Implementation 'foundation.e:privacymodule.e-29:0.4.2'
    e30Implementation 'foundation.e:privacymodule.e-30:0.4.2'
    implementation 'foundation.e:privacymodule.tor:0.2.2'
+55 −12
Original line number Diff line number Diff line
@@ -19,9 +19,14 @@ package foundation.e.privacycentralapp.common

import android.content.Context
import android.graphics.Canvas
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.DynamicDrawableSpan
import android.text.style.ImageSpan
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.text.toSpannable
import androidx.core.view.isVisible
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.components.MarkerView
@@ -37,7 +42,7 @@ import foundation.e.privacycentralapp.R
import foundation.e.privacycentralapp.extensions.dpToPxF

class GraphHolder(val barChart: BarChart, val context: Context, val isMarkerAbove: Boolean = true) {
    var data = emptyList<Int>()
    var data = emptyList<Pair<Int, Int>>()
        set(value) {
            field = value
            refreshDataSet()
@@ -80,7 +85,17 @@ class GraphHolder(val barChart: BarChart, val context: Context, val isMarkerAbov

            setOnChartValueSelectedListener(object : OnChartValueSelectedListener {
                override fun onValueSelected(e: Entry?, h: Highlight?) {
                    h?.let { periodMarker.setLabel(labels.getOrNull(it.x.toInt())) }
                    h?.let {
                        val index = it.x.toInt()
                        if (index > 0 &&
                            index < labels.size &&
                            index < this@GraphHolder.data.size
                        ) {
                            val period = labels[index]
                            val (blocked, leaked) = this@GraphHolder.data[index]
                            periodMarker.setLabel(period, blocked, leaked)
                        }
                    }
                    isHighlighted = true
                    refreshDataSet()
                }
@@ -95,18 +110,31 @@ class GraphHolder(val barChart: BarChart, val context: Context, val isMarkerAbov

    private fun refreshDataSet() {
        val trackersDataSet = BarDataSet(
            data.mapIndexed { index, value -> BarEntry(index.toFloat(), value.toFloat()) },
            data.mapIndexed { index, value ->
                BarEntry(
                    index.toFloat(),
                    floatArrayOf(value.first.toFloat(), value.second.toFloat())
                )
            },
            ""
        ).apply {
            color = ContextCompat.getColor(
                context,
                if (isHighlighted) R.color.blue_unselected else R.color.accent

            val blockedColor = ContextCompat.getColor(context, R.color.accent)
            val leakedColor = ContextCompat.getColor(context, R.color.red_off)

            // ColorUtils.setAlphaComponent()
            colors = listOf(
                blockedColor,
                //      if (isHighlighted) R.color.blue_unselected else R.color.accent
                leakedColor
            )

            setDrawValues(false)
            highLightColor = ContextCompat.getColor(
                context, R.color.accent
            )
            highLightAlpha = 255

            // highLightColor = ContextCompat.getColor(
            //     context, R.color.accent
            // )
            // highLightAlpha = 255
        }

        barChart.data = BarData(trackersDataSet)
@@ -162,8 +190,23 @@ class PeriodMarkerView(context: Context, private val isMarkerAbove: Boolean = tr
        }
    }

    fun setLabel(label: String?) {
        findViewById<TextView>(R.id.label).text = label
    fun setLabel(period: String, blocked: Int, leaked: Int) {
        val span = SpannableStringBuilder(period)
        span.append(": $blocked  ")
        span.setSpan(
            ImageSpan(context, R.drawable.ic_legend_blocked, DynamicDrawableSpan.ALIGN_BASELINE),
            span.length - 1,
            span.length,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        span.append("  $leaked  ")
        span.setSpan(
            ImageSpan(context, R.drawable.ic_legend_leaked, DynamicDrawableSpan.ALIGN_BASELINE),
            span.length - 1,
            span.length,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        findViewById<TextView>(R.id.label).text = span.toSpannable()
    }

    override fun refreshContent(e: Entry?, highlight: Highlight?) {
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package foundation.e.privacycentralapp.common

import androidx.annotation.LayoutRes
import com.google.android.material.appbar.MaterialToolbar
import foundation.e.privacycentralapp.R

abstract class NavToolbarFragment(@LayoutRes contentLayoutId: Int) : ToolbarFragment(contentLayoutId) {

+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
package foundation.e.privacycentralapp.domain.entities

data class TrackersPeriodicStatistics(
    val calls: List<Int>,
    val callsBlockedNLeaked: List<Pair<Int, Int>>,
    val periods: List<String>,
    val trackersCount: Int
)
Loading