TF-3449 Setup Sender-set important flag in Setting View
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/preferences/bindings/preferences_interactors_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/preferences/preferences_controller.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/domain/usecases/get_server_setting_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/domain/usecases/update_server_setting_interactor.dart';
|
||||
|
||||
class PreferencesBindings extends Bindings {
|
||||
|
||||
@override
|
||||
void dependencies() {
|
||||
PreferencesInteractorsBindings().dependencies();
|
||||
|
||||
Get.lazyPut(() => PreferencesController(
|
||||
Get.find<GetServerSettingInteractor>(),
|
||||
Get.find<UpdateServerSettingInteractor>(),
|
||||
));
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/interactors_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/data/datasource/server_settings_data_source.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/data/datasource_impl/remote_server_settings_data_source_impl.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/data/network/server_settings_api.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/data/repository/server_settings_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/domain/repository/server_settings_repository.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/domain/usecases/get_server_setting_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/domain/usecases/update_server_setting_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
|
||||
|
||||
class PreferencesInteractorsBindings extends InteractorsBindings {
|
||||
|
||||
@override
|
||||
void bindingsDataSource() {
|
||||
Get.lazyPut<ServerSettingsDataSource>(() => Get.find<RemoteServerSettingsDataSourceImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsDataSourceImpl() {
|
||||
Get.lazyPut(() => RemoteServerSettingsDataSourceImpl(
|
||||
Get.find<ServerSettingsAPI>(),
|
||||
Get.find<RemoteExceptionThrower>(),
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsInteractor() {
|
||||
Get.lazyPut(() => GetServerSettingInteractor(Get.find<ServerSettingsRepository>()));
|
||||
Get.lazyPut(() => UpdateServerSettingInteractor(Get.find<ServerSettingsRepository>()));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepository() {
|
||||
Get.lazyPut<ServerSettingsRepository>(() => Get.find<ServerSettingsRepositoryImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepositoryImpl() {
|
||||
Get.lazyPut(() => ServerSettingsRepositoryImpl(Get.find<ServerSettingsDataSource>()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:server_settings/server_settings/tmail_server_settings.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/manage_account_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/setting_option_type.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/domain/state/get_server_setting_state.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/domain/state/update_server_setting_state.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/domain/usecases/get_server_setting_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/server_settings/domain/usecases/update_server_setting_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
class PreferencesController extends BaseController {
|
||||
PreferencesController(
|
||||
this._getServerSettingInteractor,
|
||||
this._updateServerSettingInteractor,
|
||||
);
|
||||
|
||||
final GetServerSettingInteractor _getServerSettingInteractor;
|
||||
final UpdateServerSettingInteractor _updateServerSettingInteractor;
|
||||
|
||||
final settingOption = Rxn<TMailServerSettingOptions>();
|
||||
|
||||
bool get isLoading => viewState.value.fold(
|
||||
(failure) => false,
|
||||
(success) => success is GettingServerSetting || success is UpdatingServerSetting);
|
||||
|
||||
final _manageAccountDashBoardController = Get.find<ManageAccountDashBoardController>();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_getSettingOption();
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSuccessViewState(Success success) {
|
||||
if (success is GetServerSettingSuccess) {
|
||||
_updateSettingOptionValue(newSettingOption: success.settingOption);
|
||||
} else if (success is UpdateServerSettingSuccess) {
|
||||
_updateSettingOptionValue(newSettingOption: success.settingOption);
|
||||
} else {
|
||||
super.handleSuccessViewState(success);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void handleFailureViewState(Failure failure) {
|
||||
if (failure is GetServerSettingFailure) {
|
||||
_updateSettingOptionValue(newSettingOption: null);
|
||||
} else if (failure is UpdateServerSettingFailure) {
|
||||
_handleUpdateServerSettingFailure();
|
||||
} else {
|
||||
super.handleFailureViewState(failure);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleUpdateServerSettingFailure() {
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
appToast.showToastErrorMessage(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).an_error_occurred);
|
||||
}
|
||||
}
|
||||
|
||||
void _updateSettingOptionValue({required TMailServerSettingOptions? newSettingOption}) {
|
||||
settingOption.value = newSettingOption;
|
||||
}
|
||||
|
||||
void _getSettingOption() {
|
||||
final accountId = _manageAccountDashBoardController.accountId.value;
|
||||
if (accountId != null) {
|
||||
consumeState(_getServerSettingInteractor.execute(accountId));
|
||||
} else {
|
||||
consumeState(Stream.value(Left(GetServerSettingFailure(NotFoundAccountIdException()))));
|
||||
}
|
||||
}
|
||||
|
||||
void updateStateSettingOption(SettingOptionType optionType, bool isEnabled) {
|
||||
TMailServerSettingOptions? newSettingOption;
|
||||
switch(optionType) {
|
||||
case SettingOptionType.readReceipt:
|
||||
newSettingOption = settingOption.value?.copyWith(
|
||||
alwaysReadReceipts: !isEnabled,
|
||||
);
|
||||
break;
|
||||
case SettingOptionType.senderPriority:
|
||||
newSettingOption = settingOption.value?.copyWith(
|
||||
displaySenderPriority: !isEnabled,
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
final accountId = _manageAccountDashBoardController.accountId.value;
|
||||
if (accountId != null && newSettingOption != null) {
|
||||
consumeState(_updateServerSettingInteractor.execute(
|
||||
accountId,
|
||||
newSettingOption,
|
||||
));
|
||||
} else {
|
||||
consumeState(Stream.value(Left(UpdateServerSettingFailure(NotFoundAccountIdException()))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/menu/settings_utils.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/setting_option_type.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/preferences/preferences_controller.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/preferences/widgets/setting_option_item.dart';
|
||||
|
||||
class PreferencesView extends GetWidget<PreferencesController> with AppLoaderMixin {
|
||||
const PreferencesView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: SettingsUtils.getBackgroundColor(context, controller.responsiveUtils),
|
||||
body: Padding(
|
||||
padding: SettingsUtils.getMarginViewForSettingDetails(context, controller.responsiveUtils),
|
||||
child: Column(
|
||||
children: [
|
||||
Obx(() {
|
||||
if (!controller.isLoading) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: horizontalLoadingWidget,
|
||||
);
|
||||
}),
|
||||
Expanded(
|
||||
child: Container(
|
||||
color: SettingsUtils.getContentBackgroundColor(
|
||||
context, controller.responsiveUtils,
|
||||
),
|
||||
decoration: SettingsUtils.getBoxDecorationForContent(
|
||||
context,
|
||||
controller.responsiveUtils,
|
||||
),
|
||||
width: double.infinity,
|
||||
padding: SettingsUtils.getPaddingAlwaysReadReceiptSetting(
|
||||
context,
|
||||
controller.responsiveUtils,
|
||||
),
|
||||
child: Obx(() {
|
||||
final settingOption = controller.settingOption.value;
|
||||
|
||||
if (settingOption == null) return const SizedBox.shrink();
|
||||
|
||||
final settingOptionList = SettingOptionType.values.toList();
|
||||
|
||||
return ListView.separated(
|
||||
itemCount: settingOptionList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return SettingOptionItem(
|
||||
imagePaths: controller.imagePaths,
|
||||
settingOption: settingOption,
|
||||
optionType: settingOptionList[index],
|
||||
onTapSettingOptionAction: controller.updateStateSettingOption,
|
||||
);
|
||||
},
|
||||
separatorBuilder: (_, __) => const SizedBox(height: 60),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:server_settings/server_settings/tmail_server_settings.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/setting_option_type.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
typedef OnTapSettingOptionAction = Function(SettingOptionType optionType, bool isEnabled);
|
||||
|
||||
class SettingOptionItem extends StatelessWidget {
|
||||
|
||||
final ImagePaths imagePaths;
|
||||
final TMailServerSettingOptions settingOption;
|
||||
final SettingOptionType optionType;
|
||||
final OnTapSettingOptionAction onTapSettingOptionAction;
|
||||
|
||||
const SettingOptionItem({
|
||||
super.key,
|
||||
required this.imagePaths,
|
||||
required this.settingOption,
|
||||
required this.optionType,
|
||||
required this.onTapSettingOptionAction,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appLocalizations = AppLocalizations.of(context);
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
optionType.getTitle(appLocalizations),
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
height: 20 / 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
child: Text(
|
||||
optionType.getExplanation(appLocalizations),
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
height: 16 / 13,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () => onTapSettingOptionAction(
|
||||
optionType,
|
||||
optionType.isEnabled(settingOption),
|
||||
),
|
||||
child: SvgPicture.asset(
|
||||
optionType.isEnabled(settingOption)
|
||||
? imagePaths.icSwitchOn
|
||||
: imagePaths.icSwitchOff,
|
||||
fit: BoxFit.fill,
|
||||
width: 44,
|
||||
height: 28,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
optionType.getToggleDescription(appLocalizations),
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
height: 16 / 13,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user