浏览代码

minor refactor

Neeraj Gupta 2 年之前
父节点
当前提交
b392b90b8f
共有 2 个文件被更改,包括 9 次插入9 次删除
  1. 1 9
      lib/ui/viewer/gallery/gallery.dart
  2. 8 0
      lib/utils/date_time_util.dart

+ 1 - 9
lib/ui/viewer/gallery/gallery.dart

@@ -285,7 +285,7 @@ class _GalleryState extends State<Gallery> {
     final List<List<File>> collatedFiles = [];
     for (int index = 0; index < files.length; index++) {
       if (index > 0 &&
-          !_areFromSameDay(
+          !areFromSameDay(
             files[index - 1].creationTime,
             files[index].creationTime,
           )) {
@@ -303,14 +303,6 @@ class _GalleryState extends State<Gallery> {
         .sort((a, b) => b[0].creationTime.compareTo(a[0].creationTime));
     return collatedFiles;
   }
-
-  bool _areFromSameDay(int firstCreationTime, int secondCreationTime) {
-    final firstDate = DateTime.fromMicrosecondsSinceEpoch(firstCreationTime);
-    final secondDate = DateTime.fromMicrosecondsSinceEpoch(secondCreationTime);
-    return firstDate.year == secondDate.year &&
-        firstDate.month == secondDate.month &&
-        firstDate.day == secondDate.day;
-  }
 }
 
 class GalleryIndexUpdatedEvent {

+ 8 - 0
lib/utils/date_time_util.dart

@@ -60,6 +60,14 @@ int daysBetween(DateTime from, DateTime to) {
   return (to.difference(from).inHours / 24).round();
 }
 
+bool areFromSameDay(int firstCreationTime, int secondCreationTime) {
+  final firstDate = DateTime.fromMicrosecondsSinceEpoch(firstCreationTime);
+  final secondDate = DateTime.fromMicrosecondsSinceEpoch(secondCreationTime);
+  return firstDate.year == secondDate.year &&
+      firstDate.month == secondDate.month &&
+      firstDate.day == secondDate.day;
+}
+
 //Thu, 30 Jun
 String getDayAndMonth(DateTime dateTime) {
   return _days[dateTime.weekday]! +