| 
									
										
										
										
											2023-02-03 15:07:45 +08:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | import 'package:flutter_hbb/models/platform_model.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import '../common.dart'; | 
					
						
							|  |  |  | import 'model.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const int groupTabIndex = 4; | 
					
						
							|  |  |  | const String defaultGroupTabname = 'Group'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PeerTabModel with ChangeNotifier { | 
					
						
							|  |  |  |   WeakReference<FFI> parent; | 
					
						
							|  |  |  |   int get currentTab => _currentTab; | 
					
						
							|  |  |  |   int _currentTab = 0; // index in tabNames
 | 
					
						
							|  |  |  |   List<String> tabNames = [ | 
					
						
							|  |  |  |     'Recent Sessions', | 
					
						
							|  |  |  |     'Favorites', | 
					
						
							|  |  |  |     'Discovered', | 
					
						
							|  |  |  |     'Address Book', | 
					
						
							| 
									
										
										
										
											2023-06-23 17:05:48 +08:00
										 |  |  |     //defaultGroupTabname,
 | 
					
						
							| 
									
										
										
										
											2023-02-03 15:07:45 +08:00
										 |  |  |   ]; | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |   final List<IconData> icons = [ | 
					
						
							| 
									
										
										
										
											2023-06-23 12:58:27 +08:00
										 |  |  |     Icons.access_time_filled, | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |     Icons.star, | 
					
						
							|  |  |  |     Icons.explore, | 
					
						
							|  |  |  |     IconFont.addressBook, | 
					
						
							|  |  |  |     Icons.group, | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  |   List<int> get indexs => List.generate(tabNames.length, (index) => index); | 
					
						
							| 
									
										
										
										
											2023-02-03 15:07:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PeerTabModel(this.parent) { | 
					
						
							|  |  |  |     // init currentTab
 | 
					
						
							|  |  |  |     _currentTab = | 
					
						
							|  |  |  |         int.tryParse(bind.getLocalFlutterConfig(k: 'peer-tab-index')) ?? 0; | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |     if (_currentTab < 0 || _currentTab >= tabNames.length) { | 
					
						
							|  |  |  |       _currentTab = 0; | 
					
						
							| 
									
										
										
										
											2023-02-03 15:07:45 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setCurrentTab(int index) { | 
					
						
							|  |  |  |     if (_currentTab != index) { | 
					
						
							|  |  |  |       _currentTab = index; | 
					
						
							|  |  |  |       notifyListeners(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |   String tabTooltip(int index, String groupName) { | 
					
						
							| 
									
										
										
										
											2023-02-03 15:07:45 +08:00
										 |  |  |     if (index >= 0 && index < tabNames.length) { | 
					
						
							|  |  |  |       if (index == groupTabIndex) { | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |         if (gFFI.userModel.isAdmin.value || groupName.isEmpty) { | 
					
						
							|  |  |  |           return translate(defaultGroupTabname); | 
					
						
							| 
									
										
										
										
											2023-02-03 15:07:45 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |           return '${translate('Group')}: $groupName'; | 
					
						
							| 
									
										
										
										
											2023-02-03 15:07:45 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |         return translate(tabNames[index]); | 
					
						
							| 
									
										
										
										
											2023-02-03 15:07:45 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     assert(false); | 
					
						
							|  |  |  |     return index.toString(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |   IconData tabIcon(int index) { | 
					
						
							|  |  |  |     if (index >= 0 && index < tabNames.length) { | 
					
						
							|  |  |  |       return icons[index]; | 
					
						
							| 
									
										
										
										
											2023-02-03 15:07:45 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |     assert(false); | 
					
						
							|  |  |  |     return Icons.help; | 
					
						
							| 
									
										
										
										
											2023-02-03 15:07:45 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } |