| 
									
										
										
										
											2020-11-15 20:04:05 +08:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2022-05-24 23:33:00 +08:00
										 |  |  | import 'package:flutter_hbb/mobile/pages/server_page.dart'; | 
					
						
							|  |  |  | import 'package:flutter_hbb/mobile/pages/settings_page.dart'; | 
					
						
							| 
									
										
										
										
											2023-07-10 21:03:35 +08:00
										 |  |  | import 'package:get/get.dart'; | 
					
						
							| 
									
										
										
										
											2022-05-24 23:33:00 +08:00
										 |  |  | import '../../common.dart'; | 
					
						
							| 
									
										
										
										
											2022-10-25 21:36:01 +09:00
										 |  |  | import '../../common/widgets/chat_page.dart'; | 
					
						
							| 
									
										
										
										
											2024-04-16 22:53:01 +08:00
										 |  |  | import '../../models/platform_model.dart'; | 
					
						
							| 
									
										
										
										
											2022-02-28 21:26:44 +08:00
										 |  |  | import 'connection_page.dart'; | 
					
						
							| 
									
										
										
										
											2020-11-15 20:04:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-28 18:29:25 +08:00
										 |  |  | abstract class PageShape extends Widget { | 
					
						
							|  |  |  |   final String title = ""; | 
					
						
							| 
									
										
										
										
											2023-07-10 21:03:35 +08:00
										 |  |  |   final Widget icon = Icon(null); | 
					
						
							| 
									
										
										
										
											2022-02-28 18:29:25 +08:00
										 |  |  |   final List<Widget> appBarActions = []; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-11-15 20:04:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-28 18:29:25 +08:00
										 |  |  | class HomePage extends StatefulWidget { | 
					
						
							| 
									
										
										
										
											2024-02-12 21:39:19 +08:00
										 |  |  |   static final homeKey = GlobalKey<HomePageState>(); | 
					
						
							| 
									
										
										
										
											2022-08-05 20:29:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   HomePage() : super(key: homeKey); | 
					
						
							| 
									
										
										
										
											2020-11-15 20:04:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2024-02-12 21:39:19 +08:00
										 |  |  |   HomePageState createState() => HomePageState(); | 
					
						
							| 
									
										
										
										
											2020-11-15 20:04:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-12 21:39:19 +08:00
										 |  |  | class HomePageState extends State<HomePage> { | 
					
						
							| 
									
										
										
										
											2022-02-28 18:29:25 +08:00
										 |  |  |   var _selectedIndex = 0; | 
					
						
							| 
									
										
										
										
											2023-07-10 09:40:41 +08:00
										 |  |  |   int get selectedIndex => _selectedIndex; | 
					
						
							| 
									
										
										
										
											2022-03-24 17:58:33 +08:00
										 |  |  |   final List<PageShape> _pages = []; | 
					
						
							| 
									
										
										
										
											2024-04-19 12:44:52 +08:00
										 |  |  |   int _chatPageTabIndex = -1; | 
					
						
							| 
									
										
										
										
											2023-09-03 07:21:27 +08:00
										 |  |  |   bool get isChatPageCurrentTab => isAndroid | 
					
						
							| 
									
										
										
										
											2024-04-19 12:44:52 +08:00
										 |  |  |       ? _selectedIndex == _chatPageTabIndex | 
					
						
							| 
									
										
										
										
											2023-09-03 07:21:27 +08:00
										 |  |  |       : false; // change this when ios have chat page
 | 
					
						
							| 
									
										
										
										
											2022-03-24 17:58:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-04 17:24:02 +08:00
										 |  |  |   void refreshPages() { | 
					
						
							|  |  |  |     setState(() { | 
					
						
							|  |  |  |       initPages(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-24 17:58:33 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							|  |  |  |     super.initState(); | 
					
						
							| 
									
										
										
										
											2022-08-04 17:24:02 +08:00
										 |  |  |     initPages(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void initPages() { | 
					
						
							|  |  |  |     _pages.clear(); | 
					
						
							| 
									
										
										
										
											2024-04-16 22:53:01 +08:00
										 |  |  |     if (!bind.isIncomingOnly()) _pages.add(ConnectionPage()); | 
					
						
							| 
									
										
										
										
											2024-04-17 12:48:27 +08:00
										 |  |  |     if (isAndroid && !bind.isOutgoingOnly()) { | 
					
						
							| 
									
										
										
										
											2024-04-19 12:44:52 +08:00
										 |  |  |       _chatPageTabIndex = _pages.length; | 
					
						
							| 
									
										
										
										
											2023-07-09 19:14:57 +08:00
										 |  |  |       _pages.addAll([ChatPage(type: ChatPageType.mobileMain), ServerPage()]); | 
					
						
							| 
									
										
										
										
											2022-03-24 17:58:33 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     _pages.add(SettingsPage()); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-02-28 18:29:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2022-03-01 15:46:59 +08:00
										 |  |  |     return WillPopScope( | 
					
						
							|  |  |  |         onWillPop: () async { | 
					
						
							|  |  |  |           if (_selectedIndex != 0) { | 
					
						
							|  |  |  |             setState(() { | 
					
						
							|  |  |  |               _selectedIndex = 0; | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |           } else { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           return false; | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         child: Scaffold( | 
					
						
							| 
									
										
										
										
											2022-09-23 16:31:50 +08:00
										 |  |  |           // backgroundColor: MyTheme.grayBg,
 | 
					
						
							| 
									
										
										
										
											2022-03-01 15:46:59 +08:00
										 |  |  |           appBar: AppBar( | 
					
						
							|  |  |  |             centerTitle: true, | 
					
						
							| 
									
										
										
										
											2023-07-10 21:03:35 +08:00
										 |  |  |             title: appTitle(), | 
					
						
							| 
									
										
										
										
											2022-03-01 15:46:59 +08:00
										 |  |  |             actions: _pages.elementAt(_selectedIndex).appBarActions, | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           bottomNavigationBar: BottomNavigationBar( | 
					
						
							| 
									
										
										
										
											2022-04-04 14:54:00 +08:00
										 |  |  |             key: navigationBarKey, | 
					
						
							| 
									
										
										
										
											2022-03-01 15:46:59 +08:00
										 |  |  |             items: _pages | 
					
						
							|  |  |  |                 .map((page) => | 
					
						
							|  |  |  |                     BottomNavigationBarItem(icon: page.icon, label: page.title)) | 
					
						
							|  |  |  |                 .toList(), | 
					
						
							|  |  |  |             currentIndex: _selectedIndex, | 
					
						
							|  |  |  |             type: BottomNavigationBarType.fixed, | 
					
						
							| 
									
										
										
										
											2022-09-23 16:31:50 +08:00
										 |  |  |             selectedItemColor: MyTheme.accent, //
 | 
					
						
							| 
									
										
										
										
											2022-03-01 15:46:59 +08:00
										 |  |  |             unselectedItemColor: MyTheme.darkGray, | 
					
						
							|  |  |  |             onTap: (index) => setState(() { | 
					
						
							| 
									
										
										
										
											2022-03-22 16:40:23 +08:00
										 |  |  |               // close chat overlay when go chat page
 | 
					
						
							| 
									
										
										
										
											2023-09-03 07:21:27 +08:00
										 |  |  |               if (_selectedIndex != index) { | 
					
						
							|  |  |  |                 _selectedIndex = index; | 
					
						
							|  |  |  |                 if (isChatPageCurrentTab) { | 
					
						
							|  |  |  |                   gFFI.chatModel.hideChatIconOverlay(); | 
					
						
							|  |  |  |                   gFFI.chatModel.hideChatWindowOverlay(); | 
					
						
							|  |  |  |                   gFFI.chatModel.mobileClearClientUnread( | 
					
						
							|  |  |  |                       gFFI.chatModel.currentKey.connId); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-03-22 16:40:23 +08:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2022-03-01 15:46:59 +08:00
										 |  |  |             }), | 
					
						
							|  |  |  |           ), | 
					
						
							| 
									
										
										
										
											2022-04-19 17:53:35 +08:00
										 |  |  |           body: _pages.elementAt(_selectedIndex), | 
					
						
							| 
									
										
										
										
											2022-03-01 15:46:59 +08:00
										 |  |  |         )); | 
					
						
							| 
									
										
										
										
											2022-02-28 18:29:25 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-07-10 21:03:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Widget appTitle() { | 
					
						
							|  |  |  |     final currentUser = gFFI.chatModel.currentUser; | 
					
						
							|  |  |  |     final currentKey = gFFI.chatModel.currentKey; | 
					
						
							| 
									
										
										
										
											2023-09-03 07:21:27 +08:00
										 |  |  |     if (isChatPageCurrentTab && | 
					
						
							| 
									
										
										
										
											2023-07-10 21:03:35 +08:00
										 |  |  |         currentUser != null && | 
					
						
							|  |  |  |         currentKey.peerId.isNotEmpty) { | 
					
						
							|  |  |  |       final connected = | 
					
						
							|  |  |  |           gFFI.serverModel.clients.any((e) => e.id == currentKey.connId); | 
					
						
							|  |  |  |       return Row( | 
					
						
							|  |  |  |         mainAxisAlignment: MainAxisAlignment.center, | 
					
						
							|  |  |  |         children: [ | 
					
						
							|  |  |  |           Tooltip( | 
					
						
							|  |  |  |             message: currentKey.isOut | 
					
						
							| 
									
										
										
										
											2023-07-10 23:02:26 +08:00
										 |  |  |                 ? translate('Outgoing connection') | 
					
						
							|  |  |  |                 : translate('Incoming connection'), | 
					
						
							| 
									
										
										
										
											2023-07-10 21:03:35 +08:00
										 |  |  |             child: Icon( | 
					
						
							|  |  |  |               currentKey.isOut | 
					
						
							|  |  |  |                   ? Icons.call_made_rounded | 
					
						
							|  |  |  |                   : Icons.call_received_rounded, | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           Expanded( | 
					
						
							|  |  |  |             child: Center( | 
					
						
							|  |  |  |               child: Row( | 
					
						
							|  |  |  |                 mainAxisAlignment: MainAxisAlignment.center, | 
					
						
							|  |  |  |                 children: [ | 
					
						
							|  |  |  |                   Text( | 
					
						
							|  |  |  |                     "${currentUser.firstName}   ${currentUser.id}", | 
					
						
							|  |  |  |                   ), | 
					
						
							|  |  |  |                   if (connected) | 
					
						
							|  |  |  |                     Container( | 
					
						
							|  |  |  |                       width: 10, | 
					
						
							|  |  |  |                       height: 10, | 
					
						
							|  |  |  |                       decoration: BoxDecoration( | 
					
						
							|  |  |  |                           shape: BoxShape.circle, | 
					
						
							|  |  |  |                           color: Color.fromARGB(255, 133, 246, 199)), | 
					
						
							|  |  |  |                     ).marginSymmetric(horizontal: 2), | 
					
						
							|  |  |  |                 ], | 
					
						
							|  |  |  |               ), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-04-16 22:53:01 +08:00
										 |  |  |     return Text(bind.mainGetAppNameSync()); | 
					
						
							| 
									
										
										
										
											2023-07-10 21:03:35 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-02-28 18:29:25 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-24 17:58:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class WebHomePage extends StatelessWidget { | 
					
						
							|  |  |  |   final connectionPage = ConnectionPage(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return Scaffold( | 
					
						
							| 
									
										
										
										
											2022-09-23 16:31:50 +08:00
										 |  |  |       // backgroundColor: MyTheme.grayBg,
 | 
					
						
							| 
									
										
										
										
											2022-03-24 17:58:33 +08:00
										 |  |  |       appBar: AppBar( | 
					
						
							|  |  |  |         centerTitle: true, | 
					
						
							| 
									
										
										
										
											2024-04-16 22:53:01 +08:00
										 |  |  |         title: Text(bind.mainGetAppNameSync()), | 
					
						
							| 
									
										
										
										
											2022-03-24 17:58:33 +08:00
										 |  |  |         actions: connectionPage.appBarActions, | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       body: connectionPage, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |