TF-1068 implement data layer save recent login username & get all login username

This commit is contained in:
Ms Thuỷ
2022-10-24 17:38:41 +07:00
committed by Dat H. Pham
parent 06ec261d05
commit 6cf86b0edf
11 changed files with 230 additions and 0 deletions
@@ -0,0 +1,46 @@
import 'package:equatable/equatable.dart';
import 'package:hive/hive.dart';
import 'package:jmap_dart_client/jmap/core/extensions/date_time_extension.dart';
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
import 'package:tmail_ui_user/features/login/domain/model/recent_login_username.dart';
part 'recent_login_username_cache.g.dart';
@HiveType(typeId: CachingConstants.RECENT_LOGIN_USERNAME_HIVE_CACHE_IDENTITY)
class RecentLoginUsernameCache extends HiveObject with EquatableMixin {
@HiveField(0)
final String username;
@HiveField(1)
final DateTime creationDate;
RecentLoginUsernameCache(this.username, this.creationDate);
@override
List<Object?> get props => [username, creationDate];
}
extension RecentLoginUsernameExtension on RecentLoginUsername {
RecentLoginUsernameCache toRecentLoginUsernameCache() {
return RecentLoginUsernameCache(username, creationDate);
}
}
extension RecentLoginUsernameCacheExtension on RecentLoginUsernameCache {
RecentLoginUsername toRecentLoginUsername() {
return RecentLoginUsername(username, creationDate);
}
bool matchUsername(String pattern) {
return username.toLowerCase().contains(pattern);
}
}
extension ListRecentLoginUsernameCacheExtension on List<RecentLoginUsernameCache> {
void sortByCreationDate() {
sort((recentUsername1, recentUsername2) {
return recentUsername1.creationDate.compareToSort(recentUsername2.creationDate, false);
});
}
}