Line data Source code
1 : import 'package:flutter/cupertino.dart'; 2 : import 'package:flutter/widgets.dart'; 3 : 4 : import 'profile.dart'; 5 : 6 : class ProfileListState extends ChangeNotifier { 7 : List<ProfileInfoState> _profiles = []; 8 0 : int get num => _profiles.length; 9 : 10 0 : void add( 11 : String onion, String name, String privateName, String picture, String defaultPicture, String contactsJson, String serverJson, bool online, bool autostart, bool encrypted, bool appearOffline) { 12 0 : var idx = _profiles.indexWhere((element) => element.onion == onion); 13 0 : if (idx == -1) { 14 0 : _profiles.add(ProfileInfoState( 15 : onion: onion, 16 : nickname: name, 17 : privateName: privateName, 18 : imagePath: picture, 19 : defaultImagePath: defaultPicture, 20 : contactsJson: contactsJson, 21 : serversJson: serverJson, 22 : online: online, 23 : autostart: autostart, 24 : encrypted: encrypted, 25 : appearOffline: appearOffline)); 26 : } else { 27 0 : _profiles[idx].updateFrom(onion, name, picture, contactsJson, serverJson, online); 28 : } 29 0 : notifyListeners(); 30 : } 31 : 32 0 : List<ProfileInfoState> get profiles => _profiles.sublist(0); //todo: copy?? dont want caller able to bypass changenotifier 33 : 34 0 : ProfileInfoState? getProfile(String onion) { 35 0 : int idx = _profiles.indexWhere((element) => element.onion == onion); 36 0 : return idx >= 0 ? _profiles[idx] : null; 37 : } 38 : 39 0 : void delete(String onion) { 40 0 : _profiles.removeWhere((element) => element.onion == onion); 41 0 : notifyListeners(); 42 : } 43 : 44 0 : int generateUnreadCount(String selectedProfile) => _profiles.where((p) => p.onion != selectedProfile).fold(0, (i, p) => i + p.unreadMessages); 45 : 46 0 : int cacheMemUsage() { 47 0 : return _profiles.map((e) => e.cacheMemUsage()).fold(0, (previousValue, element) => previousValue + element); 48 : } 49 : }