|
|
@@ -8,20 +8,24 @@ import 'package:injectable/injectable.dart';
|
|
|
import 'package:location/base/base_controller.dart';
|
|
|
import 'package:location/data/bean/location_info.dart';
|
|
|
import 'package:location/data/consts/constants.dart';
|
|
|
+import 'package:location/data/consts/error_code.dart';
|
|
|
+import 'package:location/data/repositories/account_repository.dart';
|
|
|
import 'package:location/data/repositories/friends_repository.dart';
|
|
|
import 'package:location/data/repositories/track_repository.dart';
|
|
|
import 'package:location/dialog/loading_dialog.dart';
|
|
|
import 'package:location/handler/error_handler.dart';
|
|
|
+import 'package:location/module/member/member_page.dart';
|
|
|
import 'package:location/module/track/track_util.dart';
|
|
|
import 'package:location/resource/string.gen.dart';
|
|
|
import 'package:location/utils/atmob_log.dart';
|
|
|
import 'package:location/utils/common_expand.dart';
|
|
|
+import 'package:location/utils/http_handler.dart';
|
|
|
import 'package:location/utils/toast_util.dart';
|
|
|
import 'package:sliding_sheet2/sliding_sheet2.dart';
|
|
|
import '../../data/bean/atmob_track_point.dart';
|
|
|
import '../../data/bean/user_info.dart';
|
|
|
+import '../../dialog/common_confirm_dialog_impl.dart';
|
|
|
import '../../utils/date_util.dart';
|
|
|
-import '../../utils/location_convert_marker_util.dart';
|
|
|
import '../../utils/pair.dart';
|
|
|
|
|
|
@injectable
|
|
|
@@ -66,8 +70,10 @@ class TrackController extends BaseController
|
|
|
|
|
|
final TrackRepository trackRepository;
|
|
|
final FriendsRepository friendsRepository;
|
|
|
+ final AccountRepository accountRepository;
|
|
|
|
|
|
- TrackController(this.trackRepository, this.friendsRepository);
|
|
|
+ TrackController(
|
|
|
+ this.trackRepository, this.friendsRepository, this.accountRepository);
|
|
|
|
|
|
@override
|
|
|
void onInit() {
|
|
|
@@ -79,7 +85,7 @@ class TrackController extends BaseController
|
|
|
length: 2, vsync: this, initialIndex: _currentIndex.value);
|
|
|
tabController.addListener(_handleTabChange);
|
|
|
_initTime();
|
|
|
- _onCurrentLocationQuery(showLoading: false);
|
|
|
+ _onCurrentLocationQuery(isShow: false);
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
@@ -109,6 +115,10 @@ class TrackController extends BaseController
|
|
|
}
|
|
|
|
|
|
void onTrackStartTimeClick(BuildContext context) {
|
|
|
+ if (userInfo?.virtual == true && accountRepository.memberIsExpired()) {
|
|
|
+ MemberPage.start();
|
|
|
+ return;
|
|
|
+ }
|
|
|
DatePicker.showDatePicker(context,
|
|
|
locale: DateTimePickerLocale.zh_cn,
|
|
|
initialDateTime: _trackStartTime.value,
|
|
|
@@ -123,6 +133,10 @@ class TrackController extends BaseController
|
|
|
}
|
|
|
|
|
|
void onTrackEndTimeClick(BuildContext context) {
|
|
|
+ if (userInfo?.virtual == true && accountRepository.memberIsExpired()) {
|
|
|
+ MemberPage.start();
|
|
|
+ return;
|
|
|
+ }
|
|
|
DatePicker.showDatePicker(context,
|
|
|
locale: DateTimePickerLocale.zh_cn,
|
|
|
initialDateTime: _trackEndTime.value,
|
|
|
@@ -137,6 +151,10 @@ class TrackController extends BaseController
|
|
|
}
|
|
|
|
|
|
void onTrackQueryClick() {
|
|
|
+ if (userInfo?.virtual == false && accountRepository.memberIsExpired()) {
|
|
|
+ MemberPage.start();
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (currentIndex == 0) {
|
|
|
_onTrackQuery();
|
|
|
} else {
|
|
|
@@ -144,21 +162,31 @@ class TrackController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void _onCurrentLocationQuery({bool showLoading = true}) {
|
|
|
+ void _onCurrentLocationQuery({bool isShow = true}) {
|
|
|
if (userInfo == null) {
|
|
|
return;
|
|
|
}
|
|
|
- if (showLoading) LoadingDialog.show(StringName.trackLoadingTxt);
|
|
|
- friendsRepository
|
|
|
- .getUserInfoFromId(userInfo!.id, isVirtual: userInfo!.virtual)
|
|
|
- .then((userInfo) {
|
|
|
- LoadingDialog.hide();
|
|
|
- _currentLocation.value = userInfo?.lastLocation.value;
|
|
|
- _showCurrentLocation();
|
|
|
- }).catchError((error) {
|
|
|
- debugPrint("error: $error");
|
|
|
- ErrorHandler.toastError(error);
|
|
|
- });
|
|
|
+ if (userInfo?.isMine == true) {
|
|
|
+ _currentLocation.value =
|
|
|
+ accountRepository.mineUserInfo.value.lastLocation.value;
|
|
|
+ if (isShow) {
|
|
|
+ _showCurrentLocation();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (isShow) LoadingDialog.show(StringName.trackLoadingTxt);
|
|
|
+ friendsRepository
|
|
|
+ .getUserInfoFromId(userInfo!.id, isVirtual: userInfo!.virtual)
|
|
|
+ .then((location) {
|
|
|
+ LoadingDialog.hide();
|
|
|
+ _currentLocation.value = userInfo?.lastLocation.value;
|
|
|
+ if (isShow) {
|
|
|
+ _showCurrentLocation();
|
|
|
+ }
|
|
|
+ }).catchError((error) {
|
|
|
+ debugPrint("error: $error");
|
|
|
+ ErrorHandler.toastError(error);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void _onTrackQuery() {
|
|
|
@@ -217,6 +245,14 @@ class TrackController extends BaseController
|
|
|
}).catchError((error) {
|
|
|
LoadingDialog.hide();
|
|
|
if (error is TrackQueryException) {
|
|
|
+ showQueryErrorDialog();
|
|
|
+ } else if (error is ServerErrorException) {
|
|
|
+ if (error.code == ErrorCode.noMember) {
|
|
|
+ MemberPage.start();
|
|
|
+ ToastUtil.show(StringName.memberExpired);
|
|
|
+ } else {
|
|
|
+ ToastUtil.show(error.message);
|
|
|
+ }
|
|
|
} else {
|
|
|
ErrorHandler.toastError(error);
|
|
|
}
|
|
|
@@ -281,6 +317,10 @@ class TrackController extends BaseController
|
|
|
// drawMarker();
|
|
|
//显示终点标记
|
|
|
}
|
|
|
+
|
|
|
+ void showQueryErrorDialog() {
|
|
|
+ showTraceNoDataDialog(onConfirm: () {});
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class TrackQueryException implements Exception {
|