TF-1014: add quotas out of storage

This commit is contained in:
ManhNTX
2022-11-10 10:35:00 +07:00
committed by Dat H. Pham
parent 75495e7d1f
commit 181915f071
15 changed files with 262 additions and 152 deletions
@@ -15,7 +15,6 @@ import 'package:tmail_ui_user/features/email/presentation/widgets/bottom_bar_mai
import 'package:tmail_ui_user/features/email/presentation/widgets/email_action_cupertino_action_sheet_action_builder.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/extensions/vacation_response_extension.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/vacation/widgets/vacation_notification_message_widget.dart';
import 'package:tmail_ui_user/features/quotas/presentation/widget/quotas_warning_banner_widget.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
class EmailView extends GetWidget<SingleEmailController> {
@@ -89,7 +88,6 @@ class EmailView extends GetWidget<SingleEmailController> {
Widget _buildEmailView(BuildContext context, PresentationEmail email) {
return Column(children: [
_buildAppBar(context, email),
const QuotasWarningBannerWidget(),
_buildVacationNotificationMessage(context),
const Divider(color: AppColor.colorDividerHorizontal, height: 1),
Expanded(
@@ -41,36 +41,44 @@ class MailboxView extends GetWidget<MailboxController> {
child: Drawer(
child: Scaffold(
backgroundColor: Colors.white,
body: Stack(children: [
Column(children: [
_buildHeaderMailbox(context),
Obx(() => controller.isSearchActive()
? SafeArea(bottom: false, top: false, right: false,
child: _buildInputSearchFormWidget(context))
: const SizedBox.shrink()),
Expanded(child: Obx(() => Container(
color: controller.isSearchActive()
? Colors.white
: AppColor.colorBgMailbox,
child: RefreshIndicator(
color: AppColor.primaryColor,
onRefresh: () async => controller.refreshAllMailbox(),
child: SafeArea(top: false, right: false,
bottom: !controller.isSelectionEnabled(),
child: controller.isSearchActive()
? _buildListMailboxSearched(context)
: Padding(
padding: EdgeInsets.only(
bottom: _responsiveUtils.isLandscapeMobile(context)
|| controller.isSelectionEnabled() ? 0 : 55),
child: _buildListMailbox(context))
)
),
))),
Obx(() => controller.isSelectionEnabled()
? _buildOptionSelectionMailbox(context)
: const SizedBox.shrink()),
]),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(children: [
_buildHeaderMailbox(context),
Obx(() => controller.isSearchActive()
? SafeArea(bottom: false, top: false, right: false,
child: _buildInputSearchFormWidget(context))
: const SizedBox.shrink()),
Expanded(child: Obx(() => Container(
color: controller.isSearchActive()
? Colors.white
: AppColor.colorBgMailbox,
child: RefreshIndicator(
color: AppColor.primaryColor,
onRefresh: () async => controller.refreshAllMailbox(),
child: SafeArea(top: false, right: false,
bottom: !controller.isSelectionEnabled(),
child: controller.isSearchActive()
? _buildListMailboxSearched(context)
: Padding(
padding: EdgeInsets.only(
bottom: _responsiveUtils.isLandscapeMobile(context)
|| controller.isSelectionEnabled() ? 0 : 24),
child: _buildListMailbox(context))
)
),
))),
Obx(() => controller.isSelectionEnabled()
? _buildOptionSelectionMailbox(context)
: const SizedBox.shrink()),
]),
),
Obx(() => controller.isSelectionEnabled()
? const SizedBox.shrink()
: const QuotasFooterWidget(padding: EdgeInsets.only(left: 24, right: 24, bottom: 8)),
),
Obx(() {
final appInformation = controller.mailboxDashBoardController.appInformation.value;
if (appInformation != null
@@ -85,7 +93,7 @@ class MailboxView extends GetWidget<MailboxController> {
} else {
return const SizedBox.shrink();
}
}),
})
]),
)
)
@@ -229,7 +237,6 @@ class MailboxView extends GetWidget<MailboxController> {
Obx(() => controller.folderMailboxTree.value.root.childrenItems?.isNotEmpty ?? false
? _buildMailboxCategory(context, MailboxCategories.folders, controller.folderMailboxTree.value.root)
: const SizedBox.shrink()),
const QuotasFooterWidget(),
])
);
}
@@ -390,13 +397,18 @@ class MailboxView extends GetWidget<MailboxController> {
}
Widget _buildVersionInformation(BuildContext context, PackageInfo packageInfo) {
return SafeArea(child: Container(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 16),
child: Text(
'${AppLocalizations.of(context).version} ${packageInfo.version}',
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 16, color: AppColor.colorContentEmail, fontWeight: FontWeight.w500),
return SafeArea(
top: false,
child: Container(
color: AppColor.colorBgMailbox,
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 16),
child: Text(
'${AppLocalizations.of(context).version} ${packageInfo.version}',
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 16, color: AppColor.colorContentEmail, fontWeight: FontWeight.w500),
),
),
));
);
}
}
@@ -1,48 +0,0 @@
import 'package:core/core.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
class StorageWidgetBuilder {
final BuildContext _context;
StorageWidgetBuilder(this._context);
Widget build() {
return Container(
key: const Key('storage_widget'),
padding: const EdgeInsets.only(left: 40, top: 16, bottom: 20, right: 40),
color: AppColor.storageBackgroundColor,
alignment: Alignment.bottomLeft,
height: 100,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppLocalizations.of(_context).storage,
maxLines: 1,
style: const TextStyle(fontSize: 12, color: AppColor.storageTitleColor, fontWeight: FontWeight.w500)),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: RichText(
text: const TextSpan(
style: TextStyle(fontSize: 16, color: AppColor.storageMaxSizeColor, fontWeight: FontWeight.w700),
children: [
TextSpan(
text: '299.6MB',
style: TextStyle(fontWeight: FontWeight.w700, fontSize: 16, color: AppColor.storageUseSizeColor)),
TextSpan(
text: ' / unlimited',
style: TextStyle(fontWeight: FontWeight.w700, fontSize: 16, color: AppColor.storageMaxSizeColor))
]
)
)
)
]
)
);
}
}
@@ -112,7 +112,9 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
SizedBox(child: MailboxView(), width: responsiveUtils.defaultSizeMenu),
Expanded(child: Column(children: [
_buildEmptyTrashButton(context),
const QuotasWarningBannerWidget(),
const QuotasWarningBannerWidget(
margin: EdgeInsets.only(right: 16, top: 8),
),
_buildVacationNotificationMessage(context),
_buildListButtonQuickSearchFilter(context),
_buildMarkAsMailboxReadLoading(context),
@@ -20,7 +20,6 @@ import 'package:tmail_ui_user/features/manage_account/presentation/menu/settings
import 'package:tmail_ui_user/features/manage_account/presentation/model/account_menu_item.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/profiles/profiles_view.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/vacation/vacation_view.dart';
import 'package:tmail_ui_user/features/quotas/presentation/widget/quotas_warning_banner_widget.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
@@ -86,7 +85,6 @@ class ManageAccountDashBoardView extends GetWidget<ManageAccountDashBoardControl
Expanded(child: Container(
color: AppColor.colorBgDesktop,
child: Column(children: [
const QuotasWarningBannerWidget(),
Obx(() {
if (controller.vacationResponse.value?.vacationResponderIsValid == true) {
return VacationNotificationMessageWidget(
@@ -22,7 +22,9 @@ class QuotasAPI {
.execute();
final getQuotaResponse = response.parse<GetQuotaResponse>(
getQuotaInvocation.methodCallId, GetQuotaResponse.deserialize);
getQuotaInvocation.methodCallId,
GetQuotaResponse.deserialize,
);
if(getQuotaResponse != null) {
return QuotasResponse(
@@ -0,0 +1,85 @@
import 'dart:ui';
import 'package:core/core.dart';
import 'package:flutter/widgets.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
enum QuotasState {
normal,
runningOutOfStorage,
runOutOfStorage;
Color getColorProgress() {
switch(this) {
case QuotasState.normal:
return AppColor.primaryColor;
case QuotasState.runningOutOfStorage:
return AppColor.colorProgressQuotasWarning;
case QuotasState.runOutOfStorage:
return AppColor.colorOutOfStorageQuotasWarning;
}
}
Color getColorQuotasFooterText() {
switch(this) {
case QuotasState.normal:
case QuotasState.runningOutOfStorage:
return AppColor.loginTextFieldHintColor;
case QuotasState.runOutOfStorage:
return AppColor.colorOutOfStorageQuotasWarning;
}
}
String getQuotasFooterText(BuildContext context, num usedCapacity, num softLimitCapacity) {
switch(this) {
case QuotasState.normal:
case QuotasState.runningOutOfStorage:
return AppLocalizations.of(context).textQuotasUsed(
usedCapacity.toDouble(),
softLimitCapacity.toDouble(),
);
case QuotasState.runOutOfStorage:
return AppLocalizations.of(context).textQuotasOutOfStorage;
}
}
String getIconWarningBanner(ImagePaths imagePaths) {
switch(this) {
case QuotasState.normal:
case QuotasState.runningOutOfStorage:
return imagePaths.icQuotasWarning;
case QuotasState.runOutOfStorage:
return imagePaths.icQuotasOutOfStorage;
}
}
Color getBackgroundColorWarningBanner() {
switch(this) {
case QuotasState.normal:
case QuotasState.runningOutOfStorage:
return AppColor.colorBackgroundQuotasWarning.withOpacity(0.12);
case QuotasState.runOutOfStorage:
return AppColor.colorOutOfStorageQuotasWarning.withOpacity(0.12);
}
}
String getTitleWarningBanner(BuildContext context, num progress) {
switch(this) {
case QuotasState.normal:
case QuotasState.runningOutOfStorage:
return AppLocalizations.of(context).textQuotasRunningOutOfStorageTitle(progress.toDouble() * 100);
case QuotasState.runOutOfStorage:
return AppLocalizations.of(context).textQuotasRunOutOfStorageTitle;
}
}
String getContentWarningBanner(BuildContext context) {
switch(this) {
case QuotasState.normal:
case QuotasState.runningOutOfStorage:
return AppLocalizations.of(context).textQuotasRunningOutOfStorageContent;
case QuotasState.runOutOfStorage:
return AppLocalizations.of(context).textQuotasRunOutOfStorageContent;
}
}
}
@@ -7,6 +7,7 @@ import 'package:tmail_ui_user/features/base/base_controller.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
import 'package:tmail_ui_user/features/quotas/domain/state/get_quotas_state.dart';
import 'package:tmail_ui_user/features/quotas/domain/use_case/get_quotas_interactor.dart';
import 'package:tmail_ui_user/features/quotas/presentation/model/quotas_state.dart';
class QuotasController extends BaseController {
final MailboxDashBoardController mailboxDashBoardController = Get.find<MailboxDashBoardController>();
@@ -15,6 +16,7 @@ class QuotasController extends BaseController {
final softLimitCapacity = Rx<num>(0);
final warningLimitCapacity = Rx<num>(0);
final enableShowQuotas = false.obs;
final quotasState = QuotasState.normal.obs;
late Worker accountIdWorker;
double get progressUsedCapacity => softLimitCapacity.value != 0
@@ -22,7 +24,9 @@ class QuotasController extends BaseController {
: 0;
bool get enableShowWarningQuotas =>
enableShowQuotas.value && usedCapacity.value >= warningLimitCapacity.value;
enableShowQuotas.isTrue &&
(quotasState.value == QuotasState.runningOutOfStorage
|| quotasState.value == QuotasState.runOutOfStorage);
final ImagePaths imagePaths = Get.find<ImagePaths>();
final ResponsiveUtils responsiveUtils = Get.find<ResponsiveUtils>();
@@ -32,27 +36,33 @@ class QuotasController extends BaseController {
void _initWorker() {
accountIdWorker = ever(mailboxDashBoardController.accountId, (accountId) {
if (accountId is AccountId) {
enableShowQuotas.value = mailboxDashBoardController.sessionCurrent != null &&
mailboxDashBoardController.sessionCurrent!.capabilities.containsValue(CapabilityIdentifier.jmapQuota);
consumeState(_getQuotasInteractor.execute(mailboxDashBoardController.accountId.value!));
_getQuotasAction(accountId);
}
});
}
void _getQuotasAction(AccountId accountId) {
enableShowQuotas.value = mailboxDashBoardController.sessionCurrent != null &&
mailboxDashBoardController.sessionCurrent!.capabilities.containsValue(CapabilityIdentifier.jmapQuota);
if(enableShowQuotas.isTrue) {
consumeState(_getQuotasInteractor.execute(mailboxDashBoardController.accountId.value!));
}
}
@override
void onDone() {
viewState.value.fold(
(failure) {
if (failure is GetQuotasFailure) {
logError('QuotasController::onDone():[GetQuotasFailure]: ${failure.exception}');
}
},
(success) {
if (success is GetQuotasSuccess) {
_handleGetQuotasSuccess(success);
}
(failure) {
if (failure is GetQuotasFailure) {
logError('QuotasController::onDone():[GetQuotasFailure]: ${failure.exception}');
}
},
(success) {
if (success is GetQuotasSuccess) {
_handleGetQuotasSuccess(success);
}
}
);
}
@@ -62,10 +72,16 @@ class QuotasController extends BaseController {
usedCapacity.value = quotas.used.value;
warningLimitCapacity.value = quotas.warnLimit?.value ?? 0;
softLimitCapacity.value = quotas.softLimit?.value ?? 0;
if(usedCapacity.value >= softLimitCapacity.value) {
quotasState.value = QuotasState.runOutOfStorage;
} else if (usedCapacity.value >= warningLimitCapacity.value) {
quotasState.value = QuotasState.runningOutOfStorage;
} else {
quotasState.value = QuotasState.normal;
}
} catch (e) {
logError('QuotasController::_handleGetQuotasSuccess():[NotFoundException]: $e');
}
}
@override
@@ -6,15 +6,15 @@ import 'package:tmail_ui_user/features/quotas/presentation/quotas_controller.dar
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
class QuotasFooterWidget extends GetWidget<QuotasController> {
const QuotasFooterWidget({Key? key}) : super(key: key);
const QuotasFooterWidget({Key? key, this.padding}) : super(key: key);
final EdgeInsetsGeometry? padding;
@override
Widget build(BuildContext context) {
return Obx(
() => controller.enableShowQuotas.value
? Container(
color: AppColor.colorBgDesktop,
padding: const EdgeInsets.all(24),
padding: padding ?? const EdgeInsets.all(24),
alignment: Alignment.centerLeft,
child: IntrinsicWidth(
child: Column(
@@ -36,21 +36,23 @@ class QuotasFooterWidget extends GetWidget<QuotasController> {
),
const SizedBox(height: 8),
LinearProgressIndicator(
color: controller.enableShowWarningQuotas ? AppColor.colorProgressQuotasWarning: AppColor.primaryColor,
color: controller.quotasState.value.getColorProgress(),
minHeight: 3,
backgroundColor: AppColor.colorDivider,
value: controller.progressUsedCapacity,
),
const SizedBox(height: 8),
Text(
AppLocalizations.of(context).textQuotasUsed(
controller.quotasState.value.getQuotasFooterText(
context,
controller.usedCapacity.value,
controller.softLimitCapacity.value,
),
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w400,
color: AppColor.loginTextFieldHintColor),
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w400,
color: controller.quotasState.value.getColorQuotasFooterText(),
),
)
],
),
@@ -3,10 +3,10 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/quotas/presentation/quotas_controller.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
class QuotasWarningBannerWidget extends GetWidget<QuotasController> {
const QuotasWarningBannerWidget({Key? key}) : super(key: key);
const QuotasWarningBannerWidget({this.margin ,Key? key}) : super(key: key);
final EdgeInsetsGeometry? margin;
@override
Widget build(BuildContext context) {
@@ -14,36 +14,38 @@ class QuotasWarningBannerWidget extends GetWidget<QuotasController> {
() => controller.enableShowWarningQuotas
? Container(
padding: const EdgeInsets.all(16),
margin: const EdgeInsets.only(left: 12, right: 12, top: 8),
margin: margin ?? const EdgeInsets.only(left: 12, right: 12, top: 8),
decoration: BoxDecoration(
color: AppColor.colorBackgroundQuotasWarning.withOpacity(0.12),
color: controller.quotasState.value.getBackgroundColorWarningBanner(),
borderRadius: const BorderRadius.all(Radius.circular(10)),
),
child: Row(
children: [
SvgPicture.asset(controller.imagePaths.icQuotasWarning),
SvgPicture.asset(controller.quotasState.value.getIconWarningBanner(controller.imagePaths)),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppLocalizations.of(context)
.textQuotasWarningTitle(controller.progressUsedCapacity *100),
controller.quotasState.value.getTitleWarningBanner(
context,
controller.progressUsedCapacity,
),
style: const TextStyle(
fontSize: 17,
fontWeight: FontWeight.w700,
color: AppColor.colorTitleQuotasWarning,
fontSize: 17,
fontWeight: FontWeight.w700,
color: AppColor.colorTitleQuotasWarning,
),
),
const SizedBox(height: 8),
Text(
AppLocalizations.of(context)
.textQuotasWarningContent,
controller.quotasState.value.getContentWarningBanner(context),
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
color: AppColor.loginTextFieldHintColor),
fontSize: 15,
fontWeight: FontWeight.w400,
color: AppColor.loginTextFieldHintColor,
),
),
],
),
+30 -8
View File
@@ -1,9 +1,13 @@
{
<<<<<<< HEAD
<<<<<<< HEAD
"@@last_modified": "2022-11-08T16:55:51.988372",
=======
"@@last_modified": "2022-11-09T17:10:23.172672",
>>>>>>> 24967b2c (TF-1014: [Dev] Show quota at the bottom of mailbox)
=======
"@@last_modified": "2022-11-10T10:33:41.637215",
>>>>>>> 1ad5dd5c (TF-1014: add quotas out of storage)
"initializing_data": "Initializing data...",
"@initializing_data": {
"type": "text",
@@ -124,12 +128,6 @@
"placeholders_order": [],
"placeholders": {}
},
"storage": "STORAGE",
"@storage": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"myFolders": "My Folders",
"@myFolders": {
"type": "text",
@@ -2473,8 +2471,8 @@
"softLimit": {}
}
},
"textQuotasWarningTitle": "You are running out of storage ({progress}%).",
"@textQuotasWarningTitle": {
"textQuotasRunningOutOfStorageTitle": "You are running out of storage ({progress}%).",
"@textQuotasRunningOutOfStorageTitle": {
"type": "text",
"placeholders_order": [
"progress"
@@ -2483,5 +2481,29 @@
"progress": {}
>>>>>>> 24967b2c (TF-1014: [Dev] Show quota at the bottom of mailbox)
}
},
"textQuotasRunningOutOfStorageContent": "Soon you won't be able to email in Team Mail. Please clean your storage or upgrade your storage to get full features in Team Mail.",
"@textQuotasRunningOutOfStorageContent": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"textQuotasOutOfStorage": "Out of storage",
"@textQuotasOutOfStorage": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"textQuotasRunOutOfStorageTitle": "You have run out of storage space",
"@textQuotasRunOutOfStorageTitle": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"textQuotasRunOutOfStorageContent": "Now you temporarily can't send or get an email. Please free up or upgrade your storage to get the full features of Team Mail.",
"@textQuotasRunOutOfStorageContent": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
}
}
+27 -13
View File
@@ -117,13 +117,6 @@ class AppLocalizations {
);
}
String get storage {
return Intl.message(
'STORAGE',
name: 'storage',
);
}
String get myFolders {
return Intl.message(
'My Folders',
@@ -2527,7 +2520,7 @@ class AppLocalizations {
);
}
String textQuotasUsed(num used, num softLimit) {
String textQuotasUsed(double used, double softLimit) {
return Intl.message(
'$used GB of $softLimit GB Used',
name: 'textQuotasUsed',
@@ -2535,18 +2528,39 @@ class AppLocalizations {
);
}
String textQuotasWarningTitle(num progress) {
String textQuotasRunningOutOfStorageTitle(double progress) {
return Intl.message(
'You are running out of storage ($progress%).',
name: 'textQuotasWarningTitle',
name: 'textQuotasRunningOutOfStorageTitle',
args: [progress],
);
}
String get textQuotasWarningContent {
String get textQuotasRunningOutOfStorageContent {
return Intl.message(
"Soon you won't be able to email in Tmail. Please clean your storage or upgrade your storage to get full features in Tmail.",
name: 'textQuotasWarningTitle',
"Soon you won't be able to email in Team Mail. Please clean your storage or upgrade your storage to get full features in Team Mail.",
name: 'textQuotasRunningOutOfStorageContent',
);
}
String get textQuotasOutOfStorage {
return Intl.message(
'Out of storage',
name: 'textQuotasOutOfStorage',
);
}
String get textQuotasRunOutOfStorageTitle {
return Intl.message(
'You have run out of storage space',
name: 'textQuotasRunOutOfStorageTitle',
);
}
String get textQuotasRunOutOfStorageContent {
return Intl.message(
"Now you temporarily can't send or get an email. Please free up or upgrade your storage to get the full features of Team Mail.",
name: 'textQuotasRunOutOfStorageContent',
);
}
}