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

Commit 790938f1 authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

feat:1960: Updates labels of wall of shame.

parent 680b7a48
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
package foundation.e.advancedprivacy.common

import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding

class BindingViewHolder<T : ViewBinding>(val binding: T) : RecyclerView.ViewHolder(binding.root)

abstract class BindingListAdapter<T : ViewBinding, U> : RecyclerView.Adapter<BindingViewHolder<T>>() {
    var dataSet: List<U> = emptyList()
        set(value) {
            field = value
            notifyDataSetChanged()
        }

    override fun getItemCount(): Int = dataSet.size
}
+14 −5
Original line number Diff line number Diff line
@@ -16,11 +16,20 @@
 */
package foundation.e.advancedprivacy.domain.entities

import foundation.e.advancedprivacy.features.trackers.AppWithTrackersCount
import foundation.e.advancedprivacy.features.trackers.TrackerWithAppsCount
import foundation.e.advancedprivacy.trackers.domain.entities.Tracker

data class TrackersAndAppsLists(
    val trackers: List<TrackerWithAppsCount>,
    val allApps: List<AppWithTrackersCount>,
    val appsWithTrackers: List<AppWithTrackersCount>
    val trackers: List<TrackerWithCount>,
    val allApps: List<AppWithCount>,
    val appsWithTrackers: List<AppWithCount>
)

data class AppWithCount(
    val app: ApplicationDescription,
    val count: Int = 0
)

data class TrackerWithCount(
    val tracker: Tracker,
    val count: Int = 0
)
+22 −28
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@
package foundation.e.advancedprivacy.domain.usecases

