nc-photos/app/lib/widget/dynamic_album_browser.dart

778 lines
21 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2021-07-06 15:03:29 +02:00
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/api/api_util.dart' as api_util;
2021-07-25 07:00:38 +02:00
import 'package:nc_photos/app_localizations.dart';
2021-09-04 14:35:04 +02:00
import 'package:nc_photos/debug_util.dart';
import 'package:nc_photos/di_container.dart';
2021-09-28 22:56:44 +02:00
import 'package:nc_photos/download_handler.dart';
import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/album/cover_provider.dart';
2021-07-05 09:54:01 +02:00
import 'package:nc_photos/entity/album/item.dart';
2021-06-27 17:35:40 +02:00
import 'package:nc_photos/entity/album/provider.dart';
2021-07-11 06:21:35 +02:00
import 'package:nc_photos/entity/album/sort_provider.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
2021-08-13 22:18:35 +02:00
import 'package:nc_photos/event/event.dart';
2021-06-30 07:11:02 +02:00
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/iterable_extension.dart';
import 'package:nc_photos/k.dart' as k;
2022-06-06 19:37:46 +02:00
import 'package:nc_photos/object_extension.dart';
2021-07-22 08:15:41 +02:00
import 'package:nc_photos/or_null.dart';
2021-10-04 15:53:03 +02:00
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/share_handler.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/theme.dart';
2021-09-29 13:00:00 +02:00
import 'package:nc_photos/use_case/preprocess_album.dart';
import 'package:nc_photos/use_case/remove.dart';
import 'package:nc_photos/use_case/update_album.dart';
import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
import 'package:nc_photos/widget/album_browser_mixin.dart';
2021-07-11 06:21:35 +02:00
import 'package:nc_photos/widget/fancy_option_picker.dart';
import 'package:nc_photos/widget/photo_list_item.dart';
2021-12-19 12:30:56 +01:00
import 'package:nc_photos/widget/photo_list_util.dart' as photo_list_util;
import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart';
import 'package:nc_photos/widget/viewer.dart';
class DynamicAlbumBrowserArguments {
DynamicAlbumBrowserArguments(this.account, this.album);
final Account account;
final Album album;
}
class DynamicAlbumBrowser extends StatefulWidget {
static const routeName = "/dynamic-album-browser";
static Route buildRoute(DynamicAlbumBrowserArguments args) =>
2021-07-23 22:05:57 +02:00
MaterialPageRoute(
builder: (context) => DynamicAlbumBrowser.fromArgs(args),
2021-07-23 22:05:57 +02:00
);
2021-09-15 08:58:06 +02:00
const DynamicAlbumBrowser({
2021-07-23 22:05:57 +02:00
Key? key,
required this.account,
required this.album,
}) : super(key: key);
DynamicAlbumBrowser.fromArgs(DynamicAlbumBrowserArguments args, {Key? key})
: this(
key: key,
account: args.account,
album: args.album,
);
@override
createState() => _DynamicAlbumBrowserState();
final Account account;
final Album album;
}
class _DynamicAlbumBrowserState extends State<DynamicAlbumBrowser>
with
SelectableItemStreamListMixin<DynamicAlbumBrowser>,
AlbumBrowserMixin<DynamicAlbumBrowser> {
_DynamicAlbumBrowserState() {
final c = KiwiContainer().resolve<DiContainer>();
assert(require(c));
assert(PreProcessAlbum.require(c));
_c = c;
}
static bool require(DiContainer c) => DiContainer.has(c, DiType.albumRepo);
@override
initState() {
super.initState();
_initAlbum();
2021-08-13 22:18:35 +02:00
_albumUpdatedListener =
AppEventListener<AlbumUpdatedEvent>(_onAlbumUpdatedEvent);
_albumUpdatedListener.begin();
}
@override
dispose() {
super.dispose();
_albumUpdatedListener.end();
}
@override
build(BuildContext context) {
return AppTheme(
child: Scaffold(
2021-07-02 13:55:52 +02:00
body: Builder(
builder: (context) {
if (isEditMode) {
return Form(
key: _editFormKey,
child: _buildContent(context),
);
} else {
return _buildContent(context);
}
},
),
),
);
}
2022-06-06 19:37:46 +02:00
@override
onItemTap(SelectableItem item, int index) {
item.as<_ListItem>()?.onTap?.call();
}
2021-09-15 08:58:06 +02:00
@override
@protected
2021-08-20 19:02:13 +02:00
get canEdit => _album?.albumFile?.isOwned(widget.account.username) == true;
2021-07-11 06:21:35 +02:00
@override
enterEditMode() {
super.enterEditMode();
2021-07-23 22:05:57 +02:00
_editAlbum = _album!.copyWith();
2021-07-11 06:21:35 +02:00
}
@override
2021-07-23 22:05:57 +02:00
validateEditMode() => _editFormKey.currentState?.validate() == true;
2021-07-02 13:55:52 +02:00
@override
doneEditMode() {
2021-07-11 06:21:35 +02:00
try {
// persist the changes
2021-07-23 22:05:57 +02:00
_editFormKey.currentState!.save();
final newAlbum = makeEdited(_editAlbum!);
if (newAlbum.copyWith(lastUpdated: OrNull(_album!.lastUpdated)) !=
2021-07-22 08:15:41 +02:00
_album) {
2021-07-11 06:21:35 +02:00
_log.info("[doneEditMode] Album modified: $newAlbum");
setState(() {
_album = newAlbum;
});
UpdateAlbum(_c.albumRepo)(
2021-09-25 09:32:15 +02:00
widget.account,
newAlbum,
).catchError((e, stackTrace) {
_log.shout("[doneEditMode] Failed while UpdateAlbum", e, stackTrace);
2021-07-11 06:21:35 +02:00
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
2021-07-11 06:21:35 +02:00
duration: k.snackBarDurationNormal,
));
});
} else {
_log.fine("[doneEditMode] Album not modified");
}
} finally {
setState(() {
2021-07-11 06:21:35 +02:00
// reset edits
_editAlbum = null;
// update the list to show the real album
_transformItems(_sortedItems);
});
2021-07-02 13:55:52 +02:00
}
}
Future<void> _initAlbum() async {
2021-06-27 17:35:40 +02:00
assert(widget.album.provider is AlbumDynamicProvider);
final List<AlbumItem> items;
final Album album;
try {
items = await PreProcessAlbum(_c)(widget.account, widget.album);
album = await _updateAlbumPostPopulate(widget.album, items);
} catch (e, stackTrace) {
_log.severe("[_initAlbum] Failed while PreProcessAlbum", e, stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
return;
}
if (mounted) {
setState(() {
_album = album;
_transformItems(items);
initCover(widget.account, widget.album);
});
2021-06-27 17:35:40 +02:00
}
}
Widget _buildContent(BuildContext context) {
if (_album == null) {
return CustomScrollView(
slivers: [
buildNormalAppBar(context, widget.account, widget.album),
const SliverToBoxAdapter(
2021-09-15 08:58:06 +02:00
child: LinearProgressIndicator(),
),
],
);
}
return buildItemStreamListOuter(
context,
child: Theme(
data: Theme.of(context).copyWith(
colorScheme: Theme.of(context).colorScheme.copyWith(
secondary: AppTheme.getOverscrollIndicatorColor(context),
),
),
child: CustomScrollView(
slivers: [
_buildAppBar(context),
2021-10-04 21:29:01 +02:00
SliverIgnorePointer(
ignoring: isEditMode,
sliver: SliverOpacity(
opacity: isEditMode ? .25 : 1,
sliver: buildItemStreamList(
maxCrossAxisExtent: thumbSize.toDouble(),
2021-07-02 13:55:52 +02:00
),
),
),
],
),
),
);
}
2021-07-02 13:55:52 +02:00
Widget _buildAppBar(BuildContext context) {
if (isEditMode) {
return _buildEditAppBar(context);
} else if (isSelectionMode) {
return _buildSelectionAppBar(context);
} else {
return _buildNormalAppBar(context);
}
}
2021-06-30 07:11:02 +02:00
Widget _buildNormalAppBar(BuildContext context) {
2021-09-29 16:34:56 +02:00
final menuItems = <PopupMenuEntry<int>>[
PopupMenuItem(
value: _menuValueDownload,
child: Text(L10n.global().downloadTooltip),
),
];
if (canEdit) {
menuItems.add(PopupMenuItem(
value: _menuValueConvertBasic,
2022-01-27 22:03:15 +01:00
child: Text(L10n.global().convertAlbumTooltip),
2021-09-29 16:34:56 +02:00
));
}
2021-06-30 07:11:02 +02:00
return buildNormalAppBar(
context,
widget.account,
2021-07-23 22:05:57 +02:00
_album!,
2021-09-29 16:34:56 +02:00
menuItemBuilder: (_) => menuItems,
2021-07-02 13:55:52 +02:00
onSelectedMenuItem: (option) {
switch (option) {
case _menuValueConvertBasic:
2021-09-29 16:55:49 +02:00
_onConvertBasicPressed(context);
2021-07-02 13:55:52 +02:00
break;
2021-09-29 16:34:56 +02:00
case _menuValueDownload:
_onDownloadPressed();
break;
2021-07-02 13:55:52 +02:00
default:
_log.shout("[_buildNormalAppBar] Unknown value: $option");
break;
}
},
2021-06-30 07:11:02 +02:00
);
}
Widget _buildSelectionAppBar(BuildContext context) {
return buildSelectionAppBar(context, [
2021-10-09 10:42:18 +02:00
IconButton(
icon: const Icon(Icons.share),
tooltip: L10n.global().shareTooltip,
onPressed: () {
_onSelectionSharePressed(context);
},
),
2021-09-28 22:56:44 +02:00
PopupMenuButton<_SelectionMenuOption>(
2021-06-30 07:11:02 +02:00
tooltip: MaterialLocalizations.of(context).moreButtonTooltip,
itemBuilder: (context) => [
2021-09-28 22:56:44 +02:00
PopupMenuItem(
value: _SelectionMenuOption.download,
child: Text(L10n.global().downloadTooltip),
),
2021-06-30 07:11:02 +02:00
PopupMenuItem(
2021-09-28 22:22:08 +02:00
value: _SelectionMenuOption.delete,
child: Text(L10n.global().deleteTooltip),
2021-06-30 07:11:02 +02:00
),
],
2021-09-28 22:56:44 +02:00
onSelected: (option) => _onSelectionMenuSelected(context, option),
2021-06-30 07:11:02 +02:00
),
]);
}
2021-07-02 13:55:52 +02:00
Widget _buildEditAppBar(BuildContext context) {
2021-07-11 06:21:35 +02:00
return buildEditAppBar(context, widget.account, widget.album, actions: [
IconButton(
2021-09-15 08:58:06 +02:00
icon: const Icon(Icons.sort_by_alpha),
tooltip: L10n.global().sortTooltip,
2021-09-29 16:55:49 +02:00
onPressed: _onEditSortPressed,
2021-07-11 06:21:35 +02:00
),
]);
2021-07-02 13:55:52 +02:00
}
void _onItemTap(int index) {
2021-07-11 06:21:35 +02:00
// convert item index to file index
var fileIndex = index;
for (int i = 0; i < index; ++i) {
if (_sortedItems[i] is! AlbumFileItem ||
!file_util
.isSupportedFormat((_sortedItems[i] as AlbumFileItem).file)) {
--fileIndex;
}
}
Navigator.pushNamed(context, Viewer.routeName,
2021-08-13 22:18:35 +02:00
arguments: ViewerArguments(widget.account, _backingFiles, fileIndex,
album: widget.album));
}
2021-09-29 16:55:49 +02:00
Future<void> _onConvertBasicPressed(BuildContext context) async {
2021-09-25 08:02:52 +02:00
final result = await showDialog<bool>(
2021-06-30 07:11:02 +02:00
context: context,
builder: (context) => AlertDialog(
2022-01-27 22:03:15 +01:00
title: Text(L10n.global().convertAlbumTooltip),
content: Text(L10n.global().convertAlbumConfirmationDialogContent),
2021-06-30 07:11:02 +02:00
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: Text(MaterialLocalizations.of(context).okButtonLabel),
),
],
),
2021-09-25 08:02:52 +02:00
);
if (result != true) {
return;
}
_log.info(
2021-09-29 16:55:49 +02:00
"[_onConvertBasicPressed] Converting album '${_album!.name}' to static");
2021-09-25 08:02:52 +02:00
try {
await UpdateAlbum(_c.albumRepo)(
2021-09-25 08:02:52 +02:00
widget.account,
_album!.copyWith(
provider: AlbumStaticProvider(
latestItemTime: _album!.provider.latestItemTime,
2021-09-25 08:02:52 +02:00
items: _sortedItems,
),
coverProvider: AlbumAutoCoverProvider(),
));
SnackBarManager().showSnackBar(SnackBar(
2022-01-27 22:03:15 +01:00
content: Text(L10n.global().convertAlbumSuccessNotification),
2021-09-25 08:02:52 +02:00
duration: k.snackBarDurationNormal,
));
if (mounted) {
Navigator.of(context).pop();
2021-06-30 07:11:02 +02:00
}
2021-09-25 08:02:52 +02:00
} catch (e, stackTrace) {
_log.shout(
2021-09-29 16:55:49 +02:00
"[_onConvertBasicPressed] Failed while converting to basic album",
2021-09-25 08:02:52 +02:00
e,
stackTrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
}
2021-06-30 07:11:02 +02:00
}
2021-09-29 16:34:56 +02:00
void _onDownloadPressed() {
DownloadHandler().downloadFiles(
widget.account,
_sortedItems.whereType<AlbumFileItem>().map((e) => e.file).toList(),
parentDir: _album!.name,
);
}
2021-09-28 22:56:44 +02:00
void _onSelectionMenuSelected(
BuildContext context, _SelectionMenuOption option) {
switch (option) {
case _SelectionMenuOption.delete:
2021-09-29 16:55:49 +02:00
_onSelectionDeletePressed();
2021-09-28 22:56:44 +02:00
break;
case _SelectionMenuOption.download:
_onSelectionDownloadPressed();
break;
default:
_log.shout("[_onSelectionMenuSelected] Unknown option: $option");
break;
}
}
2021-09-29 16:55:49 +02:00
void _onSelectionSharePressed(BuildContext context) {
final selected = selectedListItems
.whereType<_FileListItem>()
.map((e) => e.file)
.toList();
2021-10-08 20:39:53 +02:00
ShareHandler(
context: context,
clearSelection: () {
setState(() {
clearSelectedItems();
});
},
).shareFiles(widget.account, selected);
2021-09-29 16:55:49 +02:00
}
void _onSelectionDeletePressed() async {
SnackBarManager().showSnackBar(
SnackBar(
content: Text(L10n.global()
.deleteSelectedProcessingNotification(selectedListItems.length)),
duration: k.snackBarDurationShort,
),
canBeReplaced: true,
);
2021-07-11 06:21:35 +02:00
final selected = selectedListItems.whereType<_FileListItem>().toList();
setState(() {
clearSelectedItems();
});
2021-07-11 06:21:35 +02:00
final successes = <_FileListItem>[];
await Remove(KiwiContainer().resolve<DiContainer>())(
widget.account,
selected.map((e) => e.file).toList(),
onRemoveFileFailed: (file, e, stackTrace) {
_log.shout(
"[_onSelectionDeletePressed] Failed while removing file: ${logFilename(file.path)}",
e,
stackTrace);
successes.removeWhere((item) => item.file.compareServerIdentity(file));
},
);
if (successes.length == selected.length) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(L10n.global().deleteSelectedSuccessNotification),
duration: k.snackBarDurationNormal,
));
} else {
SnackBarManager().showSnackBar(SnackBar(
content: Text(L10n.global().deleteSelectedFailureNotification(
selected.length - successes.length)),
duration: k.snackBarDurationNormal,
));
}
if (successes.isNotEmpty) {
2021-07-11 06:21:35 +02:00
final indexes = successes.map((e) => e.index).sorted();
setState(() {
2021-07-11 06:21:35 +02:00
for (final i in indexes.reversed) {
_sortedItems.removeAt(i);
}
_onSortedItemsUpdated();
});
}
}
2021-09-28 22:56:44 +02:00
void _onSelectionDownloadPressed() {
final selected = selectedListItems
.whereType<_FileListItem>()
.map((e) => e.file)
.toList();
DownloadHandler().downloadFiles(widget.account, selected);
setState(() {
clearSelectedItems();
});
}
2021-09-29 16:55:49 +02:00
void _onEditSortPressed() {
2021-07-23 22:05:57 +02:00
final sortProvider = _editAlbum!.sortProvider;
2021-07-11 06:21:35 +02:00
showDialog(
context: context,
builder: (context) => FancyOptionPicker(
title: L10n.global().sortOptionDialogTitle,
2021-07-11 06:21:35 +02:00
items: [
FancyOptionPickerItem(
2021-09-08 17:39:16 +02:00
label: L10n.global().sortOptionTimeDescendingLabel,
2021-07-11 06:21:35 +02:00
isSelected: sortProvider is AlbumTimeSortProvider &&
2021-09-08 17:39:16 +02:00
!sortProvider.isAscending,
2021-07-11 06:21:35 +02:00
onSelect: () {
2021-09-29 16:55:49 +02:00
_onEditSortNewestPressed();
2021-07-11 06:21:35 +02:00
Navigator.of(context).pop();
},
),
FancyOptionPickerItem(
2021-09-08 17:39:16 +02:00
label: L10n.global().sortOptionTimeAscendingLabel,
2021-07-11 06:21:35 +02:00
isSelected: sortProvider is AlbumTimeSortProvider &&
2021-09-08 17:39:16 +02:00
sortProvider.isAscending,
2021-07-11 06:21:35 +02:00
onSelect: () {
2021-09-29 16:55:49 +02:00
_onEditSortOldestPressed();
2021-07-11 06:21:35 +02:00
Navigator.of(context).pop();
},
),
2022-05-26 06:00:55 +02:00
FancyOptionPickerItem(
label: L10n.global().sortOptionFilenameAscendingLabel,
isSelected: sortProvider is AlbumFilenameSortProvider &&
sortProvider.isAscending,
onSelect: () {
_onEditSortFilenamePressed();
Navigator.of(context).pop();
},
),
FancyOptionPickerItem(
label: L10n.global().sortOptionFilenameDescendingLabel,
isSelected: sortProvider is AlbumFilenameSortProvider &&
!sortProvider.isAscending,
onSelect: () {
_onEditSortFilenameDescendingPressed();
Navigator.of(context).pop();
},
),
2021-07-11 06:21:35 +02:00
],
),
);
}
2021-09-29 16:55:49 +02:00
void _onEditSortOldestPressed() {
2021-07-23 22:05:57 +02:00
_editAlbum = _editAlbum!.copyWith(
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumTimeSortProvider(isAscending: true),
2021-07-11 06:21:35 +02:00
);
setState(() {
_transformItems(_sortedItems);
});
}
2021-09-29 16:55:49 +02:00
void _onEditSortNewestPressed() {
2021-07-23 22:05:57 +02:00
_editAlbum = _editAlbum!.copyWith(
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumTimeSortProvider(isAscending: false),
2021-07-11 06:21:35 +02:00
);
setState(() {
_transformItems(_sortedItems);
});
}
2022-05-26 06:00:55 +02:00
void _onEditSortFilenamePressed() {
_editAlbum = _editAlbum!.copyWith(
sortProvider: const AlbumFilenameSortProvider(isAscending: true),
);
setState(() {
_transformItems(_sortedItems);
});
}
void _onEditSortFilenameDescendingPressed() {
_editAlbum = _editAlbum!.copyWith(
sortProvider: const AlbumFilenameSortProvider(isAscending: false),
);
setState(() {
_transformItems(_sortedItems);
});
}
Future<void> _onAlbumUpdatedEvent(AlbumUpdatedEvent ev) async {
2021-08-13 22:18:35 +02:00
if (ev.album.albumFile!.path == _album?.albumFile?.path) {
final album = await _updateAlbumPostPopulate(ev.album, _sortedItems);
2021-08-13 22:18:35 +02:00
setState(() {
_album = album;
initCover(widget.account, album);
2021-08-13 22:18:35 +02:00
});
}
}
void _transformItems(List<AlbumItem> items) {
2021-10-04 15:53:16 +02:00
_sortedItems = (_editAlbum ?? _album)!.sortProvider.sort(items);
2021-07-11 06:21:35 +02:00
_onSortedItemsUpdated();
}
void _onSortedItemsUpdated() {
_backingFiles = _sortedItems
.whereType<AlbumFileItem>()
.map((e) => e.file)
.where((element) => file_util.isSupportedFormat(element))
2021-07-11 06:21:35 +02:00
.toList();
2021-12-19 12:30:56 +01:00
final dateHelper = photo_list_util.DateGroupHelper(
2021-10-04 15:53:03 +02:00
isMonthOnly: false,
);
itemStreamListItems = () sync* {
2021-07-11 06:21:35 +02:00
for (int i = 0; i < _sortedItems.length; ++i) {
final item = _sortedItems[i];
if (item is AlbumFileItem) {
final previewUrl = api_util.getFilePreviewUrl(
widget.account,
item.file,
2021-09-16 12:25:08 +02:00
width: k.photoThumbSize,
height: k.photoThumbSize,
);
2021-10-04 15:53:03 +02:00
if ((_editAlbum ?? _album)?.sortProvider is AlbumTimeSortProvider &&
2021-10-27 22:40:54 +02:00
Pref().isAlbumBrowserShowDateOr()) {
2021-10-04 15:53:03 +02:00
final date = dateHelper.onFile(item.file);
if (date != null) {
yield _DateListItem(date: date);
}
}
2021-07-11 06:21:35 +02:00
if (file_util.isSupportedImageFormat(item.file)) {
yield _ImageListItem(
index: i,
file: item.file,
account: widget.account,
previewUrl: previewUrl,
onTap: () => _onItemTap(i),
);
} else if (file_util.isSupportedVideoFormat(item.file)) {
yield _VideoListItem(
index: i,
file: item.file,
account: widget.account,
previewUrl: previewUrl,
onTap: () => _onItemTap(i),
);
}
}
}
2021-07-07 20:51:34 +02:00
}()
.toList();
}
Future<Album> _updateAlbumPostPopulate(
Album album, List<AlbumItem> items) async {
return await UpdateAlbumWithActualItems(_c.albumRepo)(
widget.account, album, items);
}
late final DiContainer _c;
2021-07-23 22:05:57 +02:00
Album? _album;
2021-07-11 06:21:35 +02:00
var _sortedItems = <AlbumItem>[];
var _backingFiles = <File>[];
2021-07-02 13:55:52 +02:00
final _editFormKey = GlobalKey<FormState>();
2021-07-23 22:05:57 +02:00
Album? _editAlbum;
2021-07-02 13:55:52 +02:00
2021-08-13 22:18:35 +02:00
late AppEventListener<AlbumUpdatedEvent> _albumUpdatedListener;
static final _log =
Logger("widget.dynamic_album_browser._DynamicAlbumBrowserState");
2021-07-02 13:55:52 +02:00
static const _menuValueConvertBasic = 0;
2021-09-29 16:34:56 +02:00
static const _menuValueDownload = 1;
}
2021-09-28 22:22:08 +02:00
enum _SelectionMenuOption {
delete,
2021-09-28 22:56:44 +02:00
download,
2021-09-28 22:22:08 +02:00
}
2021-07-06 15:03:29 +02:00
abstract class _ListItem implements SelectableItem {
2021-10-04 15:53:03 +02:00
const _ListItem({
2021-07-23 22:05:57 +02:00
required this.index,
2022-06-06 19:37:46 +02:00
this.onTap,
});
2021-07-06 15:03:29 +02:00
@override
2022-06-06 19:37:46 +02:00
get isTappable => onTap != null;
2021-07-06 15:03:29 +02:00
@override
get isSelectable => true;
@override
get staggeredTile => const StaggeredTile.count(1, 1);
2021-07-11 06:21:35 +02:00
@override
toString() {
return "$runtimeType {"
"index: $index, "
"}";
}
final int index;
2022-06-06 19:37:46 +02:00
final VoidCallback? onTap;
2021-07-06 15:03:29 +02:00
}
abstract class _FileListItem extends _ListItem {
_FileListItem({
2021-07-23 22:05:57 +02:00
required int index,
required this.file,
VoidCallback? onTap,
}) : super(
2021-07-11 06:21:35 +02:00
index: index,
onTap: onTap,
);
final File file;
}
class _ImageListItem extends _FileListItem {
_ImageListItem({
2021-07-23 22:05:57 +02:00
required int index,
required File file,
required this.account,
required this.previewUrl,
VoidCallback? onTap,
}) : super(
2021-07-11 06:21:35 +02:00
index: index,
file: file,
onTap: onTap,
);
@override
buildWidget(BuildContext context) {
return PhotoListImage(
account: account,
previewUrl: previewUrl,
isGif: file.contentType == "image/gif",
);
}
final Account account;
final String previewUrl;
}
class _VideoListItem extends _FileListItem {
_VideoListItem({
2021-07-23 22:05:57 +02:00
required int index,
required File file,
required this.account,
required this.previewUrl,
VoidCallback? onTap,
}) : super(
2021-07-11 06:21:35 +02:00
index: index,
file: file,
onTap: onTap,
);
@override
buildWidget(BuildContext context) {
return PhotoListVideo(
account: account,
previewUrl: previewUrl,
);
}
final Account account;
final String previewUrl;
}
2021-10-04 15:53:03 +02:00
class _DateListItem extends _ListItem {
const _DateListItem({
required this.date,
}) : super(index: -1);
@override
get isSelectable => false;
@override
get staggeredTile => const StaggeredTile.extent(99, 32);
@override
buildWidget(BuildContext context) {
return PhotoListDate(
date: date,
);
}
final DateTime date;
}