Add sort by most recent tracker detection#537
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new sort option to the main app list to order apps by the most recent tracker detection (most recently active first), addressing issue #504.
Changes:
- Added a new “Sort by latest detected tracker” menu option and wiring in
ActivityMain. - Added logic to compute “last tracker detection time per UID” in
TrackerList. - Added storage/accessor for recent tracker timestamps and a new sort comparator in
Rule.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| app/src/main/res/values/strings.xml | Adds the new menu title string for the recent-tracker sort option. |
| app/src/main/res/menu/main.xml | Adds a new menu item under the sort menu group. |
| app/src/main/java/net/kollnig/missioncontrol/data/TrackerList.java | Introduces getLastTrackerTimes() to compute most recent tracker contact per UID. |
| app/src/main/java/eu/faircode/netguard/Rule.java | Stores recent tracker timestamps and adds comparator branch for the new sort. |
| app/src/main/java/eu/faircode/netguard/ActivityMain.java | Persists the new sort selection and reflects checked state in the menu. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| else if ("menu_sort_by_latest_detected_tracker".equals(sort)) | ||
| Collections.sort(listRules, (a, b) -> | ||
| Long.compare(b.getLastTrackerTime(), a.getLastTrackerTime())); |
There was a problem hiding this comment.
The sort key checked here doesn't match the value written to SharedPreferences. ActivityMain stores sort = "trackers_recent", but this branch checks for "menu_sort_by_latest_detected_tracker", so the new sort option will never be applied. Update this condition (and ideally centralize/constant-ize sort keys) so the comparator runs when sort is "trackers_recent". Also consider adding a deterministic tie-breaker (e.g., by name/package) when timestamps are equal to avoid UI jitter.
Implements feature from PR #537 (issue #504) with a bug fix: the sort comparator in Rule.java incorrectly checked for "menu_sort_by_latest_detected_tracker" instead of "trackers_recent", which would have prevented the sort from ever activating. https://claude.ai/code/session_01PUZFM4E3HjpFRAqcTDfEtU
|
@nmarteybotchway thanks for the PR. can you fix the above issue? "menu_sort_by_latest_detected_tracker" → "trackers_recent" |
|
love this new feature. it's great. thanks! |
|
But to be honest, the best way to solve this would probably me to migrate to some timeline-like interface eventually. |
…fix tiebreaking so that it is done in alphabetical order if both apps have the same last tracker detected time
|
Agreed - a timeline UI would be more intuitive. For now I’ve fixed the sort key and added a deterministic tie-breaker (alphabetical). |
|
I think should still add this feature. It's very good @nmarteybotchway |
kasnder
left a comment
There was a problem hiding this comment.
I'd improve this slightly for readability, otherwise I think we should merge.
| int cmp = Long.compare(b.getLastTrackerTime(), a.getLastTrackerTime()); | ||
| if (cmp != 0) return cmp; | ||
| int i = collator.compare(a.name, b.name); | ||
| return (i == 0 ? a.packageName.compareTo(b.packageName) : i); |
There was a problem hiding this comment.
The code changes here are very dense. Not so easy to read in my view.
There was a problem hiding this comment.
@kasnder I've improved the readability of this section and added some comments so it is similar to the other comparison branches - hope it is better now. Thanks for the feedback
Closes #504
Summary
Adds a new sort option to the main app list that orders apps by the most
recent tracker detection, with the most recently active at the top.
Changes
TrackerList.java: AddedgetLastTrackerTimes()which iterates throughrecorded host contacts, filters to known trackers only via
findTracker(),and returns the most recent tracker contact timestamp per app UID
Rule.java: AddedtrackerRecentmap,getLastTrackerTime()getter,and sort comparator case for
trackers_recentres/menu/main.xml: Added new menu item for the sort optionres/values/strings.xml: Added string resourcemenu_sort_trackers_recentActivityMain.java: Added menu selection handling inonOptionsItemSelectedand checked state in
onPrepareOptionsMenuApproach
Rather than adding a new database query, this reuses the existing
getHosts()cursor which already returns the
timecolumn, following the same pattern asgetTrackerCountsAndTotal(). Only hostnames identified as trackers byfindTracker()are considered, so the sort reflects genuine trackerdetections rather than general network activity.
Testing