urgent_contact_controller.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:get/get.dart';
  3. import 'package:injectable/injectable.dart';
  4. import 'package:location/base/base_controller.dart';
  5. import 'package:location/data/repositories/account_repository.dart';
  6. import 'package:location/data/repositories/urgent_contact_repository.dart';
  7. import 'package:location/handler/error_handler.dart';
  8. import 'package:location/module/member/member_page.dart';
  9. import 'package:location/popup/urgent_contact_more_action_popup.dart';
  10. import 'package:location/resource/string.gen.dart';
  11. import 'package:location/utils/toast_util.dart';
  12. import '../../data/bean/contact_info.dart';
  13. import '../../dialog/common_alert_dialog_impl.dart';
  14. import 'add_contact/add_urgent_contact_view.dart';
  15. @injectable
  16. class UrgentContactController extends BaseController {
  17. final UrgentContactRepository _urgentContactRepository;
  18. final AccountRepository accountRepository;
  19. RxList<ContactInfo> get contactList => _urgentContactRepository.contactList;
  20. UrgentContactController(
  21. this._urgentContactRepository, this.accountRepository);
  22. @override
  23. void onReady() {
  24. super.onReady();
  25. }
  26. void back() {
  27. Get.back();
  28. }
  29. void addContactClick() async {
  30. AddUrgentContactView.show();
  31. }
  32. void moreClick(BuildContext context, ContactInfo e) {
  33. UrgentContactMoreActionPopup.show(context, e.favor == true,
  34. onSetDefault: () {
  35. _setDefaultContact(e);
  36. }, onDelete: () {
  37. showDeleteUrgentContactDialog(e.phone,
  38. confirmOnTap: () => _deleteContact(e));
  39. });
  40. }
  41. void _setDefaultContact(ContactInfo contactInfo) {
  42. _urgentContactRepository
  43. .contactFavor(
  44. contactInfo.phone, contactInfo.favor == true ? false : true)
  45. .then((value) {
  46. if (contactInfo.favor == true) {
  47. ToastUtil.show(StringName.urgentContactCancelSuccess);
  48. } else {
  49. ToastUtil.show(StringName.urgentContactSetSuccess);
  50. }
  51. }).catchError((e) {
  52. ErrorHandler.toastError(e);
  53. });
  54. }
  55. void _deleteContact(ContactInfo e) {
  56. _urgentContactRepository.contactDelete(e.phone).then((value) {
  57. ToastUtil.show(StringName.urgentContactDeleteSuccess);
  58. }).catchError((e) {
  59. ErrorHandler.toastError(e);
  60. });
  61. }
  62. sendHelpClick(String phone) {
  63. if (accountRepository.memberIsExpired()) {
  64. MemberPage.start();
  65. return;
  66. }
  67. sendUrgentContactDialog(phone, confirmOnTap: () {
  68. _urgentContactRepository.contactMayDay(phone).then((value) {
  69. ToastUtil.show(StringName.urgentContactHelpSendSuccess);
  70. }).catchError((e) {
  71. ErrorHandler.toastError(e);
  72. });
  73. });
  74. }
  75. void sendAllHelpClick() {
  76. if (accountRepository.memberIsExpired()) {
  77. MemberPage.start();
  78. return;
  79. }
  80. sendAllUrgentContactDialog(confirmOnTap: () {
  81. _urgentContactRepository.contactMayDayAll().then((response) {
  82. if (response.fail == null || response.fail!.isEmpty) {
  83. ToastUtil.show(StringName.urgentContactHelpSendSuccess);
  84. } else {
  85. sendUrgentContactPartErrorDialog(response.fail!, confirmOnTap: () {});
  86. }
  87. }).catchError((e) {
  88. ErrorHandler.toastError(e);
  89. });
  90. });
  91. }
  92. }