|
@@ -1,7 +1,5 @@
|
|
|
import 'dart:async';
|
|
import 'dart:async';
|
|
|
-import 'dart:ffi';
|
|
|
|
|
import 'dart:io';
|
|
import 'dart:io';
|
|
|
-
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
import 'package:flutter_map/flutter_map.dart';
|
|
import 'package:flutter_map/flutter_map.dart';
|
|
|
import 'package:flutter_tool_android/flutter_tool_android.dart';
|
|
import 'package:flutter_tool_android/flutter_tool_android.dart';
|
|
@@ -26,7 +24,6 @@ import 'package:location/sdk/map/map_helper.dart';
|
|
|
import 'package:location/utils/atmob_log.dart';
|
|
import 'package:location/utils/atmob_log.dart';
|
|
|
import 'package:location/utils/mmkv_util.dart';
|
|
import 'package:location/utils/mmkv_util.dart';
|
|
|
import 'package:location/utils/toast_util.dart';
|
|
import 'package:location/utils/toast_util.dart';
|
|
|
-
|
|
|
|
|
import '../../data/bean/member_status_info.dart';
|
|
import '../../data/bean/member_status_info.dart';
|
|
|
import '../../data/repositories/config_repository.dart';
|
|
import '../../data/repositories/config_repository.dart';
|
|
|
import '../../data/repositories/track_repository.dart';
|
|
import '../../data/repositories/track_repository.dart';
|
|
@@ -93,6 +90,10 @@ class MainController extends BaseController {
|
|
|
String? lastCheckFriendId;
|
|
String? lastCheckFriendId;
|
|
|
bool isExecuteAutoSelect = false;
|
|
bool isExecuteAutoSelect = false;
|
|
|
|
|
|
|
|
|
|
+ Timer? electricTimer;
|
|
|
|
|
+
|
|
|
|
|
+ final Map<String, int> electricMap = {};
|
|
|
|
|
+
|
|
|
RxMap<String, TodayTrackReportBean> get todayTrackReportMap =>
|
|
RxMap<String, TodayTrackReportBean> get todayTrackReportMap =>
|
|
|
todayTrackHelper.todayTrackReportMap;
|
|
todayTrackHelper.todayTrackReportMap;
|
|
|
|
|
|
|
@@ -127,42 +128,66 @@ class MainController extends BaseController {
|
|
|
_selectedFriend.value = mineUserInfo;
|
|
_selectedFriend.value = mineUserInfo;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- friendsListSubscription = _friendsList.listen((list) {
|
|
|
|
|
- integrateList.clear();
|
|
|
|
|
- integrateList.add(mineUserInfo);
|
|
|
|
|
- integrateList.addAll(list);
|
|
|
|
|
- mapController.replaceAllMarkers(
|
|
|
|
|
- Location2MarkerUtil.userInfoList2MarkerList(integrateList,
|
|
|
|
|
- accountRepository.memberIsExpired(), selectedFriend));
|
|
|
|
|
- if (selectedFriend != null) {
|
|
|
|
|
- UserInfo? userInfo = integrateList
|
|
|
|
|
- .firstWhereOrNull((element) => element.id == selectedFriend?.id);
|
|
|
|
|
- _selectedFriend.value = userInfo;
|
|
|
|
|
- }
|
|
|
|
|
- _autoSelectFriend();
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ //刷新好友列表
|
|
|
|
|
+ if (_friendsList.isNotEmpty) {
|
|
|
|
|
+ _updateFriendList(_friendsList);
|
|
|
|
|
+ }
|
|
|
|
|
+ friendsListSubscription =
|
|
|
|
|
+ _friendsList.listen((list) => _updateFriendList(list));
|
|
|
|
|
+
|
|
|
|
|
+ //刷新我的marker
|
|
|
updateMineInfo(accountRepository.mineUserInfo.value);
|
|
updateMineInfo(accountRepository.mineUserInfo.value);
|
|
|
mineUserInfoSubscription =
|
|
mineUserInfoSubscription =
|
|
|
accountRepository.mineUserInfo.listen((mineInfo) {
|
|
accountRepository.mineUserInfo.listen((mineInfo) {
|
|
|
updateMineInfo(mineInfo);
|
|
updateMineInfo(mineInfo);
|
|
|
});
|
|
});
|
|
|
|
|
+ //刷新我的定位
|
|
|
|
|
+ final location = accountRepository.mineUserInfo.value.lastLocation.value;
|
|
|
|
|
+ if (location != null) {
|
|
|
|
|
+ _updateMineLocation(location);
|
|
|
|
|
+ }
|
|
|
mineLocationSubscription =
|
|
mineLocationSubscription =
|
|
|
accountRepository.mineUserInfo.value.lastLocation.listen((location) {
|
|
accountRepository.mineUserInfo.value.lastLocation.listen((location) {
|
|
|
- final mineInfo = accountRepository.mineUserInfo.value;
|
|
|
|
|
- mapController.updateOrAddMarker(Location2MarkerUtil.userInfo2Marker(
|
|
|
|
|
- mineInfo, selectedFriend?.id == mineInfo.id));
|
|
|
|
|
- if (isFirstShowMineLocation && location != null) {
|
|
|
|
|
- isFirstShowMineLocation = false;
|
|
|
|
|
- animateCameraToUser(mineInfo);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ _updateMineLocation(location);
|
|
|
|
|
+ });
|
|
|
|
|
+ //根据会员状态刷新好友列表
|
|
|
|
|
+ memberStatusInfoSubscription =
|
|
|
|
|
+ accountRepository.memberStatusInfo.listen((memberStatus) {
|
|
|
|
|
+ _updateFriendList(_friendsList);
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- friendsRepository.refreshFriends();
|
|
|
|
|
|
|
|
|
|
///刷新检查有没有广告
|
|
///刷新检查有没有广告
|
|
|
_refreshTrackDailyDialogs();
|
|
_refreshTrackDailyDialogs();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ void _updateMineLocation(LocationInfo? location) {
|
|
|
|
|
+ final mineInfo = accountRepository.mineUserInfo.value;
|
|
|
|
|
+ mapController.updateOrAddMarker(Location2MarkerUtil.userInfo2Marker(
|
|
|
|
|
+ mineInfo, selectedFriend?.id == mineInfo.id, null));
|
|
|
|
|
+ if (isFirstShowMineLocation && location != null) {
|
|
|
|
|
+ isFirstShowMineLocation = false;
|
|
|
|
|
+ animateCameraToUser(mineInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void _updateFriendList(List<UserInfo> list) {
|
|
|
|
|
+ integrateList.clear();
|
|
|
|
|
+ integrateList.add(mineUserInfo);
|
|
|
|
|
+ integrateList.addAll(list);
|
|
|
|
|
+ mapController.replaceAllMarkers(Location2MarkerUtil.userInfoList2MarkerList(
|
|
|
|
|
+ integrateList, accountRepository.memberIsExpired(), selectedFriend));
|
|
|
|
|
+ if (selectedFriend != null) {
|
|
|
|
|
+ UserInfo? userInfo = integrateList
|
|
|
|
|
+ .firstWhereOrNull((element) => element.id == selectedFriend?.id);
|
|
|
|
|
+ if (userInfo == null) {
|
|
|
|
|
+ _selectedFriend.value = null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ _setSelectUserInfo(userInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ _autoSelectFriend();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
///刷新检查有没有广告
|
|
///刷新检查有没有广告
|
|
|
void _refreshTrackDailyDialogs() {
|
|
void _refreshTrackDailyDialogs() {
|
|
|
trackRepository.locationTrackDailyDialogs().then((trackResponse) {
|
|
trackRepository.locationTrackDailyDialogs().then((trackResponse) {
|
|
@@ -190,7 +215,7 @@ class MainController extends BaseController {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
mapController.updateOrAddMarker(Location2MarkerUtil.userInfo2Marker(
|
|
mapController.updateOrAddMarker(Location2MarkerUtil.userInfo2Marker(
|
|
|
- mineInfo, selectedFriend?.id == mineInfo.id));
|
|
|
|
|
|
|
+ mineInfo, selectedFriend?.id == mineInfo.id, null));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Future<void> onAddFriendClick() {
|
|
Future<void> onAddFriendClick() {
|
|
@@ -211,21 +236,58 @@ class MainController extends BaseController {
|
|
|
|
|
|
|
|
void onSelectUserClick(UserInfo userInfo) {
|
|
void onSelectUserClick(UserInfo userInfo) {
|
|
|
KVUtil.putString(Constants.keyLastSelectFriendId, userInfo.id);
|
|
KVUtil.putString(Constants.keyLastSelectFriendId, userInfo.id);
|
|
|
|
|
+ if (_selectedFriend.value == userInfo) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
_setSelectUserInfo(userInfo);
|
|
_setSelectUserInfo(userInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _setSelectUserInfo(UserInfo userInfo) {
|
|
void _setSelectUserInfo(UserInfo userInfo) {
|
|
|
UserInfo? oldInfo = _selectedFriend.value;
|
|
UserInfo? oldInfo = _selectedFriend.value;
|
|
|
_selectedFriend.value = userInfo;
|
|
_selectedFriend.value = userInfo;
|
|
|
|
|
+ //定时查询手机电量
|
|
|
|
|
+ _scheduleQueryBattery();
|
|
|
//修改地图选中
|
|
//修改地图选中
|
|
|
- _updateMapSelected(oldInfo, userInfo);
|
|
|
|
|
|
|
+ int? electric = electricMap[userInfo.id];
|
|
|
|
|
+ _updateMapSelected(oldInfo, userInfo, electric: electric);
|
|
|
if (!accountRepository.memberIsExpired() || userInfo.isMine == true) {
|
|
if (!accountRepository.memberIsExpired() || userInfo.isMine == true) {
|
|
|
//移动到选中的位置
|
|
//移动到选中的位置
|
|
|
animateCameraToUser(userInfo);
|
|
animateCameraToUser(userInfo);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void _updateMapSelected(UserInfo? oldInfo, UserInfo newInfo) {
|
|
|
|
|
|
|
+ void _scheduleQueryBattery() {
|
|
|
|
|
+ electricTimer?.cancel();
|
|
|
|
|
+ final friend = _selectedFriend.value;
|
|
|
|
|
+ if (friend == null || friend.id == Constants.mineLocationId) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ queryFriendElectric(friend);
|
|
|
|
|
+ electricTimer = Timer.periodic(const Duration(minutes: 3), (timer) {
|
|
|
|
|
+ queryFriendElectric(friend);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void queryFriendElectric(UserInfo friend) async {
|
|
|
|
|
+ friendsRepository
|
|
|
|
|
+ .userElectricQuery(friend.id)
|
|
|
|
|
+ .then((response) => response.electric)
|
|
|
|
|
+ .then((electric) {
|
|
|
|
|
+ //更新选中点位的电量
|
|
|
|
|
+ if (electric == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ electricMap[friend.id] = electric;
|
|
|
|
|
+ final selectFriend = _selectedFriend.value;
|
|
|
|
|
+ if (selectFriend == null || friend.id != selectFriend.id) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ _updateMapSelected(null, selectFriend, electric: electric);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void _updateMapSelected(UserInfo? oldInfo, UserInfo newInfo,
|
|
|
|
|
+ {int? electric}) {
|
|
|
List<UserInfo> markers = [];
|
|
List<UserInfo> markers = [];
|
|
|
if (oldInfo != null) {
|
|
if (oldInfo != null) {
|
|
|
markers.add(oldInfo);
|
|
markers.add(oldInfo);
|
|
@@ -233,7 +295,8 @@ class MainController extends BaseController {
|
|
|
markers.add(newInfo);
|
|
markers.add(newInfo);
|
|
|
mapController.updateOrAddMarkers(
|
|
mapController.updateOrAddMarkers(
|
|
|
Location2MarkerUtil.userInfoList2MarkerList(
|
|
Location2MarkerUtil.userInfoList2MarkerList(
|
|
|
- markers, accountRepository.memberIsExpired(), selectedFriend));
|
|
|
|
|
|
|
+ markers, accountRepository.memberIsExpired(), selectedFriend,
|
|
|
|
|
+ electric: electric));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void animateCameraToUser(UserInfo userInfo) {
|
|
void animateCameraToUser(UserInfo userInfo) {
|