import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:injectable/injectable.dart'; import 'package:location/base/base_controller.dart'; import 'package:location/data/repositories/account_repository.dart'; import 'package:location/data/repositories/urgent_contact_repository.dart'; import 'package:location/handler/error_handler.dart'; import 'package:location/module/member/member_page.dart'; import 'package:location/popup/urgent_contact_more_action_popup.dart'; import 'package:location/resource/string.gen.dart'; import 'package:location/utils/toast_util.dart'; import '../../data/bean/contact_info.dart'; import '../../dialog/common_alert_dialog_impl.dart'; import 'add_contact/add_urgent_contact_view.dart'; @injectable class UrgentContactController extends BaseController { final UrgentContactRepository _urgentContactRepository; final AccountRepository accountRepository; RxList get contactList => _urgentContactRepository.contactList; UrgentContactController( this._urgentContactRepository, this.accountRepository); @override void onReady() { super.onReady(); } void back() { Get.back(); } void addContactClick() async { AddUrgentContactView.show(); } void moreClick(BuildContext context, ContactInfo e) { UrgentContactMoreActionPopup.show(context, e.favor == true, onSetDefault: () { _setDefaultContact(e); }, onDelete: () { showDeleteUrgentContactDialog(e.phone, confirmOnTap: () => _deleteContact(e)); }); } void _setDefaultContact(ContactInfo contactInfo) { _urgentContactRepository .contactFavor( contactInfo.phone, contactInfo.favor == true ? false : true) .then((value) { if (contactInfo.favor == true) { ToastUtil.show(StringName.urgentContactCancelSuccess); } else { ToastUtil.show(StringName.urgentContactSetSuccess); } }).catchError((e) { ErrorHandler.toastError(e); }); } void _deleteContact(ContactInfo e) { _urgentContactRepository.contactDelete(e.phone).then((value) { ToastUtil.show(StringName.urgentContactDeleteSuccess); }).catchError((e) { ErrorHandler.toastError(e); }); } sendHelpClick(String phone) { if (accountRepository.memberIsExpired()) { MemberPage.start(); return; } sendUrgentContactDialog(phone, confirmOnTap: () { _urgentContactRepository.contactMayDay(phone).then((value) { ToastUtil.show(StringName.urgentContactHelpSendSuccess); }).catchError((e) { ErrorHandler.toastError(e); }); }); } void sendAllHelpClick() { if (accountRepository.memberIsExpired()) { MemberPage.start(); return; } sendAllUrgentContactDialog(confirmOnTap: () { _urgentContactRepository.contactMayDayAll().then((response) { if (response.fail == null || response.fail!.isEmpty) { ToastUtil.show(StringName.urgentContactHelpSendSuccess); } else { sendUrgentContactPartErrorDialog(response.fail!, confirmOnTap: () {}); } }).catchError((e) { ErrorHandler.toastError(e); }); }); } }