周睿 2 tahun lalu
induk
melakukan
df043d63ad

+ 87 - 3
lib/service/map_watch.dart

@@ -4,12 +4,34 @@ import 'package:common_pub/model/position.dart';
 import 'package:common_pub/service/controller.dart';
 import 'package:common_pub/ui/map_view/map_view.dart';
 import 'package:common_pub/ui/map_view/view_map_trace.dart';
+import '../logger.dart';
 import '../service/api.dart' as pb;
 import 'package:fixnum/fixnum.dart';
 
 
 typedef MapId = Int64;
 
+class Flag{
+  Flag(this.value);
+  int value;
+  Color get color=>Color(value);
+
+  @override
+  bool operator ==(Object other) {
+    if(other is Flag){
+      return value == other.value;
+    }
+    return false;
+  }
+
+  @override
+  int get hashCode => value.hashCode;
+
+  static final red = Flag(0xffff0000);
+  static final yellow = Flag(0xffffcb00);
+  static final blue = Flag(0xff00a0ff);
+  static List<Flag> get values =>[red, yellow, blue];
+}
 
 class ActiveInfo{
   var id = 0;
@@ -18,6 +40,7 @@ class ActiveInfo{
   var userList = <UserInfo>[];
   final isHide = false.obs;
 
+
   UserInfo? getUserById(int id){
     for (final one in userList){
       if(one.gameInfo.userId==id){
@@ -40,7 +63,24 @@ class ActiveInfo{
       ..gameInfo = info
     ;
   }
+  Future<void> update(pb.ToActionInfo info) async {
+    final newUserList = <UserInfo>[];
+
+    for (final nUser in info.userList) {
+      late UserInfo user;
+      final oUser = getUserById(nUser.userId);
+      if (oUser != null) {
+        user = oUser;
+        await user.update(nUser);
+
+      }else{
+        user = await newUserInfo(nUser);
+      }
 
+      newUserList.add(user);
+    }
+    userList = newUserList;
+  }
 
 }
 extension ActiveInfoExt on pb.ToActionInfo{
@@ -74,7 +114,8 @@ class UserInfo{
   var routeInfo = pb.CourseBaseInfo();
   var userInfo = pb.OrienteerBaseInfo();
   var trace = <TracePoint>[].obs;
-
+  var flag = Flag.red.obs;
+  DateTime? get startAt => gameInfo.gameSaveInfo.hasStartAt()?gameInfo.gameSaveInfo.startAt.toModel(): null;
 
   Distance get nextDistance {
     final one = nextWant;
@@ -112,7 +153,8 @@ class UserInfo{
 
     for(final one in info.gpsInfo.gameGpsInfos){
       final t = one.gpsTime.toModel();
-      final ts = gameInfo.gameSaveInfo.startAt.toModel().difference(t);
+      final startAt = gameInfo.gameSaveInfo.startAt.toModel();
+      final ts = t.difference(startAt);
       if(ts.inMilliseconds>0 && !indexMap.containsKey(ts.inMilliseconds)){
         final pos = one.toModel();
         trace.add(TracePoint()
@@ -150,10 +192,52 @@ class MapWatchService extends PlugController{
 
     _instance.value = thisInstance;
     thisInstance.init();
+    thisInstance.workFlushData();
   }
 
-  MapWatchService({required this.id});
+  Future<void> workFlushData()async{
+    while(isActive){
+      try{
+        await flushData();
+      }catch(e){
+        error(e);
+      }
+      await 1.seconds.delay();
+    }
+  }
 
+  ActiveInfo? getActiveById(int id){
+    for (final one in activeList){
+      if(one.id==id){
+        return one;
+      }
+    }
+    return null;
+  }
+
+  Future<void> flushData()async{
+    final r = await pb.ApiService.to.stub.toUserDetailQueryV2(pb.ToUserDetailQueryRequestV2(
+        mapId: id.toInt()));
+
+    final newList = <ActiveInfo>[];
+
+    for(final one in r.list){
+      late ActiveInfo info;
+      final old = getActiveById(one.actId);
+      if(old != null){
+        info = old;
+        await info.update(one);
+      }else{
+        info = await one.into();
+      }
+      newList.add(info);
+    }
+
+    activeList.value = newList;
+  }
+
+
+  MapWatchService({required this.id});
   final MapId id;
   String name= '';
   final plugMap = PlugMap();

+ 41 - 14
lib/view/home/app_bar.dart

@@ -4,35 +4,62 @@ import 'package:get/get.dart';
 import '../../generated/assets.dart';
 import 'home_controller.dart';
 
-class HomeAppBar extends GetView<HomeController> implements PreferredSizeWidget{
+class HomeAppBar extends GetView<HomeController>
+    implements PreferredSizeWidget {
   const HomeAppBar({super.key, required this.tab});
+
   final Widget tab;
 
   @override
   Widget build(BuildContext context) {
     final statusBarHeight = MediaQuery.of(context).viewPadding.top;
 
-    return SizedBox.expand(child: Container(
+    return SizedBox.expand(
+        child: Container(
       padding: EdgeInsets.only(top: statusBarHeight),
-      decoration: const BoxDecoration(image: DecorationImage(
-          image: AssetImage(Assets.imagesBkCommonPage), fit:  BoxFit.fitWidth),
-        boxShadow: [
-          BoxShadow(color: Color(0x33000000), spreadRadius: 4, blurRadius: 4)
-        ]
-      ),
+      decoration: const BoxDecoration(
+          image: DecorationImage(
+              image: AssetImage(Assets.imagesBkCommonPage),
+              fit: BoxFit.fitWidth),
+          boxShadow: [
+            BoxShadow(color: Color(0x33000000), spreadRadius: 4, blurRadius: 4)
+          ]),
       child: Row(
         mainAxisSize: MainAxisSize.max,
         crossAxisAlignment: CrossAxisAlignment.center,
         children: [
-          SizedBox(
-              width: context.wp(70),
-              height: double.infinity, child: tab),
-          IconButton(onPressed: (){}, icon: const Icon(Icons.radio))
+          SizedBox(width: 660, height: double.infinity, child: tab),
+          Expanded(
+              child: Obx(() => controller.selectMapName.value.isEmpty
+                  ? const SizedBox()
+                  : Row(children: [
+                      Container(
+                        width: 10,
+                        height: 34,
+                        margin: const EdgeInsets.only(right: 12),
+                        decoration: BoxDecoration(
+                            color: Colors.blue,
+                            borderRadius: BorderRadius.circular(5)),
+                      ),
+                      Text(controller.selectMapName.value,
+                          style: const TextStyle(
+                              color: Colors.white, fontSize: 22))
+                    ]))),
+          TextButton(
+              onPressed: () {},
+              child: const Row(
+                crossAxisAlignment: CrossAxisAlignment.center,
+                children: [
+                  Icon(Icons.radio, color: Colors.white),
+                  Text(' 广播',
+                      style: TextStyle(color: Colors.white, fontSize: 20))
+                ],
+              ))
         ],
       ),
     ));
   }
 
   @override
-  Size get preferredSize => const Size.fromHeight(kToolbarHeight) ;
-}
+  Size get preferredSize => const Size.fromHeight(kToolbarHeight);
+}

+ 33 - 24
lib/view/home/field_control/field_control.dart

@@ -69,18 +69,16 @@ class _ViewTrace extends GetView<FieldControlController>{
   @override
   Widget build(BuildContext context) {
     return Obx((){
-      final children = <Widget>[
+      final children = <Widget>[];
 
-      ];
-
-      for(final act in controller.activeList){
+      for(final act in map.activeList){
         for(final user in act.userList){
           if(user.isHide.value){
             continue;
           }
           final trace = user.trace.lastOrNull;
           if(trace != null){
-            children.add(ViewMapUserPoint(map.plugMap, trace));
+            children.add(ViewMapUserPoint(map.plugMap, trace, info: user.name, color: user.flag.value.color));
           }
         }
       }
@@ -112,24 +110,35 @@ class _ActiveInfoView extends GetView<FieldControlController>{
       Row(children: [
         Text('${info.name} (${info.userList.length}人)'),
         const Spacer(),
-        IconButton(onPressed: (){}, icon: const Icon(Icons.arrow_drop_up))
+        IconButton(onPressed: (){
+          info.isHide.value=!info.isHide.value;
+        }, icon: info.isHide.value?const Icon(Icons.arrow_drop_down):const Icon(Icons.arrow_drop_up))
       ]),
-      Container(
-        decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(5)),
-        padding: const EdgeInsets.fromLTRB(26, 11, 26, 11),
-        child: Row(
-          children: [
-            Text('广播'),
-            const Spacer(),
-            Image.asset(Assets.imagesIcCp, height: 20, width: 20),
-            Text(' ${info.cpAllCount}'),
-            const Spacer(),
-            Text('全部隐藏'),
-          ],
-        ),
-      )
+
     ];
-    children.addAll(info.userList.map((e) => _UserInfoView(data: e)).toList());
+
+    if(!info.isHide.value){
+      children.addAll([
+        Container(
+          decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(5)),
+          padding: const EdgeInsets.fromLTRB(26, 11, 26, 11),
+          child: Row(
+            children: [
+              Text('广播'),
+              const Spacer(),
+              Image.asset(Assets.imagesIcCp, height: 20, width: 20),
+              Text(' ${info.cpAllCount}'),
+              const Spacer(),
+              Text('全部隐藏'),
+            ],
+          ),
+        )
+      ]);
+      children.addAll(info.userList.map((e) => _UserInfoView(data: e)).toList());
+    }
+
+
+
 
 
     return Container(
@@ -157,10 +166,10 @@ class _UserInfoView extends GetView<FieldControlController>{
       child: Row(
         crossAxisAlignment: CrossAxisAlignment.start,
         children: [
-          Container(
+          Obx(() => Container(
               margin: const EdgeInsets.only(top: 2),
-              decoration: BoxDecoration(color: Colors.blue, borderRadius: BorderRadius.circular(4)),
-              width: 7, height: 16),
+              decoration: BoxDecoration(color: data.flag.value.color, borderRadius: BorderRadius.circular(4)),
+              width: 7, height: 16)),
           const SizedBox(width: 8,),
           Expanded(child: Column(
             crossAxisAlignment: CrossAxisAlignment.start,

+ 6 - 65
lib/view/home/field_control/field_control_controller.dart

@@ -6,77 +6,18 @@ import '../home_controller.dart';
 export 'package:application/service/map_watch.dart';
 
 
-extension ActiveInfoExt2 on ActiveInfo{
-  Future<void> update(ToActionInfo info) async {
-    final newUserList = <UserInfo>[];
-
-    for (final nUser in info.userList) {
-      late UserInfo user;
-      final oUser = getUserById(nUser.userId);
-      if (oUser != null) {
-        user = oUser;
-        await user.update(nUser);
-
-      }else{
-        user = await newUserInfo(nUser);
-      }
-
-      newUserList.add(user);
-    }
-    userList = newUserList;
-  }
-}
-
-
 class FieldControlController extends GetxController{
-  HomeController get _home => Get.find();
-  MapWatchService? get mapWatch => MapWatchService.instance;
-  final activeList = <ActiveInfo>[].obs;
-
   @override
   void onInit() {
     super.onInit();
-    workFlushData();
-  }
-
-  Future<void> workFlushData()async{
-    while(!isClosed){
-      try{
-        await flushData();
-      }catch(e){
-        error(e);
-      }
-      await 1.seconds.delay();
-    }
-  }
-
-  ActiveInfo? getActiveById(int id){
-    for (final one in activeList){
-      if(one.id==id){
-        return one;
-      }
+    final map = MapWatchService.instance;
+    if(map != null){
+      activeList.bindStream(map.activeList.stream);
     }
-    return null;
   }
 
-  Future<void> flushData()async{
-    final r = await ApiService.to.stub.toUserDetailQueryV2(ToUserDetailQueryRequestV2(
-        mapId: mapWatch?.id.toInt()));
-
-    final newList = <ActiveInfo>[];
 
-    for(final one in r.list){
-      late ActiveInfo info;
-      final old = getActiveById(one.actId);
-      if(old != null){
-        info = old;
-        await info.update(one);
-      }else{
-        info = await one.into();
-      }
-      newList.add(info);
-    }
-
-    activeList.value = newList;
-  }
+  HomeController get _home => Get.find();
+  MapWatchService? get mapWatch => MapWatchService.instance;
+  final activeList = <ActiveInfo>[].obs;
 }

+ 1 - 0
lib/view/home/home_controller.dart

@@ -1,5 +1,6 @@
 import 'package:get/get.dart';
 
 class HomeController extends GetxController{
+  final selectMapName = ''.obs;
 
 }

+ 4 - 1
lib/view/home/map/map_page.dart

@@ -1,4 +1,5 @@
 import 'package:application/service/map_watch.dart';
+import 'package:application/view/home/home_controller.dart';
 import 'package:common_pub/model/distance.dart';
 import '../../../service/api.dart' as api;
 import '../../../utils.dart';
@@ -101,14 +102,16 @@ class GalleryCardWidget extends StatelessWidget {
   final MapInfo data;
   final m.Position? position;
   final bool isSelected;
+  final HomeController c = Get.find();
 
-  const GalleryCardWidget({
+  GalleryCardWidget({
     super.key,
     required this.data,
     required this.position, required this.isSelected});
 
   void onTap(int id) async {
     await MapWatchService.setMapById(MapId(id));
+    c.selectMapName.value =  data.name;
   }
 
   @override

+ 5 - 76
lib/view/home/user_manage/user_manage_controller.dart

@@ -1,91 +1,20 @@
 import 'package:application/service/api.dart';
 import 'package:application/service/map_watch.dart';
 import 'package:application/utils.dart';
-
 import '../../../widget.dart';
-
-
-enum Flag{
-  red, yellow, blue,
-
-  ;
-
-  Color color(){
-    return switch(this){
-      red=> Colors.red,
-      yellow=> Colors.yellow,
-      blue=>Colors.blue,
-    };
-  }
-}
-
-class ActiveInfo{
-  var id=0;
-  var name = '';
-  var userList = <UserInfo>[];
-}
-extension ToActionInfoExt on ToActionInfo{
-  ActiveInfo toActiveInfo(){
-    return ActiveInfo()
-      ..id=actId
-      ..userList=userList.map((e) => e.toUserInfo()).toList();
-  }
-}
-
-class UserInfo{
-  var index = 0;
-  late String name;
-  DateTime? startAt;
-  final _isNotShow = false.obs;
-  final _flag = Flag.red.obs;
-  bool get isNotShow => _isNotShow.value;
-  set isNotShow(bool v){
-    _isNotShow.value = v;
-  }
-  Flag get flag => _flag.value;
-  set flag(Flag v){
-    _flag.value = v;
-  }
-}
-extension ToOrienteerInGameInfoExt on ToOrienteerInGameInfo{
-  UserInfo toUserInfo(){
-    return UserInfo()
-      ..startAt=gameSaveInfo.hasStartAt()? gameSaveInfo.startAt.toDateTime(toLocal: true): null;
-  }
-}
+export 'package:application/service/map_watch.dart';
 
 
 class UserManageController extends GetxController{
   @override
   void onInit() {
     super.onInit();
-    flushData();
+    final map = MapWatchService.instance;
+    if(map != null){
+      activeList.bindStream(map.activeList.stream);
+    }
   }
 
-  Future<void> flushData()async{
-    await tryApi(() async{
-      final r = await ApiService.to.stub.toUserDetailQueryV2(ToUserDetailQueryRequestV2()
-        ..mapId=MapWatchService.instance?.id.toInt()??0);
-      activeList.value = r.list.map((e) => e.toActiveInfo()).toList();
-      activeList.value = [
-        ActiveInfo()
-          ..id=1
-          ..name='穿越荒野:勇闯野性之旅'
-          ..userList.addAll([
-            UserInfo()
-              ..index=0
-              ..name='123',
-            UserInfo()
-              ..index=1
-              ..name='431'
-              ..startAt = DateTime.now(),
-          ]),
-        ActiveInfo()
-          ..id=2
-          ..name='极限挑战 战胜重力'
-      ];
-    });
-  }
 
   final activeList = <ActiveInfo>[].obs;
   final Rx<ActiveInfo?> selectActive = Rx(null);

+ 5 - 5
lib/view/home/user_manage/user_manage_page.dart

@@ -137,7 +137,7 @@ class UserManagePage extends StatelessWidget {
         const VerticalDivider(color: Colors.transparent),
         SizedBox(width: _userFlagWidth, child: Row(
           mainAxisAlignment: MainAxisAlignment.spaceEvenly,
-          children: Flag.values.map((e) => Icon(Icons.flag, color: e.color())).toList()
+          children: Flag.values.map((e) => Icon(Icons.flag, color: e.color)).toList()
         )),
       ],
     );
@@ -169,10 +169,10 @@ class UserManagePage extends StatelessWidget {
           width: _userIsNotShowWidth,
           alignment: Alignment.center,
           child: Checkbox(
-            value: data.isNotShow,
+            value: data.isHide.value,
             onChanged: (v){
               if(v != null){
-                data.isNotShow=v;
+                data.isHide.value=v;
               }
             },
           ),
@@ -182,10 +182,10 @@ class UserManagePage extends StatelessWidget {
           mainAxisAlignment: MainAxisAlignment.spaceEvenly,
           children: Flag.values.map((e) => Radio<Flag>(
             value: e,
-            groupValue: data.flag,
+            groupValue: data.flag.value,
             onChanged: (Flag? value) {
               if(value!= null){
-                data.flag=value;
+                data.flag.value=value;
               }
             },
           )).toList()