TF-1931 Fix user cannot do infinity scroll when he turn off network and reconnect again
(cherry picked from commit e19a644e10671089ac792cb1072cc1856b909940)
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
enum LoadingMoreStatus {
|
||||||
|
idle,
|
||||||
|
running,
|
||||||
|
completed;
|
||||||
|
|
||||||
|
bool get isRunning => this == LoadingMoreStatus.running;
|
||||||
|
}
|
||||||
@@ -61,6 +61,7 @@ import 'package:tmail_ui_user/features/thread/domain/usecases/search_more_email_
|
|||||||
import 'package:tmail_ui_user/features/thread/presentation/extensions/list_presentation_email_extensions.dart';
|
import 'package:tmail_ui_user/features/thread/presentation/extensions/list_presentation_email_extensions.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/presentation/mixin/email_action_controller.dart';
|
import 'package:tmail_ui_user/features/thread/presentation/mixin/email_action_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/presentation/model/delete_action_type.dart';
|
import 'package:tmail_ui_user/features/thread/presentation/model/delete_action_type.dart';
|
||||||
|
import 'package:tmail_ui_user/features/thread/presentation/model/loading_more_status.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/presentation/model/search_status.dart';
|
import 'package:tmail_ui_user/features/thread/presentation/model/search_status.dart';
|
||||||
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';
|
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';
|
||||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||||
@@ -89,7 +90,7 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
|
|
||||||
bool canLoadMore = true;
|
bool canLoadMore = true;
|
||||||
bool canSearchMore = true;
|
bool canSearchMore = true;
|
||||||
bool _isLoadingMore = false;
|
LoadingMoreStatus loadingMoreStatus = LoadingMoreStatus.idle;
|
||||||
MailboxId? _currentMailboxId;
|
MailboxId? _currentMailboxId;
|
||||||
jmap.State? _currentEmailState;
|
jmap.State? _currentEmailState;
|
||||||
NavigationRouter? _navigationRouter;
|
NavigationRouter? _navigationRouter;
|
||||||
@@ -101,8 +102,6 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
..add(EmailComparator(EmailComparatorProperty.receivedAt)
|
..add(EmailComparator(EmailComparatorProperty.receivedAt)
|
||||||
..setIsAscending(false));
|
..setIsAscending(false));
|
||||||
|
|
||||||
bool get isLoadingMore => _isLoadingMore;
|
|
||||||
|
|
||||||
AccountId? get _accountId => mailboxDashBoardController.accountId.value;
|
AccountId? get _accountId => mailboxDashBoardController.accountId.value;
|
||||||
|
|
||||||
Session? get _session => mailboxDashBoardController.sessionCurrent;
|
Session? get _session => mailboxDashBoardController.sessionCurrent;
|
||||||
@@ -159,7 +158,7 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
} else if (success is SearchMoreEmailSuccess) {
|
} else if (success is SearchMoreEmailSuccess) {
|
||||||
_searchMoreEmailsSuccess(success);
|
_searchMoreEmailsSuccess(success);
|
||||||
} else if (success is SearchingMoreState || success is LoadingMoreState) {
|
} else if (success is SearchingMoreState || success is LoadingMoreState) {
|
||||||
_isLoadingMore = true;
|
loadingMoreStatus = LoadingMoreStatus.running;
|
||||||
} else if (success is GetEmailByIdLoading) {
|
} else if (success is GetEmailByIdLoading) {
|
||||||
openingEmail.value = true;
|
openingEmail.value = true;
|
||||||
} else if (success is GetEmailByIdSuccess) {
|
} else if (success is GetEmailByIdSuccess) {
|
||||||
@@ -175,7 +174,7 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
canSearchMore = false;
|
canSearchMore = false;
|
||||||
mailboxDashBoardController.emailsInCurrentMailbox.clear();
|
mailboxDashBoardController.emailsInCurrentMailbox.clear();
|
||||||
} else if (failure is SearchMoreEmailFailure || failure is LoadMoreEmailsFailure) {
|
} else if (failure is SearchMoreEmailFailure || failure is LoadMoreEmailsFailure) {
|
||||||
_isLoadingMore = false;
|
loadingMoreStatus = LoadingMoreStatus.completed;
|
||||||
} else if (failure is GetEmailByIdFailure) {
|
} else if (failure is GetEmailByIdFailure) {
|
||||||
openingEmail.value = false;
|
openingEmail.value = false;
|
||||||
_navigationRouter = null;
|
_navigationRouter = null;
|
||||||
@@ -186,15 +185,25 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
@override
|
@override
|
||||||
void handleErrorViewState(Object error, StackTrace stackTrace) {
|
void handleErrorViewState(Object error, StackTrace stackTrace) {
|
||||||
super.handleErrorViewState(error, stackTrace);
|
super.handleErrorViewState(error, stackTrace);
|
||||||
|
logError('ThreadController::handleErrorViewState(): error: $error | stackTrace: $stackTrace');
|
||||||
|
_resetLoadingMore();
|
||||||
_handleErrorGetAllOrRefreshChangesEmail(error, stackTrace);
|
_handleErrorGetAllOrRefreshChangesEmail(error, stackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void handleExceptionAction({Failure? failure, Exception? exception}) {
|
void handleExceptionAction({Failure? failure, Exception? exception}) {
|
||||||
super.handleExceptionAction(failure: failure, exception: exception);
|
super.handleExceptionAction(failure: failure, exception: exception);
|
||||||
|
logError('ThreadController::handleExceptionAction(): failure: $failure | exception: $exception');
|
||||||
|
_resetLoadingMore();
|
||||||
clearState();
|
clearState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _resetLoadingMore() {
|
||||||
|
if (loadingMoreStatus == LoadingMoreStatus.running) {
|
||||||
|
loadingMoreStatus = LoadingMoreStatus.idle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _registerObxStreamListener() {
|
void _registerObxStreamListener() {
|
||||||
ever(mailboxDashBoardController.selectedMailbox, (mailbox) {
|
ever(mailboxDashBoardController.selectedMailbox, (mailbox) {
|
||||||
if (mailbox is PresentationMailbox) {
|
if (mailbox is PresentationMailbox) {
|
||||||
@@ -356,7 +365,7 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
dispatchState(Right(LoadingState()));
|
dispatchState(Right(LoadingState()));
|
||||||
mailboxDashBoardController.emailsInCurrentMailbox.clear();
|
mailboxDashBoardController.emailsInCurrentMailbox.clear();
|
||||||
canLoadMore = true;
|
canLoadMore = true;
|
||||||
_isLoadingMore = false;
|
loadingMoreStatus = LoadingMoreStatus.idle;
|
||||||
cancelSelectEmail();
|
cancelSelectEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,6 +452,7 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
void refreshAllEmail() {
|
void refreshAllEmail() {
|
||||||
dispatchState(Right(LoadingState()));
|
dispatchState(Right(LoadingState()));
|
||||||
canLoadMore = true;
|
canLoadMore = true;
|
||||||
|
loadingMoreStatus == LoadingMoreStatus.idle;
|
||||||
cancelSelectEmail();
|
cancelSelectEmail();
|
||||||
|
|
||||||
if (searchController.isSearchEmailRunning) {
|
if (searchController.isSearchEmailRunning) {
|
||||||
@@ -517,6 +527,7 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _loadMoreEmailsSuccess(LoadMoreEmailsSuccess success) {
|
void _loadMoreEmailsSuccess(LoadMoreEmailsSuccess success) {
|
||||||
|
loadingMoreStatus = LoadingMoreStatus.completed;
|
||||||
if (success.emailList.isNotEmpty) {
|
if (success.emailList.isNotEmpty) {
|
||||||
final appendableList = success.emailList
|
final appendableList = success.emailList
|
||||||
.where(_belongToCurrentMailboxId)
|
.where(_belongToCurrentMailboxId)
|
||||||
@@ -533,7 +544,6 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
} else {
|
} else {
|
||||||
canLoadMore = false;
|
canLoadMore = false;
|
||||||
}
|
}
|
||||||
_isLoadingMore = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectMode getSelectMode(PresentationEmail presentationEmail, PresentationEmail? selectedEmail) {
|
SelectMode getSelectMode(PresentationEmail presentationEmail, PresentationEmail? selectedEmail) {
|
||||||
@@ -746,6 +756,8 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _searchMoreEmailsSuccess(SearchMoreEmailSuccess success) {
|
void _searchMoreEmailsSuccess(SearchMoreEmailSuccess success) {
|
||||||
|
loadingMoreStatus = LoadingMoreStatus.completed;
|
||||||
|
|
||||||
if (success.emailList.isNotEmpty) {
|
if (success.emailList.isNotEmpty) {
|
||||||
canSearchMore = true;
|
canSearchMore = true;
|
||||||
final resultEmailSearchList = success.emailList
|
final resultEmailSearchList = success.emailList
|
||||||
@@ -762,7 +774,6 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
} else {
|
} else {
|
||||||
canSearchMore = false;
|
canSearchMore = false;
|
||||||
}
|
}
|
||||||
_isLoadingMore = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSelectionEnabled() => mailboxDashBoardController.isSelectionEnabled();
|
bool isSelectionEnabled() => mailboxDashBoardController.isSelectionEnabled();
|
||||||
|
|||||||
@@ -302,9 +302,10 @@ class ThreadView extends GetWidget<ThreadController>
|
|||||||
return NotificationListener<ScrollNotification>(
|
return NotificationListener<ScrollNotification>(
|
||||||
onNotification: (ScrollNotification scrollInfo) {
|
onNotification: (ScrollNotification scrollInfo) {
|
||||||
if (scrollInfo is ScrollEndNotification
|
if (scrollInfo is ScrollEndNotification
|
||||||
&& !controller.isLoadingMore
|
&& !controller.loadingMoreStatus.isRunning
|
||||||
&& scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent
|
&& scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent
|
||||||
) {
|
) {
|
||||||
|
log('ThreadView::_buildListEmailBody(): CALL LOAD MORE');
|
||||||
if (controller.isSearchActive() || controller.searchController.advancedSearchIsActivated.isTrue) {
|
if (controller.isSearchActive() || controller.searchController.advancedSearchIsActivated.isTrue) {
|
||||||
controller.searchMoreEmails();
|
controller.searchMoreEmails();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user