mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Fix comic menu cannot work in history_page when use mobile device (#204)
This commit is contained in:
@@ -7,7 +7,6 @@ import 'dart:ffi' as ffi;
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/widgets.dart' show ChangeNotifier;
|
import 'package:flutter/widgets.dart' show ChangeNotifier;
|
||||||
import 'package:sqlite3/common.dart';
|
|
||||||
import 'package:sqlite3/sqlite3.dart';
|
import 'package:sqlite3/sqlite3.dart';
|
||||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||||
import 'package:venera/foundation/comic_type.dart';
|
import 'package:venera/foundation/comic_type.dart';
|
||||||
|
@@ -29,12 +29,18 @@ class _HistoryPageState extends State<HistoryPage> {
|
|||||||
void onUpdate() {
|
void onUpdate() {
|
||||||
setState(() {
|
setState(() {
|
||||||
comics = HistoryManager().getAll();
|
comics = HistoryManager().getAll();
|
||||||
|
if (multiSelectMode) {
|
||||||
|
selectedComics.removeWhere((comic, _) => !comics.contains(comic));
|
||||||
|
if (selectedComics.isEmpty) {
|
||||||
|
multiSelectMode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var comics = HistoryManager().getAll();
|
var comics = HistoryManager().getAll();
|
||||||
var controller = FlyoutController();
|
var controller = FlyoutController();
|
||||||
|
|
||||||
bool multiSelectMode = false;
|
bool multiSelectMode = false;
|
||||||
Map<History, bool> selectedComics = {};
|
Map<History, bool> selectedComics = {};
|
||||||
|
|
||||||
@@ -59,55 +65,72 @@ class _HistoryPageState extends State<HistoryPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _removeHistory(History comic) {
|
||||||
|
if (comic.sourceKey.startsWith("Unknown")) {
|
||||||
|
HistoryManager().remove(
|
||||||
|
comic.id,
|
||||||
|
ComicType(int.parse(comic.sourceKey.split(':')[1])),
|
||||||
|
);
|
||||||
|
} else if (comic.sourceKey == 'local') {
|
||||||
|
HistoryManager().remove(
|
||||||
|
comic.id,
|
||||||
|
ComicType.local,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
HistoryManager().remove(
|
||||||
|
comic.id,
|
||||||
|
ComicType(comic.sourceKey.hashCode),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
List<Widget> selectActions = [
|
List<Widget> selectActions = [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.select_all),
|
icon: const Icon(Icons.select_all),
|
||||||
tooltip: "Select All".tl,
|
tooltip: "Select All".tl,
|
||||||
onPressed: selectAll
|
onPressed: selectAll
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.deselect),
|
icon: const Icon(Icons.deselect),
|
||||||
tooltip: "Deselect".tl,
|
tooltip: "Deselect".tl,
|
||||||
onPressed: deSelect
|
onPressed: deSelect
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.flip),
|
icon: const Icon(Icons.flip),
|
||||||
tooltip: "Invert Selection".tl,
|
tooltip: "Invert Selection".tl,
|
||||||
onPressed: invertSelection
|
onPressed: invertSelection
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.delete),
|
icon: const Icon(Icons.delete),
|
||||||
tooltip: "Delete".tl,
|
tooltip: "Delete".tl,
|
||||||
onPressed: selectedComics.isEmpty ? null : () {
|
onPressed: selectedComics.isEmpty
|
||||||
for (final comic in selectedComics.keys) {
|
? null
|
||||||
if (comic.sourceKey.startsWith("Unknown")) {
|
: () {
|
||||||
HistoryManager().remove(
|
final comicsToDelete = List<History>.from(selectedComics.keys);
|
||||||
comic.id,
|
setState(() {
|
||||||
ComicType(int.parse(comic.sourceKey.split(':')[1])),
|
multiSelectMode = false;
|
||||||
);
|
selectedComics.clear();
|
||||||
} else if (comic.sourceKey == 'local') {
|
});
|
||||||
HistoryManager().remove(
|
|
||||||
comic.id,
|
for (final comic in comicsToDelete) {
|
||||||
ComicType.local,
|
_removeHistory(comic);
|
||||||
);
|
}
|
||||||
} else {
|
},
|
||||||
HistoryManager().remove(
|
|
||||||
comic.id,
|
|
||||||
ComicType(comic.sourceKey.hashCode),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setState(() {
|
|
||||||
multiSelectMode = false;
|
|
||||||
selectedComics.clear();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
List<Widget> normalActions = [
|
List<Widget> normalActions = [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.checklist),
|
||||||
|
tooltip: multiSelectMode ? "Exit Multi-Select".tl : "Multi-Select".tl,
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
multiSelectMode = !multiSelectMode;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
Tooltip(
|
Tooltip(
|
||||||
message: 'Clear History'.tl,
|
message: 'Clear History'.tl,
|
||||||
child: Flyout(
|
child: Flyout(
|
||||||
@@ -178,24 +201,21 @@ class _HistoryPageState extends State<HistoryPage> {
|
|||||||
SliverGridComics(
|
SliverGridComics(
|
||||||
comics: comics,
|
comics: comics,
|
||||||
selections: selectedComics,
|
selections: selectedComics,
|
||||||
onLongPressed: (c) {
|
onLongPressed: null,
|
||||||
setState(() {
|
onTap: multiSelectMode
|
||||||
multiSelectMode = true;
|
? (c) {
|
||||||
selectedComics[c as History] = true;
|
setState(() {
|
||||||
});
|
if (selectedComics.containsKey(c as History)) {
|
||||||
},
|
selectedComics.remove(c);
|
||||||
onTap: multiSelectMode ? (c) {
|
} else {
|
||||||
setState(() {
|
selectedComics[c] = true;
|
||||||
if (selectedComics.containsKey(c as History)) {
|
}
|
||||||
selectedComics.remove(c);
|
if (selectedComics.isEmpty) {
|
||||||
} else {
|
multiSelectMode = false;
|
||||||
selectedComics[c] = true;
|
}
|
||||||
}
|
});
|
||||||
if (selectedComics.isEmpty) {
|
}
|
||||||
multiSelectMode = false;
|
: null,
|
||||||
}
|
|
||||||
});
|
|
||||||
} : null,
|
|
||||||
badgeBuilder: (c) {
|
badgeBuilder: (c) {
|
||||||
return ComicSource.find(c.sourceKey)?.name;
|
return ComicSource.find(c.sourceKey)?.name;
|
||||||
},
|
},
|
||||||
@@ -206,22 +226,7 @@ class _HistoryPageState extends State<HistoryPage> {
|
|||||||
text: 'Remove'.tl,
|
text: 'Remove'.tl,
|
||||||
color: context.colorScheme.error,
|
color: context.colorScheme.error,
|
||||||
onClick: () {
|
onClick: () {
|
||||||
if (c.sourceKey.startsWith("Unknown")) {
|
_removeHistory(c as History);
|
||||||
HistoryManager().remove(
|
|
||||||
c.id,
|
|
||||||
ComicType(int.parse(c.sourceKey.split(':')[1])),
|
|
||||||
);
|
|
||||||
} else if (c.sourceKey == 'local') {
|
|
||||||
HistoryManager().remove(
|
|
||||||
c.id,
|
|
||||||
ComicType.local,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
HistoryManager().remove(
|
|
||||||
c.id,
|
|
||||||
ComicType(c.sourceKey.hashCode),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
Reference in New Issue
Block a user