mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Add sorting folders feature
This commit is contained in:
@@ -204,7 +204,8 @@
|
|||||||
"Select in range": "区间选择",
|
"Select in range": "区间选择",
|
||||||
"Finished": "已完成",
|
"Finished": "已完成",
|
||||||
"Updating": "更新中",
|
"Updating": "更新中",
|
||||||
"Update Comics Info": "更新漫画信息"
|
"Update Comics Info": "更新漫画信息",
|
||||||
|
"Create Folder": "新建文件夹"
|
||||||
},
|
},
|
||||||
"zh_TW": {
|
"zh_TW": {
|
||||||
"Home": "首頁",
|
"Home": "首頁",
|
||||||
@@ -411,6 +412,7 @@
|
|||||||
"Select in range": "區間選擇",
|
"Select in range": "區間選擇",
|
||||||
"Finished": "已完成",
|
"Finished": "已完成",
|
||||||
"Updating": "更新中",
|
"Updating": "更新中",
|
||||||
"Update Comics Info": "更新漫畫信息"
|
"Update Comics Info": "更新漫畫信息",
|
||||||
|
"Create Folder": "新建文件夾"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -238,12 +238,12 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
return folders;
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateOrder(Map<String, int> order) {
|
void updateOrder(List<String> folders) {
|
||||||
for (var folder in order.keys) {
|
for (int i = 0; i < folders.length; i++) {
|
||||||
_db.execute("""
|
_db.execute("""
|
||||||
insert or replace into folder_order (folder_name, order_value)
|
insert or replace into folder_order (folder_name, order_value)
|
||||||
values (?, ?);
|
values (?, ?);
|
||||||
""", [folder, order[folder]]);
|
""", [folders[i], i]);
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
@@ -159,7 +159,7 @@ Future<List<FavoriteItem>> updateComicsInfo(String folder) async {
|
|||||||
return;
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
retry--;
|
retry--;
|
||||||
if(retry == 0) {
|
if (retry == 0) {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -205,7 +205,7 @@ Future<List<FavoriteItem>> updateComicsInfo(String folder) async {
|
|||||||
isCanceled = true;
|
isCanceled = true;
|
||||||
context.pop();
|
context.pop();
|
||||||
},
|
},
|
||||||
child: isFinished ?Text("OK".tl) : Text("Cancel".tl),
|
child: isFinished ? Text("OK".tl) : Text("Cancel".tl),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -216,16 +216,16 @@ Future<List<FavoriteItem>> updateComicsInfo(String folder) async {
|
|||||||
isCanceled = true;
|
isCanceled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
while(index < comics.length) {
|
while (index < comics.length) {
|
||||||
var futures = <Future>[];
|
var futures = <Future>[];
|
||||||
const maxConcurrency = 4;
|
const maxConcurrency = 4;
|
||||||
|
|
||||||
if(isCanceled) {
|
if (isCanceled) {
|
||||||
return comics;
|
return comics;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < maxConcurrency; i++) {
|
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) {
|
futures.add(updateSingleComic(index + i).then((v) {
|
||||||
finished.value++;
|
finished.value++;
|
||||||
}, onError: (_) {
|
}, onError: (_) {
|
||||||
@@ -240,3 +240,51 @@ Future<List<FavoriteItem>> updateComicsInfo(String folder) async {
|
|||||||
|
|
||||||
return comics;
|
return comics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> 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);
|
||||||
|
}
|
||||||
|
@@ -80,7 +80,6 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
|||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(width: 16),
|
|
||||||
Icon(
|
Icon(
|
||||||
Icons.local_activity,
|
Icons.local_activity,
|
||||||
color: context.colorScheme.secondary,
|
color: context.colorScheme.secondary,
|
||||||
@@ -88,17 +87,19 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
|||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Text("Local".tl),
|
Text("Local".tl),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
IconButton(
|
MenuButton(
|
||||||
icon: const Icon(Icons.search),
|
entries: [
|
||||||
color: context.colorScheme.primary,
|
MenuEntry(
|
||||||
onPressed: () {
|
icon: Icons.search,
|
||||||
|
text: 'Search'.tl,
|
||||||
|
onClick: () {
|
||||||
context.to(() => const LocalSearchPage());
|
context.to(() => const LocalSearchPage());
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
MenuEntry(
|
||||||
icon: const Icon(Icons.add),
|
icon: Icons.add,
|
||||||
color: context.colorScheme.primary,
|
text: 'Create Folder'.tl,
|
||||||
onPressed: () {
|
onClick: () {
|
||||||
newFolder().then((value) {
|
newFolder().then((value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
folders = LocalFavoritesManager().folderNames;
|
folders = LocalFavoritesManager().folderNames;
|
||||||
@@ -106,9 +107,21 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
MenuEntry(
|
||||||
|
icon: Icons.reorder,
|
||||||
|
text: 'Sort'.tl,
|
||||||
|
onClick: () {
|
||||||
|
sortFolders().then((value) {
|
||||||
|
setState(() {
|
||||||
|
folders = LocalFavoritesManager().folderNames;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
).paddingHorizontal(16),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
index--;
|
index--;
|
||||||
@@ -219,13 +232,13 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void update() {
|
void update() {
|
||||||
if(!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void updateFolders() {
|
void updateFolders() {
|
||||||
if(!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
folders = LocalFavoritesManager().folderNames;
|
folders = LocalFavoritesManager().folderNames;
|
||||||
networkFolders = ComicSource.all()
|
networkFolders = ComicSource.all()
|
||||||
|
Reference in New Issue
Block a user