TF-2362 Automatically detect that the screen is not fully filled to load more emails
Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit 73c36be3a5c972c2da1a04d09e3eb493e0732f6e)
This commit is contained in:
@@ -89,4 +89,7 @@ class ThreadConstants {
|
|||||||
EmailProperty.mailboxIds,
|
EmailProperty.mailboxIds,
|
||||||
IndividualHeaderIdentifier.headerCalendarEvent.value,
|
IndividualHeaderIdentifier.headerCalendarEvent.value,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static const int defaultMaxHeightEmailItemOnBrowser = 40;
|
||||||
|
static const int defaultMaxHeightBrowser = 1200;
|
||||||
}
|
}
|
||||||
@@ -78,6 +78,7 @@ import 'package:tmail_ui_user/main/routes/dialog_router.dart';
|
|||||||
import 'package:tmail_ui_user/main/routes/navigation_router.dart';
|
import 'package:tmail_ui_user/main/routes/navigation_router.dart';
|
||||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||||
import 'package:tmail_ui_user/main/routes/route_utils.dart';
|
import 'package:tmail_ui_user/main/routes/route_utils.dart';
|
||||||
|
import 'package:universal_html/html.dart' as html;
|
||||||
|
|
||||||
typedef StartRangeSelection = int;
|
typedef StartRangeSelection = int;
|
||||||
typedef EndRangeSelection = int;
|
typedef EndRangeSelection = int;
|
||||||
@@ -132,6 +133,9 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
_registerObxStreamListener();
|
_registerObxStreamListener();
|
||||||
|
if (PlatformInfo.isWeb) {
|
||||||
|
_registerBrowserResizeListener();
|
||||||
|
}
|
||||||
super.onInit();
|
super.onInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,6 +373,35 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _registerBrowserResizeListener() {
|
||||||
|
log('ThreadController::_registerBrowserResizeListener:');
|
||||||
|
html.window.onResize.listen((_) => _measureBrowserHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
void _initialMeasureBrowserHeight() {
|
||||||
|
log('ThreadController::_initialMeasureBrowserHeight:');
|
||||||
|
_measureBrowserHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _measureBrowserHeight() {
|
||||||
|
final browserInnerHeight = html.window.innerHeight ?? 0;
|
||||||
|
log('ThreadController::_measureBrowserHeight: BROWSER_INTER_HEIGHT = $browserInnerHeight');
|
||||||
|
final currentListEmails = mailboxDashBoardController.emailsInCurrentMailbox;
|
||||||
|
final totalHeightListEmails = currentListEmails.isEmpty
|
||||||
|
? 0
|
||||||
|
: currentListEmails.length * ThreadConstants.defaultMaxHeightEmailItemOnBrowser;
|
||||||
|
log('ThreadController::_handleResizeBrowser: TOTAL_HEIGHT_LIST_EMAILS = $totalHeightListEmails');
|
||||||
|
if (browserInnerHeight >= ThreadConstants.defaultMaxHeightBrowser &&
|
||||||
|
totalHeightListEmails <= browserInnerHeight) {
|
||||||
|
_performAutomaticallyLoadMoreEmails();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _performAutomaticallyLoadMoreEmails() {
|
||||||
|
log('ThreadController::_performAutomaticallyLoadMoreEmails:');
|
||||||
|
handleLoadMoreEmailsRequest();
|
||||||
|
}
|
||||||
|
|
||||||
void _handleErrorGetAllOrRefreshChangesEmail(Object error, StackTrace stackTrace) async {
|
void _handleErrorGetAllOrRefreshChangesEmail(Object error, StackTrace stackTrace) async {
|
||||||
logError('ThreadController::_handleErrorGetAllOrRefreshChangesEmail():Error: $error');
|
logError('ThreadController::_handleErrorGetAllOrRefreshChangesEmail():Error: $error');
|
||||||
if (error is CannotCalculateChangesMethodResponseException) {
|
if (error is CannotCalculateChangesMethodResponseException) {
|
||||||
@@ -418,6 +451,9 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
duration: const Duration(milliseconds: 500),
|
duration: const Duration(milliseconds: 500),
|
||||||
curve: Curves.fastOutSlowIn);
|
curve: Curves.fastOutSlowIn);
|
||||||
}
|
}
|
||||||
|
if (PlatformInfo.isWeb) {
|
||||||
|
_initialMeasureBrowserHeight();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,6 +475,8 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
|
|
||||||
if (mailboxDashBoardController.emailsInCurrentMailbox.isEmpty) {
|
if (mailboxDashBoardController.emailsInCurrentMailbox.isEmpty) {
|
||||||
refreshAllEmail();
|
refreshAllEmail();
|
||||||
|
} else if (PlatformInfo.isWeb) {
|
||||||
|
_initialMeasureBrowserHeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,8 +572,8 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadMoreEmails() {
|
void _loadMoreEmails() {
|
||||||
log('ThreadController::loadMoreEmails()');
|
log('ThreadController::_loadMoreEmails()');
|
||||||
if (canLoadMore && _session != null && _accountId != null) {
|
if (canLoadMore && _session != null && _accountId != null) {
|
||||||
final oldestEmail = mailboxDashBoardController.emailsInCurrentMailbox.isNotEmpty
|
final oldestEmail = mailboxDashBoardController.emailsInCurrentMailbox.isNotEmpty
|
||||||
? mailboxDashBoardController.emailsInCurrentMailbox.last
|
? mailboxDashBoardController.emailsInCurrentMailbox.last
|
||||||
@@ -586,6 +624,10 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
canLoadMore = false;
|
canLoadMore = false;
|
||||||
}
|
}
|
||||||
loadingMoreStatus.value = LoadingMoreStatus.completed;
|
loadingMoreStatus.value = LoadingMoreStatus.completed;
|
||||||
|
|
||||||
|
if (PlatformInfo.isWeb) {
|
||||||
|
_initialMeasureBrowserHeight();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectMode getSelectMode(PresentationEmail presentationEmail, PresentationEmail? selectedEmail) {
|
SelectMode getSelectMode(PresentationEmail presentationEmail, PresentationEmail? selectedEmail) {
|
||||||
@@ -805,10 +847,14 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
mailboxDashBoardController.updateEmailList(newEmailListSynced);
|
mailboxDashBoardController.updateEmailList(newEmailListSynced);
|
||||||
|
|
||||||
canSearchMore = newEmailListSynced.length >= ThreadConstants.maxCountEmails;
|
canSearchMore = newEmailListSynced.length >= ThreadConstants.maxCountEmails;
|
||||||
|
|
||||||
|
if (PlatformInfo.isWeb) {
|
||||||
|
_initialMeasureBrowserHeight();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void searchMoreEmails() {
|
void _searchMoreEmails() {
|
||||||
log('ThreadController::searchMoreEmails:');
|
log('ThreadController::_searchMoreEmails:');
|
||||||
if (canSearchMore && _session != null && _accountId != null) {
|
if (canSearchMore && _session != null && _accountId != null) {
|
||||||
final lastEmail = mailboxDashBoardController.emailsInCurrentMailbox.isNotEmpty
|
final lastEmail = mailboxDashBoardController.emailsInCurrentMailbox.isNotEmpty
|
||||||
? mailboxDashBoardController.emailsInCurrentMailbox.last
|
? mailboxDashBoardController.emailsInCurrentMailbox.last
|
||||||
@@ -816,7 +862,7 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
|
|
||||||
if (searchController.sortOrderFiltered.value.isScrollByPosition()) {
|
if (searchController.sortOrderFiltered.value.isScrollByPosition()) {
|
||||||
final nextPosition = mailboxDashBoardController.emailsInCurrentMailbox.length;
|
final nextPosition = mailboxDashBoardController.emailsInCurrentMailbox.length;
|
||||||
log('ThreadController::searchMoreEmails:nextPosition: $nextPosition');
|
log('ThreadController::_searchMoreEmails:nextPosition: $nextPosition');
|
||||||
searchController.updateFilterEmail(
|
searchController.updateFilterEmail(
|
||||||
positionOption: Some(nextPosition),
|
positionOption: Some(nextPosition),
|
||||||
beforeOption: const None()
|
beforeOption: const None()
|
||||||
@@ -860,6 +906,10 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
}
|
}
|
||||||
canSearchMore = success.emailList.isNotEmpty;
|
canSearchMore = success.emailList.isNotEmpty;
|
||||||
loadingMoreStatus.value = LoadingMoreStatus.completed;
|
loadingMoreStatus.value = LoadingMoreStatus.completed;
|
||||||
|
|
||||||
|
if (PlatformInfo.isWeb) {
|
||||||
|
_initialMeasureBrowserHeight();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSelectionEnabled() => mailboxDashBoardController.isSelectionEnabled();
|
bool isSelectionEnabled() => mailboxDashBoardController.isSelectionEnabled();
|
||||||
@@ -1260,4 +1310,13 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
_searchEmail();
|
_searchEmail();
|
||||||
mailboxDashBoardController.clearDashBoardAction();
|
mailboxDashBoardController.clearDashBoardAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleLoadMoreEmailsRequest() {
|
||||||
|
log('ThreadController::handleLoadMoreEmailsRequest:');
|
||||||
|
if (isSearchActive) {
|
||||||
|
_searchMoreEmails();
|
||||||
|
} else {
|
||||||
|
_loadMoreEmails();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -423,19 +423,11 @@ class ThreadView extends GetWidget<ThreadController>
|
|||||||
scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent &&
|
scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent &&
|
||||||
!controller.loadingMoreStatus.value.isRunning
|
!controller.loadingMoreStatus.value.isRunning
|
||||||
) {
|
) {
|
||||||
_handleLoadMoreEmailsRequest();
|
controller.handleLoadMoreEmailsRequest();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleLoadMoreEmailsRequest() {
|
|
||||||
if (controller.isSearchActive) {
|
|
||||||
controller.searchMoreEmails();
|
|
||||||
} else {
|
|
||||||
controller.loadMoreEmails();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildLoadMoreButton(BuildContext context, LoadingMoreStatus loadingMoreStatus) {
|
Widget _buildLoadMoreButton(BuildContext context, LoadingMoreStatus loadingMoreStatus) {
|
||||||
if (((controller.canLoadMore && !controller.isSearchActive) ||
|
if (((controller.canLoadMore && !controller.isSearchActive) ||
|
||||||
(controller.canSearchMore && controller.isSearchActive)) &&
|
(controller.canSearchMore && controller.isSearchActive)) &&
|
||||||
@@ -445,7 +437,7 @@ class ThreadView extends GetWidget<ThreadController>
|
|||||||
style: OutlinedButton.styleFrom(
|
style: OutlinedButton.styleFrom(
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
),
|
),
|
||||||
onPressed: _handleLoadMoreEmailsRequest,
|
onPressed: controller.handleLoadMoreEmailsRequest,
|
||||||
child: Text(
|
child: Text(
|
||||||
AppLocalizations.of(context).loadMore,
|
AppLocalizations.of(context).loadMore,
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
|
|||||||
Reference in New Issue
Block a user