diff --git a/assets/translation.json b/assets/translation.json index 92816e6..ae9f0cb 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -204,7 +204,8 @@ "Select in range": "区间选择", "Finished": "已完成", "Updating": "更新中", - "Update Comics Info": "更新漫画信息" + "Update Comics Info": "更新漫画信息", + "Create Folder": "新建文件夹" }, "zh_TW": { "Home": "首頁", @@ -411,6 +412,7 @@ "Select in range": "區間選擇", "Finished": "已完成", "Updating": "更新中", - "Update Comics Info": "更新漫畫信息" + "Update Comics Info": "更新漫畫信息", + "Create Folder": "新建文件夾" } } \ No newline at end of file diff --git a/lib/foundation/favorites.dart b/lib/foundation/favorites.dart index 3482601..eef3fa3 100644 --- a/lib/foundation/favorites.dart +++ b/lib/foundation/favorites.dart @@ -238,12 +238,12 @@ class LocalFavoritesManager with ChangeNotifier { return folders; } - void updateOrder(Map order) { - for (var folder in order.keys) { + void updateOrder(List folders) { + for (int i = 0; i < folders.length; i++) { _db.execute(""" insert or replace into folder_order (folder_name, order_value) values (?, ?); - """, [folder, order[folder]]); + """, [folders[i], i]); } notifyListeners(); } diff --git a/lib/pages/favorites/favorite_actions.dart b/lib/pages/favorites/favorite_actions.dart index 21d1634..1cb8847 100644 --- a/lib/pages/favorites/favorite_actions.dart +++ b/lib/pages/favorites/favorite_actions.dart @@ -159,7 +159,7 @@ Future> updateComicsInfo(String folder) async { return; } catch (e) { retry--; - if(retry == 0) { + if (retry == 0) { rethrow; } continue; @@ -205,7 +205,7 @@ Future> updateComicsInfo(String folder) async { isCanceled = true; context.pop(); }, - child: isFinished ?Text("OK".tl) : Text("Cancel".tl), + child: isFinished ? Text("OK".tl) : Text("Cancel".tl), ), ], ); @@ -216,16 +216,16 @@ Future> updateComicsInfo(String folder) async { isCanceled = true; }); - while(index < comics.length) { + while (index < comics.length) { var futures = []; const maxConcurrency = 4; - if(isCanceled) { + if (isCanceled) { return comics; } for (var i = 0; i < maxConcurrency; i++) { - if (index+i >= comics.length) break; + if (index + i >= comics.length) break; futures.add(updateSingleComic(index + i).then((v) { finished.value++; }, onError: (_) { @@ -240,3 +240,51 @@ Future> updateComicsInfo(String folder) async { return comics; } + +Future sortFolders() async { + var folders = LocalFavoritesManager().folderNames; + + await showPopUpWidget( + App.rootContext, + StatefulBuilder(builder: (context, setState) { + return PopUpWidgetScaffold( + title: "Sort".tl, + tailing: [ + Tooltip( + message: "Help".tl, + child: IconButton( + icon: const Icon(Icons.help_outline), + onPressed: () { + showInfoDialog( + context: context, + title: "Reorder".tl, + content: "Long press and drag to reorder.".tl, + ); + }, + ), + ) + ], + body: ReorderableListView.builder( + onReorder: (oldIndex, newIndex) { + if (oldIndex < newIndex) { + newIndex--; + } + setState(() { + var item = folders.removeAt(oldIndex); + folders.insert(newIndex, item); + }); + }, + itemCount: folders.length, + itemBuilder: (context, index) { + return ListTile( + key: ValueKey(folders[index]), + title: Text(folders[index]), + ); + }, + ), + ); + }), + ); + + LocalFavoritesManager().updateOrder(folders); +} diff --git a/lib/pages/favorites/side_bar.dart b/lib/pages/favorites/side_bar.dart index acc403f..72fd0ae 100644 --- a/lib/pages/favorites/side_bar.dart +++ b/lib/pages/favorites/side_bar.dart @@ -80,7 +80,6 @@ class _LeftBarState extends State<_LeftBar> implements FolderList { padding: const EdgeInsets.symmetric(vertical: 8), child: Row( children: [ - const SizedBox(width: 16), Icon( Icons.local_activity, color: context.colorScheme.secondary, @@ -88,27 +87,41 @@ class _LeftBarState extends State<_LeftBar> implements FolderList { const SizedBox(width: 12), Text("Local".tl), const Spacer(), - IconButton( - icon: const Icon(Icons.search), - color: context.colorScheme.primary, - onPressed: () { - context.to(() => const LocalSearchPage()); - }, + MenuButton( + entries: [ + MenuEntry( + icon: Icons.search, + text: 'Search'.tl, + onClick: () { + context.to(() => const LocalSearchPage()); + }, + ), + MenuEntry( + icon: Icons.add, + text: 'Create Folder'.tl, + onClick: () { + newFolder().then((value) { + setState(() { + folders = LocalFavoritesManager().folderNames; + }); + }); + }, + ), + MenuEntry( + icon: Icons.reorder, + text: 'Sort'.tl, + onClick: () { + sortFolders().then((value) { + setState(() { + folders = LocalFavoritesManager().folderNames; + }); + }); + }, + ), + ], ), - IconButton( - icon: const Icon(Icons.add), - color: context.colorScheme.primary, - onPressed: () { - newFolder().then((value) { - setState(() { - folders = LocalFavoritesManager().folderNames; - }); - }); - }, - ), - const SizedBox(width: 16), ], - ), + ).paddingHorizontal(16), ); } index--; @@ -219,13 +232,13 @@ class _LeftBarState extends State<_LeftBar> implements FolderList { @override void update() { - if(!mounted) return; + if (!mounted) return; setState(() {}); } @override void updateFolders() { - if(!mounted) return; + if (!mounted) return; setState(() { folders = LocalFavoritesManager().folderNames; networkFolders = ComicSource.all()