TF-3977 Add disable spam banner in preferences setting
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/local_setting_options.dart';
|
||||
|
||||
class LocalSettingCacheManager {
|
||||
const LocalSettingCacheManager(this._sharedPreferences);
|
||||
|
||||
final SharedPreferences _sharedPreferences;
|
||||
|
||||
Future<void> update(
|
||||
Map<SupportedLocalSetting, LocalSettingOptions?> localSettings,
|
||||
) async {
|
||||
await Future.wait(localSettings.entries.map((entry) async {
|
||||
if (entry.value == null) {
|
||||
await _sharedPreferences.remove(entry.key.name);
|
||||
return;
|
||||
}
|
||||
|
||||
await _sharedPreferences.setString(
|
||||
entry.key.name,
|
||||
jsonEncode(entry.value!.toJson()),
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
Future<Map<SupportedLocalSetting, LocalSettingOptions?>> get(
|
||||
List<SupportedLocalSetting> supportedLocalSettings,
|
||||
) async {
|
||||
await _sharedPreferences.reload();
|
||||
|
||||
return Map.fromEntries(supportedLocalSettings.map((supportedLocalSetting) {
|
||||
final data = _sharedPreferences.getString(supportedLocalSetting.name);
|
||||
|
||||
return MapEntry(
|
||||
supportedLocalSetting,
|
||||
data == null ? null : LocalSettingOptions.fromJson(jsonDecode(data)),
|
||||
);
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/preferences/preferences_root.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/preferences/spam_report_config.dart';
|
||||
|
||||
class PreferencesSettingManager {
|
||||
static const String _preferencesSettingKey = 'PREFERENCES_SETTING';
|
||||
|
||||
const PreferencesSettingManager(this._sharedPreferences);
|
||||
|
||||
final SharedPreferences _sharedPreferences;
|
||||
|
||||
Future<PreferencesRoot> loadPreferences() async {
|
||||
await _sharedPreferences.reload();
|
||||
|
||||
final jsonString = _sharedPreferences.getString(_preferencesSettingKey);
|
||||
|
||||
if (jsonString != null) {
|
||||
return PreferencesRoot.fromJson(jsonDecode(jsonString));
|
||||
}
|
||||
|
||||
return PreferencesRoot.initial();
|
||||
}
|
||||
|
||||
Future<void> savePreferences(PreferencesRoot root) async {
|
||||
await _sharedPreferences.setString(
|
||||
_preferencesSettingKey,
|
||||
jsonEncode(root.toJson()),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> updateThread(bool enabled) async {
|
||||
final current = await loadPreferences();
|
||||
final updated = current.updateThreadDetail(enabled);
|
||||
await savePreferences(updated);
|
||||
}
|
||||
|
||||
Future<void> updateSpamReport({
|
||||
bool? isEnabled,
|
||||
int? lastTimeDismissedMilliseconds,
|
||||
}) async {
|
||||
final current = await loadPreferences();
|
||||
final updated = current.updateSpamReport(
|
||||
isEnabled: isEnabled,
|
||||
lastTimeDismissedMilliseconds: lastTimeDismissedMilliseconds,
|
||||
);
|
||||
await savePreferences(updated);
|
||||
}
|
||||
|
||||
Future<SpamReportConfig> getSpamReportConfig() async {
|
||||
final preferences = await loadPreferences();
|
||||
return preferences.setting.spamReport;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user