TF-2269 Show the report once a day

Signed-off-by: dab246 <tdvu@linagora.com>

Signed-off-by: dab246 <tdvu@linagora.com>

Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit 74bed6e6dfbd32d70baeb131546b490199bb8fbb)
This commit is contained in:
dab246
2023-11-06 12:32:20 +07:00
committed by Dat Vu
parent b4cf796a57
commit 54ff9bdada
4 changed files with 32 additions and 27 deletions
@@ -1,39 +1,44 @@
import 'package:core/utils/app_logger.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/spam_report_state.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/utils/mailbox_dashboard_constant.dart';
class LocalSpamReportManager {
static const String _keyLastTimeDismissedSpamReported = 'KEY_LAST_TIME_DISMISSED_SPAM_REPORTED';
static const String _keySpamReportState = 'KEY_SPAM_REPORT_STATE';
final SharedPreferences _sharedPreferences;
LocalSpamReportManager(this._sharedPreferences);
Future<DateTime> getLastTimeDismissedSpamReported() async {
final timeStamp = _sharedPreferences.getInt(MailboxDashboardConstant.keyLastTimeDismissedSpamReported) ?? 0;
final timeStamp = _sharedPreferences.getInt(_keyLastTimeDismissedSpamReported) ?? 0;
log('LocalSpamReportManager::getLastTimeDismissedSpamReported:timeStamp: $timeStamp');
final lastTimeDismissedSpamReported = DateTime.fromMillisecondsSinceEpoch(timeStamp);
return lastTimeDismissedSpamReported;
}
Future<bool> storeLastTimeDismissedSpamReported(DateTime lastTimeDismissedSpamReported) async {
final timeStamp = lastTimeDismissedSpamReported.millisecondsSinceEpoch;
return await _sharedPreferences.setInt(MailboxDashboardConstant.keyLastTimeDismissedSpamReported,timeStamp);
log('LocalSpamReportManager::storeLastTimeDismissedSpamReported:timeStamp: $timeStamp');
return await _sharedPreferences.setInt(_keyLastTimeDismissedSpamReported, timeStamp);
}
Future<bool> deleteLastTimeDismissedSpamReported() async {
return await _sharedPreferences.remove(MailboxDashboardConstant.keyLastTimeDismissedSpamReported);
return await _sharedPreferences.remove(_keyLastTimeDismissedSpamReported);
}
Future<bool> deleteSpamReportState() async {
return await _sharedPreferences.remove(MailboxDashboardConstant.keySpamReportState);
return await _sharedPreferences.remove(_keySpamReportState);
}
Future<SpamReportState> getSpamReportState() async {
final spamReportState = _sharedPreferences.getString(MailboxDashboardConstant.keySpamReportState) ?? '';
final spamReportState = _sharedPreferences.getString(_keySpamReportState) ?? '';
return spamReportState == SpamReportState.disabled.keyValue ? SpamReportState.disabled : SpamReportState.enabled;
}
Future<bool> storeSpamReportState(SpamReportState spamReportState) async {
final spamReportState0 = spamReportState.keyValue;
return await _sharedPreferences.setString(MailboxDashboardConstant.keySpamReportState, spamReportState0);
return await _sharedPreferences.setString(_keySpamReportState, spamReportState0);
}
Future<void> clear() async {