|
|
@@ -2,19 +2,16 @@ import 'package:electronic_assistant/base/base_controller.dart';
|
|
|
import 'package:electronic_assistant/data/bean/talks.dart';
|
|
|
import 'package:electronic_assistant/data/repositories/agenda_repository.dart';
|
|
|
import 'package:electronic_assistant/data/repositories/talk_repository.dart';
|
|
|
-import 'package:electronic_assistant/module/home/view.dart';
|
|
|
import 'package:electronic_assistant/module/main/controller.dart';
|
|
|
import 'package:electronic_assistant/resource/string.gen.dart';
|
|
|
import 'package:electronic_assistant/utils/event_bus.dart';
|
|
|
-import 'package:electronic_assistant/utils/toast_util.dart';
|
|
|
import 'package:electronic_assistant/widget/pull_to_refresh.dart';
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
import '../../data/bean/agenda.dart';
|
|
|
import '../../data/repositories/account_repository.dart';
|
|
|
-import '../../data/repositories/home_repository.dart';
|
|
|
-import '../../utils/animated_list_controller.dart';
|
|
|
import '../../utils/error_handler.dart';
|
|
|
+import '../../utils/toast_util.dart';
|
|
|
|
|
|
class HomePageController extends BaseController {
|
|
|
get isLogin => accountRepository.isLogin.value;
|
|
|
@@ -23,13 +20,14 @@ class HomePageController extends BaseController {
|
|
|
? accountRepository.getUserSubName(accountRepository.phone)
|
|
|
: StringName.homeGoLogin.tr;
|
|
|
|
|
|
- final taskList = AnimatedListController<TalkBean>();
|
|
|
- final agendaList = AnimatedListController<Agenda>();
|
|
|
-
|
|
|
final refreshController = PullToRefreshController();
|
|
|
|
|
|
BuildContext? todoTargetContext;
|
|
|
|
|
|
+ RxList<Rxn<TalkBean>> get talkList => talkRepository.talkList;
|
|
|
+
|
|
|
+ RxList<Rxn<Agenda>> get agendaList => agendaRepository.agendaList;
|
|
|
+
|
|
|
@override
|
|
|
void onReady() {
|
|
|
super.onReady();
|
|
|
@@ -52,28 +50,27 @@ class HomePageController extends BaseController {
|
|
|
eventBus.off(EventUserLogout);
|
|
|
}
|
|
|
|
|
|
- void requestHomeData() {
|
|
|
- homeRepository.homeInfo().then((data) {
|
|
|
- taskList.clearAll();
|
|
|
- taskList.addAll(data.talks);
|
|
|
- agendaList.clearAll();
|
|
|
- agendaList.addAll(data.agendas,
|
|
|
- duration: const Duration(milliseconds: 500));
|
|
|
- }).whenComplete(() {
|
|
|
+ void requestHomeData() async {
|
|
|
+ try {
|
|
|
+ await Future.wait([
|
|
|
+ talkRepository.requestHomeTalkData(),
|
|
|
+ agendaRepository.requestHomeAgendaData(),
|
|
|
+ ]);
|
|
|
+ } catch (e) {
|
|
|
+ // Handle errors if necessary
|
|
|
+ } finally {
|
|
|
refreshController.refreshCompleted();
|
|
|
- }).catchError((e) {
|
|
|
- // accountRepository.logout();
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void requestName(String? newName, TalkBean bean) {
|
|
|
talkRepository.talkRename(bean.id, newName).then((data) {
|
|
|
bean.title = newName;
|
|
|
- int index = taskList.indexOf(bean);
|
|
|
+ int index = talkList.indexOf(bean);
|
|
|
if (index != -1) {
|
|
|
- taskList.update(index, bean);
|
|
|
- ToastUtil.showToast(StringName.talkRenameSuccess.tr);
|
|
|
+ talkList[index].value = bean;
|
|
|
}
|
|
|
+ ToastUtil.showToast(StringName.talkRenameSuccess.tr);
|
|
|
}).catchError((error) {
|
|
|
ErrorHandler.toastError(error, message: StringName.talkRenameFail.tr);
|
|
|
});
|
|
|
@@ -97,11 +94,7 @@ class HomePageController extends BaseController {
|
|
|
|
|
|
void agendaComplete(Agenda item) {
|
|
|
agendaRepository.agendaFinish(item.id, true).then((data) {
|
|
|
- item.isDone = true;
|
|
|
- agendaList.removeItem(
|
|
|
- item,
|
|
|
- (context, animation, item) =>
|
|
|
- buildRemoveTodoItem(context, animation, item));
|
|
|
+ agendaRepository.removeItem(item);
|
|
|
}).catchError((error) {
|
|
|
ErrorHandler.toastError(error);
|
|
|
});
|