TF-1014: add quotas out of storage
This commit is contained in:
@@ -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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user