import foundation.e.advancedprivacy.data.repositories.AppListsRepository
import foundation.e.advancedprivacy.domain.entities.AppWithCount
import foundation.e.advancedprivacy.domain.entities.ApplicationDescription
import foundation.e.advancedprivacy.domain.entities.TrackerWithCount
import foundation.e.advancedprivacy.domain.entities.TrackersAndAppsLists
import foundation.e.advancedprivacy.features.trackers.AppWithTrackersCount
import foundation.e.advancedprivacy.features.trackers.Period
import foundation.e.advancedprivacy.features.trackers.TrackerWithAppsCount
import foundation.e.advancedprivacy.trackers.data.StatsDatabase
import foundation.e.advancedprivacy.trackers.data.TrackersRepository
import foundation.e.advancedprivacy.trackers.domain.entities.Tracker
@@ -43,31 +43,23 @@ class TrackersAndAppsListsUseCase(
        )
    }

    suspend fun getWallOfShame(): TrackersAndAppsLists {
    suspend fun buildWallOfShame(): TrackersAndAppsLists {
        val trackers = statsDatabase
            .get5MostCalledTrackers(since = Period.MONTH.getPeriodStart().epochSecond)
            .mapNotNull { trackerId ->
                trackersRepository.getTracker(trackerId)
            .mapNotNull { (trackerId, calls) ->
                trackersRepository.getTracker(trackerId)?.let {
                    TrackerWithCount(it, calls)
                }

        val apps = get5MostTrackedAppsLastMonth()

        val (countByApp, countByTracker) = getCountByEntityMaps(Period.MONTH)

        val trackerWithAppsCounts = trackers.mapNotNull { tracker ->
            TrackerWithAppsCount(tracker, countByTracker[tracker]!!)
        }
        val appsWithTrackersCounts = apps.map { app ->
            AppWithTrackersCount(app, countByApp[app]!!)
            }

        return TrackersAndAppsLists(
            trackers = trackerWithAppsCounts,
            appsWithTrackers = appsWithTrackersCounts,
            trackers = trackers,
            appsWithTrackers = get5MostTrackedAppsLastMonth(),
            allApps = emptyList()
        )
    }

    private suspend fun get5MostTrackedAppsLastMonth(): List<ApplicationDescription> {
    private suspend fun get5MostTrackedAppsLastMonth(): List<AppWithCount> {
        val countByAppIds = statsDatabase.getCallsByAppIds(since = Period.MONTH.getPeriodStart().epochSecond)

        val countByApps = mutableMapOf<ApplicationDescription, Int>()
@@ -76,7 +68,9 @@ class TrackersAndAppsListsUseCase(
                countByApps[app] = count + (countByApps[app] ?: 0)
            }
        }
        return countByApps.toList().sortedByDescending { it.second }.take(5).map { it.first }
        return countByApps.toList().sortedByDescending { it.second }.take(5).map { (app, count) ->
            AppWithCount(app, count)
        }
    }

    private suspend fun getCountByEntityMaps(period: Period): Pair<Map<ApplicationDescription, Int>, Map<Tracker, Int>> {
@@ -86,22 +80,22 @@ class TrackersAndAppsListsUseCase(
        return foldToCountByEntityMaps(trackersAndApps)
    }

    private fun buildTrackerList(countByTracker: Map<Tracker, Int>): List<TrackerWithAppsCount> {
    private fun buildTrackerList(countByTracker: Map<Tracker, Int>): List<TrackerWithCount> {
        return countByTracker.map { (tracker, count) ->
            TrackerWithAppsCount(tracker = tracker, appsCount = count)
        }.sortedByDescending { it.appsCount }
            TrackerWithCount(tracker = tracker, count = count)
        }.sortedByDescending { it.count }
    }

    private suspend fun buildAllAppList(countByApp: Map<ApplicationDescription, Int>): List<AppWithTrackersCount> {
    private suspend fun buildAllAppList(countByApp: Map<ApplicationDescription, Int>): List<AppWithCount> {
        return appListsRepository.apps().first().map { app: ApplicationDescription ->
            AppWithTrackersCount(app = app, trackersCount = countByApp[app] ?: 0)
        }.sortedByDescending { it.trackersCount }
            AppWithCount(app = app, count = countByApp[app] ?: 0)
        }.sortedByDescending { it.count }
    }

    private fun buildAppList(countByApp: Map<ApplicationDescription, Int>): List<AppWithTrackersCount> {
    private fun buildAppList(countByApp: Map<ApplicationDescription, Int>): List<AppWithCount> {
        return countByApp.map { (app, count) ->
            AppWithTrackersCount(app = app, trackersCount = count)
        }.sortedByDescending { it.trackersCount }
            AppWithCount(app = app, count = count)
        }.sortedByDescending { it.count }
    }

    private suspend fun mapIdsToEntities(trackersAndAppsIds: List<Pair<String, String>>): List<Pair<Tracker, ApplicationDescription>> {
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ class TrackersScreenUseCase(private val localStateRepository: LocalStateReposito
    }

    fun resetTrackerTabStartPosition() {
        localStateRepository.trackersScreenTabStartPosition = 0
        localStateRepository.trackersScreenTabStartPosition = -1
    }

    suspend fun preselectTab(periodPosition: Int, tabPosition: Int) = withContext(Dispatchers.IO) {
+4 −4
Original line number Diff line number Diff line
@@ -18,10 +18,10 @@

package foundation.e.advancedprivacy.features.dashboard

import foundation.e.advancedprivacy.domain.entities.AppWithCount
import foundation.e.advancedprivacy.domain.entities.FeatureState
import foundation.e.advancedprivacy.domain.entities.TrackerMode
import foundation.e.advancedprivacy.features.trackers.AppWithTrackersCount
import foundation.e.advancedprivacy.features.trackers.TrackerWithAppsCount
import foundation.e.advancedprivacy.domain.entities.TrackerWithCount

data class DashboardState(
    val trackerMode: TrackerMode = TrackerMode.VULNERABLE,
@@ -29,6 +29,6 @@ data class DashboardState(
    val ipScramblingMode: FeatureState = FeatureState.STOPPING,
    val blockedCallsCount: Int = 0,
    val appsWithCallsCount: Int = 0,
    val shameApps: List<AppWithTrackersCount> = emptyList(),
    val shameTrackers: List<TrackerWithAppsCount> = emptyList()
    val shameApps: List<AppWithCount> = emptyList(),
    val shameTrackers: List<TrackerWithCount> = emptyList()
)
Loading