TF-1014: [Dev] Show quota at the bottom of mailbox
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/quotas/data/datasource/quotas_data_source.dart';
|
||||
import 'package:tmail_ui_user/features/quotas/data/datasource_impl/quotas_data_source_impl.dart';
|
||||
import 'package:tmail_ui_user/features/quotas/data/network/quotas_api.dart';
|
||||
import 'package:tmail_ui_user/features/quotas/data/repository/quotas_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/quotas/domain/repository/quotas_repository.dart';
|
||||
import 'package:tmail_ui_user/features/quotas/domain/use_case/get_quotas_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/quotas/presentation/quotas_controller.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
|
||||
|
||||
class QuotasBindings extends BaseBindings {
|
||||
@override
|
||||
void bindingsController() {
|
||||
Get.put(QuotasController(Get.find<GetQuotasInteractor>()));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsDataSource() {
|
||||
Get.lazyPut<QuotasDataSource>(() => Get.find<QuotasDataSourceImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsDataSourceImpl() {
|
||||
Get.lazyPut(() => QuotasDataSourceImpl(Get.find<QuotasAPI>(), Get.find<RemoteExceptionThrower>()));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsInteractor() {
|
||||
Get.lazyPut(() => GetQuotasInteractor(Get.find<QuotasRepository>()));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepository() {
|
||||
Get.lazyPut<QuotasRepository>(() => Get.find<QuotasRepositoryImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepositoryImpl() {
|
||||
Get.lazyPut(() => QuotasRepositoryImpl(Get.find<QuotasDataSource>()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/quotas/data_types.dart';
|
||||
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';
|
||||
|
||||
class QuotasController extends BaseController {
|
||||
final MailboxDashBoardController mailboxDashBoardController = Get.find<MailboxDashBoardController>();
|
||||
final GetQuotasInteractor _getQuotasInteractor;
|
||||
final usedCapacity = Rx<num>(0);
|
||||
final softLimitCapacity = Rx<num>(0);
|
||||
final warningLimitCapacity = Rx<num>(0);
|
||||
final enableShowQuotas = false.obs;
|
||||
late Worker accountIdWorker;
|
||||
|
||||
double get progressUsedCapacity => softLimitCapacity.value != 0
|
||||
? (usedCapacity.value / softLimitCapacity.value)
|
||||
: 0;
|
||||
|
||||
bool get enableShowWarningQuotas =>
|
||||
enableShowQuotas.value && usedCapacity.value >= warningLimitCapacity.value;
|
||||
|
||||
final ImagePaths imagePaths = Get.find<ImagePaths>();
|
||||
final ResponsiveUtils responsiveUtils = Get.find<ResponsiveUtils>();
|
||||
|
||||
QuotasController(this._getQuotasInteractor);
|
||||
|
||||
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!));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void onDone() {
|
||||
viewState.value.fold(
|
||||
(failure) {
|
||||
if (failure is GetQuotasFailure) {
|
||||
logError('QuotasController::onDone():[GetQuotasFailure]: ${failure.exception}');
|
||||
}
|
||||
},
|
||||
(success) {
|
||||
if (success is GetQuotasSuccess) {
|
||||
_handleGetQuotasSuccess(success);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void _handleGetQuotasSuccess(GetQuotasSuccess success) {
|
||||
try {
|
||||
final quotas = success.quotas.firstWhere((e) => e.resourceType == ResourceType.octets);
|
||||
usedCapacity.value = quotas.used.value;
|
||||
warningLimitCapacity.value = quotas.warnLimit?.value ?? 0;
|
||||
softLimitCapacity.value = quotas.softLimit?.value ?? 0;
|
||||
} catch (e) {
|
||||
logError('QuotasController::_handleGetQuotasSuccess():[NotFoundException]: $e');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
_initWorker();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
accountIdWorker.call();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import 'package:core/core.dart';
|
||||
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 QuotasFooterWidget extends GetWidget<QuotasController> {
|
||||
const QuotasFooterWidget({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(
|
||||
() => controller.enableShowQuotas.value
|
||||
? Container(
|
||||
color: AppColor.colorBgDesktop,
|
||||
padding: const EdgeInsets.all(24),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: IntrinsicWidth(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SvgPicture.asset(controller.imagePaths.icQuotas),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
AppLocalizations.of(context).storageQuotas,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColor.loginTextFieldHintColor),
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(
|
||||
color: controller.enableShowWarningQuotas ? AppColor.colorProgressQuotasWarning: AppColor.primaryColor,
|
||||
minHeight: 3,
|
||||
backgroundColor: AppColor.colorDivider,
|
||||
value: controller.progressUsedCapacity,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
AppLocalizations.of(context).textQuotasUsed(
|
||||
controller.usedCapacity.value,
|
||||
controller.softLimitCapacity.value,
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColor.loginTextFieldHintColor),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'package:core/core.dart';
|
||||
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);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(
|
||||
() => controller.enableShowWarningQuotas
|
||||
? Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
margin: const EdgeInsets.only(left: 12, right: 12, top: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.colorBackgroundQuotasWarning.withOpacity(0.12),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
SvgPicture.asset(controller.imagePaths.icQuotasWarning),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context)
|
||||
.textQuotasWarningTitle(controller.progressUsedCapacity *100),
|
||||
style: const TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColor.colorTitleQuotasWarning,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
AppLocalizations.of(context)
|
||||
.textQuotasWarningContent,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColor.loginTextFieldHintColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user