浏览代码

Fix sort option names

Neeraj Gupta 3 年之前
父节点
当前提交
512b724f8e
共有 2 个文件被更改,包括 49 次插入35 次删除
  1. 47 32
      lib/ui/collections_gallery_widget.dart
  2. 2 3
      lib/utils/local_settings.dart

+ 47 - 32
lib/ui/collections_gallery_widget.dart

@@ -152,38 +152,7 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
                   ),
             Padding(padding: EdgeInsets.all(4)),
             Divider(),
-            PopupMenuButton(
-              offset: Offset(10, 40),
-              initialValue: sortKey?.index ?? 0,
-              child: Align(
-                  child: Row(
-                mainAxisAlignment: MainAxisAlignment.end,
-                children: [
-                  Text(sortKey.toString(),
-                    style: TextStyle(
-                      fontWeight: FontWeight.bold,
-                      fontSize: 12,
-                      color: Theme.of(context).buttonColor,
-                    ),
-                  ),
-                  Padding(padding: EdgeInsets.only(left: 5.0)),
-                  Icon(Icons.sort_outlined),
-                ],
-              )),
-              onSelected: (int index) {
-                setState(() {
-                  sortKey = AlbumSortKey.values[index];
-                });
-              },
-              itemBuilder: (context) {
-                return List.generate(AlbumSortKey.values.length, (index) {
-                  return PopupMenuItem(
-                    value: index,
-                    child: Text('${AlbumSortKey.values[index]}'),
-                  );
-                });
-              },
-            ),
+            _sortMenu(),
             SectionTitle("on ente"),
             Padding(padding: EdgeInsets.all(12)),
             Configuration.instance.hasConfiguredAccount()
@@ -209,6 +178,52 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
     );
   }
 
+  PopupMenuButton<int> _sortMenu() {
+    String sortOptionText(AlbumSortKey key) {
+      switch (key) {
+        case AlbumSortKey.albumName:
+          return "album name";
+        case AlbumSortKey.lastUpdated:
+          return "last updated";
+        case AlbumSortKey.recentPhoto:
+          return "recent photo";
+      }
+      return key.toString();
+    }
+    return PopupMenuButton(
+            offset: Offset(10, 40),
+            initialValue: sortKey?.index ?? 0,
+            child: Align(
+                child: Row(
+              mainAxisAlignment: MainAxisAlignment.end,
+              children: [
+                Text(sortOptionText(sortKey),
+                  style: TextStyle(
+                    fontWeight: FontWeight.bold,
+                    fontSize: 14,
+                    color: Theme.of(context).buttonColor,
+                  ),
+                ),
+                Padding(padding: EdgeInsets.only(left: 5.0)),
+                Icon(Icons.sort_outlined),
+              ],
+            )),
+            onSelected: (int index) {
+              setState(() {
+                sortKey = AlbumSortKey.values[index];
+              });
+            },
+            itemBuilder: (context) {
+              return List.generate(AlbumSortKey.values.length, (index) {
+                return PopupMenuItem(
+                  value: index,
+                  child: Text(sortOptionText(AlbumSortKey.values[index])),
+                );
+              });
+            },
+          );
+  }
+
   Widget _buildCollection(BuildContext context,
       List<CollectionWithThumbnail> collections, int index) {
     if (index < collections.length) {

+ 2 - 3
lib/utils/local_settings.dart

@@ -1,9 +1,8 @@
-import 'package:logging/logging.dart';
 import 'package:shared_preferences/shared_preferences.dart';
 
 enum AlbumSortKey {
   albumName,
-  lastModified,
+  lastUpdated,
   recentPhoto,
 }
 
@@ -20,7 +19,7 @@ class LocalSettings {
 
   AlbumSortKey albumSortKey() {
     return AlbumSortKey.values[_prefs?.getInt(kCollectionSortPref) ?? 0] ??
-        AlbumSortKey.lastModified;
+        AlbumSortKey.lastUpdated;
   }
 
   void setAlbumSortKey(AlbumSortKey key) {