mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Add select mode to gallery page
This commit is contained in:
@@ -12,11 +12,20 @@ import 'thumbnail_gridview.dart';
|
||||
|
||||
class GalleryInfo extends StatefulWidget {
|
||||
const GalleryInfo(this.gData,
|
||||
{super.key, this.files, this.refreshIndicatorKey, this.onRefresh});
|
||||
{super.key,
|
||||
this.files,
|
||||
this.refreshIndicatorKey,
|
||||
this.onRefresh,
|
||||
this.isSelectMode = false,
|
||||
this.onSelectChanged,
|
||||
this.selected});
|
||||
final GalleryData gData;
|
||||
final EhFiles? files;
|
||||
final GlobalKey<RefreshIndicatorState>? refreshIndicatorKey;
|
||||
final Future<void> Function()? onRefresh;
|
||||
final bool isSelectMode;
|
||||
final ValueChanged<bool>? onSelectChanged;
|
||||
final List<String>? selected;
|
||||
|
||||
@override
|
||||
State<GalleryInfo> createState() => _GalleryInfo();
|
||||
@@ -66,14 +75,29 @@ class _GalleryInfo extends State<GalleryInfo> with ThemeModeWidget {
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
icon: Icon(widget.isSelectMode ? Icons.close : Icons.arrow_back),
|
||||
onPressed: () {
|
||||
context.canPop() ? context.pop() : context.go("/");
|
||||
if (widget.isSelectMode) {
|
||||
if (widget.onSelectChanged != null) {
|
||||
widget.onSelectChanged!(false);
|
||||
}
|
||||
} else {
|
||||
context.canPop() ? context.pop() : context.go("/");
|
||||
}
|
||||
},
|
||||
),
|
||||
title: SelectableText(widget.gData.meta.preferredTitle,
|
||||
maxLines: 1, minLines: 1),
|
||||
actions: [
|
||||
widget.isSelectMode || widget.onSelectChanged == null
|
||||
? Container()
|
||||
: IconButton(
|
||||
onPressed: () {
|
||||
if (widget.onSelectChanged != null) {
|
||||
widget.onSelectChanged!(true);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.check_box)),
|
||||
buildThemeModeIcon(context),
|
||||
buildMoreVertSettingsButon(context),
|
||||
],
|
||||
@@ -113,7 +137,10 @@ class _GalleryInfo extends State<GalleryInfo> with ThemeModeWidget {
|
||||
SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: useMobile ? 2 : 5),
|
||||
files: widget.files,
|
||||
gid: widget.gData.meta.gid),
|
||||
gid: widget.gData.meta.gid,
|
||||
isSelectMode: widget.isSelectMode,
|
||||
selected: widget.selected,
|
||||
onSelectedChange: () => setState(() {})),
|
||||
],
|
||||
);
|
||||
if (widget.refreshIndicatorKey != null && widget.onRefresh != null) {
|
||||
|
||||
@@ -28,7 +28,10 @@ class Thumbnail extends StatefulWidget {
|
||||
this.gid,
|
||||
this.index,
|
||||
this.files,
|
||||
this.gdata})
|
||||
this.gdata,
|
||||
this.isSelectMode = false,
|
||||
this.isSelected = false,
|
||||
this.onSelectedChange})
|
||||
: _pMeta = pMeta,
|
||||
_max = max ?? 1200,
|
||||
_width = width,
|
||||
@@ -43,6 +46,9 @@ class Thumbnail extends StatefulWidget {
|
||||
final int? index;
|
||||
final EhFiles? files;
|
||||
final GalleryData? gdata;
|
||||
final bool isSelectMode;
|
||||
final bool isSelected;
|
||||
final ValueChanged<bool>? onSelectedChange;
|
||||
|
||||
int get height => _height != null
|
||||
? _height!
|
||||
@@ -246,7 +252,8 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
}
|
||||
}
|
||||
|
||||
bool get showNsfw => _showNsfw || (prefs.getBool("showNsfw") ?? false);
|
||||
bool get showNsfw =>
|
||||
widget.isSelectMode || _showNsfw || (prefs.getBool("showNsfw") ?? false);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -391,6 +398,7 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
},
|
||||
child: timg)
|
||||
: timg;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
return SizedBox(
|
||||
width: widget.width.toDouble(),
|
||||
height: widget.height.toDouble(),
|
||||
@@ -431,7 +439,21 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
width: widget.width.toDouble(),
|
||||
height: widget.height.toDouble(),
|
||||
child: img),
|
||||
moreVertMenu
|
||||
widget.isSelectMode ? Container() : moreVertMenu,
|
||||
Visibility(
|
||||
visible: widget.isSelectMode,
|
||||
child: const ModalBarrier()),
|
||||
widget.isSelectMode
|
||||
? Center(
|
||||
child: Checkbox(
|
||||
value: widget.isSelected,
|
||||
onChanged: (v) {
|
||||
if (widget.onSelectedChange != null &&
|
||||
v != null) {
|
||||
widget.onSelectedChange!(v);
|
||||
}
|
||||
}))
|
||||
: Container(),
|
||||
])
|
||||
: Center(
|
||||
child: Column(
|
||||
|
||||
@@ -6,11 +6,19 @@ import 'thumbnail.dart';
|
||||
|
||||
class ThumbnailGridView extends StatelessWidget {
|
||||
const ThumbnailGridView(this.gdata, this.gridDelegate,
|
||||
{super.key, this.files, this.gid});
|
||||
{super.key,
|
||||
this.files,
|
||||
this.gid,
|
||||
this.isSelectMode = false,
|
||||
this.selected,
|
||||
this.onSelectedChange});
|
||||
final GalleryData gdata;
|
||||
final int? gid;
|
||||
final EhFiles? files;
|
||||
final SliverGridDelegate gridDelegate;
|
||||
final bool isSelectMode;
|
||||
final List<String>? selected;
|
||||
final Function? onSelectedChange;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -27,13 +35,27 @@ class ThumbnailGridView extends StatelessWidget {
|
||||
final key = Key("thumbnail$gid-${page.index}-$fileId");
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
child: Thumbnail(page,
|
||||
key: key,
|
||||
fileId: fileId,
|
||||
gid: gid,
|
||||
index: page.index,
|
||||
files: files,
|
||||
gdata: gdata));
|
||||
child: Thumbnail(
|
||||
page,
|
||||
key: key,
|
||||
fileId: fileId,
|
||||
gid: gid,
|
||||
index: page.index,
|
||||
files: files,
|
||||
gdata: gdata,
|
||||
isSelectMode: isSelectMode,
|
||||
isSelected: selected?.contains(page.token) ?? false,
|
||||
onSelectedChange: (v) {
|
||||
if (v) {
|
||||
selected?.add(page.token);
|
||||
} else {
|
||||
selected?.remove(page.token);
|
||||
}
|
||||
if (onSelectedChange != null) {
|
||||
onSelectedChange!();
|
||||
}
|
||||
},
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user