TF-4193 Show/Hide Label list when toggle label state in Setting
This commit is contained in:
@@ -16,4 +16,6 @@ abstract class ManageAccountDataSource {
|
||||
Future<bool> getLabelVisibility();
|
||||
|
||||
Future<void> saveLabelVisibility(bool visible);
|
||||
|
||||
Future<bool> getLabelSettingState();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:tmail_ui_user/features/manage_account/data/local/language_cache_
|
||||
import 'package:tmail_ui_user/features/manage_account/data/local/preferences_setting_manager.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/ai_scribe_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/data/local/setting_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/label_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_setting.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/spam_report_config.dart';
|
||||
@@ -52,6 +53,10 @@ class ManageAccountDataSourceImpl extends ManageAccountDataSource {
|
||||
await _preferencesSettingManager.updateAIScribe(
|
||||
preferencesConfig.isEnabled,
|
||||
);
|
||||
} else if (preferencesConfig is LabelConfig) {
|
||||
await _preferencesSettingManager.updateLabel(
|
||||
preferencesConfig.isEnabled,
|
||||
);
|
||||
} else {
|
||||
await _preferencesSettingManager.savePreferences(
|
||||
preferencesConfig,
|
||||
@@ -94,4 +99,15 @@ class ManageAccountDataSourceImpl extends ManageAccountDataSource {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> getLabelSettingState() {
|
||||
return Future.sync(() async {
|
||||
final labelConfig = await _preferencesSettingManager.getLabelConfig();
|
||||
return labelConfig.isEnabled;
|
||||
}).catchError((error, stackTrace) async {
|
||||
await _exceptionThrower.throwException(error, stackTrace);
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class PreferencesSettingManager {
|
||||
return PreferencesSetting(listConfigs);
|
||||
}
|
||||
|
||||
String _getPreferencesConfig(PreferencesConfig config) {
|
||||
String _getPreferencesConfigKey(PreferencesConfig config) {
|
||||
if (config is ThreadDetailConfig) {
|
||||
return _preferencesSettingThreadKey;
|
||||
} else if (config is SpamReportConfig) {
|
||||
@@ -83,7 +83,7 @@ class PreferencesSettingManager {
|
||||
|
||||
Future<void> savePreferences(PreferencesConfig config) async {
|
||||
await _sharedPreferences.setString(
|
||||
_getPreferencesConfig(config),
|
||||
_getPreferencesConfigKey(config),
|
||||
jsonEncode(config.toJson()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -41,4 +41,9 @@ class ManageAccountRepositoryImpl extends ManageAccountRepository {
|
||||
Future<void> saveLabelVisibility(bool visible) {
|
||||
return dataSource.saveLabelVisibility(visible);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> getLabelSettingState() {
|
||||
return dataSource.getLabelSettingState();
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,6 @@ abstract class ManageAccountRepository {
|
||||
Future<bool> getLabelVisibility();
|
||||
|
||||
Future<void> saveLabelVisibility(bool visible);
|
||||
|
||||
Future<bool> getLabelSettingState();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
|
||||
class GettingLabelSettingState extends LoadingState {}
|
||||
|
||||
class GetLabelSettingStateSuccess extends UIState {
|
||||
final bool isEnabled;
|
||||
final AccountId accountId;
|
||||
|
||||
GetLabelSettingStateSuccess(this.isEnabled, this.accountId);
|
||||
|
||||
@override
|
||||
List<Object> get props => [isEnabled, accountId];
|
||||
}
|
||||
|
||||
class GetLabelSettingStateFailure extends FeatureFailure {
|
||||
GetLabelSettingStateFailure(dynamic exception) : super(exception: exception);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/get_label_setting_state.dart';
|
||||
|
||||
class GetLabelSettingStateInteractor {
|
||||
final ManageAccountRepository _manageAccountRepository;
|
||||
|
||||
GetLabelSettingStateInteractor(this._manageAccountRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
try {
|
||||
yield Right(GettingLabelSettingState());
|
||||
final isEnable = await _manageAccountRepository.getLabelSettingState();
|
||||
yield Right(GetLabelSettingStateSuccess(isEnable, accountId));
|
||||
} catch (e) {
|
||||
yield Left(GetLabelSettingStateFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:tmail_ui_user/features/manage_account/data/local/preferences_set
|
||||
import 'package:tmail_ui_user/features/manage_account/data/local/setting_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/data/repository/manage_account_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_label_setting_state_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_label_visibility_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/usecases/save_label_visibility_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
|
||||
@@ -39,6 +40,9 @@ class SettingInteractorBindings extends InteractorsBindings {
|
||||
Get.lazyPut(
|
||||
() => GetLabelVisibilityInteractor(Get.find<ManageAccountRepository>()),
|
||||
);
|
||||
Get.lazyPut(
|
||||
() => GetLabelSettingStateInteractor(Get.find<ManageAccountRepository>()),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -8,6 +8,7 @@ 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/mailbox_dashboard/presentation/model/loader_status.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/ai_scribe_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/label_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_setting.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/spam_report_config.dart';
|
||||
@@ -162,6 +163,9 @@ class PreferencesController extends BaseController {
|
||||
case PreferencesOptionType.aiScribe:
|
||||
config = AIScribeConfig(isEnabled: !isEnabled);
|
||||
break;
|
||||
case PreferencesOptionType.label:
|
||||
config = LabelConfig(isEnabled: !isEnabled);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user