LCOV - code coverage report
Current view: top level - lib/models - hybridgroups.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 50 0.0 %
Date: 2026-09-01 17:56:29 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : 
       3             : class HybridGroupsListState extends ChangeNotifier {
       4             :   List<HybridGroupState> _groups = [];
       5             : 
       6           0 :   void replace(Iterable<HybridGroupState> newGroups) {
       7           0 :     _groups.clear();
       8           0 :     _groups.addAll(newGroups);
       9           0 :     notifyListeners();
      10             :   }
      11             : 
      12           0 :   void clear() {
      13           0 :     _groups.clear();
      14             :   }
      15             : 
      16           0 :   HybridGroupState? getGroup(String onion) {
      17           0 :     int idx = _groups.indexWhere((element) => element.onion == onion);
      18           0 :     return idx >= 0 ? _groups[idx] : null;
      19             :   }
      20             : 
      21           0 :   void add(String onion, String serverBundle, bool running, String description, bool autoStart, bool isEncrypted) {
      22           0 :     var sis = HybridGroupState(onion: onion, serverBundle: serverBundle, running: running, description: description, autoStart: autoStart, isEncrypted: isEncrypted);
      23           0 :     int idx = _groups.indexWhere((element) => element.onion == onion);
      24           0 :     if (idx >= 0) {
      25           0 :       _groups[idx] = sis;
      26             :     } else {
      27           0 :       _groups.add(HybridGroupState(onion: onion, serverBundle: serverBundle, running: running, description: description, autoStart: autoStart, isEncrypted: isEncrypted));
      28             :     }
      29           0 :     notifyListeners();
      30             :   }
      31             : 
      32           0 :   void updateGroup(String onion, String serverBundle, bool running, String description, bool autoStart, bool isEncrypted) {
      33           0 :     int idx = _groups.indexWhere((element) => element.onion == onion);
      34           0 :     if (idx >= 0) {
      35           0 :       _groups[idx] = HybridGroupState(onion: onion, serverBundle: serverBundle, running: running, description: description, autoStart: autoStart, isEncrypted: isEncrypted);
      36             :     } else {
      37           0 :       print("Tried to update hybrid group list without a starting state...this is probably an error");
      38             :     }
      39           0 :     notifyListeners();
      40             :   }
      41             : 
      42           0 :   void updateGroupStats(String onion, int newTotalMessages, int newConnections) {
      43           0 :     var group = getGroup(onion);
      44             :     if (group != null) {
      45           0 :       group.setStats(newTotalMessages, newConnections);
      46           0 :       resort();
      47           0 :       notifyListeners();
      48             :     }
      49             :   }
      50             : 
      51           0 :   void delete(String onion) {
      52           0 :     _groups.removeWhere((element) => element.onion == onion);
      53           0 :     notifyListeners();
      54             :   }
      55             : 
      56           0 :   void resort() {
      57           0 :     _groups.sort((HybridGroupState a, HybridGroupState b) {
      58             :       // return -1 = a first in list
      59             :       // return 1 = b first in list
      60           0 :       if (a.totalMessages > b.totalMessages) {
      61           0 :         return -1;
      62           0 :       } else if (b.totalMessages > a.totalMessages) {
      63             :         return 1;
      64             :       }
      65             : 
      66             :       return 0;
      67             :     });
      68             :   }
      69             : 
      70           0 :   List<HybridGroupState> get groups => _groups.sublist(0); //todo: copy?? dont want caller able to bypass changenotifier
      71             : }
      72             : 
      73             : class HybridGroupState extends ChangeNotifier {
      74             :   String onion;
      75             :   String serverBundle;
      76             :   String description;
      77             :   bool running;
      78             :   bool autoStart;
      79             :   bool isEncrypted;
      80             :   int totalMessages = 0;
      81             :   int connections = 0;
      82             : 
      83           0 :   HybridGroupState({required this.onion, required this.serverBundle, required this.running, required this.description, required this.autoStart, required this.isEncrypted});
      84             : 
      85           0 :   void setAutostart(bool val) {
      86           0 :     autoStart = val;
      87           0 :     notifyListeners();
      88             :   }
      89             : 
      90           0 :   void setRunning(bool val) {
      91           0 :     running = val;
      92           0 :     notifyListeners();
      93             :   }
      94             : 
      95           0 :   void setDescription(String val) {
      96           0 :     description = val;
      97           0 :     notifyListeners();
      98             :   }
      99             : 
     100           0 :   void setStats(int newTotalMessages, int newConnections) {
     101           0 :     totalMessages = newTotalMessages;
     102           0 :     connections = newConnections;
     103           0 :     notifyListeners();
     104             :   }
     105             : }

Generated by: LCOV version 1.14