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

683 lines
20 KiB
Dart
Raw Normal View History

2022-04-09 12:45:17 +02:00
import 'dart:ui';
2021-04-10 06:28:12 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
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';
2021-07-25 07:00:38 +02:00
import 'package:nc_photos/app_localizations.dart';
2021-04-10 06:28:12 +02:00
import 'package:nc_photos/bloc/list_album.dart';
import 'package:nc_photos/di_container.dart';
2021-04-10 06:28:12 +02:00
import 'package:nc_photos/entity/album.dart';
2021-06-24 18:26:56 +02:00
import 'package:nc_photos/entity/album/provider.dart';
2021-12-10 19:44:56 +01:00
import 'package:nc_photos/entity/album_util.dart' as album_util;
2021-04-10 06:28:12 +02:00
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/event/event.dart';
2021-04-10 06:28:12 +02:00
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
2022-06-06 19:37:46 +02:00
import 'package:nc_photos/object_extension.dart';
2022-05-12 15:27:53 +02:00
import 'package:nc_photos/platform/features.dart' as features;
2021-08-20 19:02:13 +02:00
import 'package:nc_photos/pref.dart';
2021-04-10 06:28:12 +02:00
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/theme.dart';
2021-10-25 13:20:56 +02:00
import 'package:nc_photos/use_case/remove_album.dart';
import 'package:nc_photos/use_case/unimport_shared_album.dart';
2021-08-20 08:06:37 +02:00
import 'package:nc_photos/widget/album_browser_util.dart' as album_browser_util;
2021-07-01 13:32:22 +02:00
import 'package:nc_photos/widget/album_importer.dart';
2021-07-13 21:29:52 +02:00
import 'package:nc_photos/widget/album_search_delegate.dart';
2021-07-31 19:02:41 +02:00
import 'package:nc_photos/widget/archive_browser.dart';
2021-07-13 21:29:52 +02:00
import 'package:nc_photos/widget/builder/album_grid_item_builder.dart';
import 'package:nc_photos/widget/dynamic_album_browser.dart';
2022-05-06 11:16:56 +02:00
import 'package:nc_photos/widget/enhanced_photo_browser.dart';
2021-09-08 18:23:42 +02:00
import 'package:nc_photos/widget/fancy_option_picker.dart';
2022-01-25 11:08:13 +01:00
import 'package:nc_photos/widget/favorite_browser.dart';
2021-04-10 06:28:12 +02:00
import 'package:nc_photos/widget/home_app_bar.dart';
import 'package:nc_photos/widget/new_album_dialog.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart';
import 'package:nc_photos/widget/people_browser.dart';
2021-08-22 22:03:13 +02:00
import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart';
2021-07-25 16:27:19 +02:00
import 'package:nc_photos/widget/selection_app_bar.dart';
2021-10-06 22:32:36 +02:00
import 'package:nc_photos/widget/sharing_browser.dart';
2021-08-01 22:46:16 +02:00
import 'package:nc_photos/widget/trashbin_browser.dart';
2021-04-10 06:28:12 +02:00
class HomeAlbums extends StatefulWidget {
2021-09-15 08:58:06 +02:00
const HomeAlbums({
2021-07-23 22:05:57 +02:00
Key? key,
required this.account,
2021-04-10 06:28:12 +02:00
}) : super(key: key);
@override
createState() => _HomeAlbumsState();
final Account account;
}
class _HomeAlbumsState extends State<HomeAlbums>
2021-08-22 22:03:13 +02:00
with
SelectableItemStreamListMixin,
RouteAware,
PageVisibilityMixin<HomeAlbums> {
2021-04-10 06:28:12 +02:00
@override
initState() {
super.initState();
_initBloc();
_accountPrefUpdatedEventListener.begin();
}
@override
dispose() {
_accountPrefUpdatedEventListener.end();
super.dispose();
2021-04-10 06:28:12 +02:00
}
@override
build(BuildContext context) {
return BlocListener<ListAlbumBloc, ListAlbumBlocState>(
bloc: _bloc,
listener: (context, state) => _onStateChange(context, state),
child: BlocBuilder<ListAlbumBloc, ListAlbumBlocState>(
bloc: _bloc,
builder: (context, state) => _buildContent(context, state),
),
);
}
2022-06-06 19:37:46 +02:00
@override
onItemTap(SelectableItem item, int index) {
item.as<_ListItem>()?.onTap?.call();
}
2021-04-10 06:28:12 +02:00
void _initBloc() {
if (_bloc.state is ListAlbumBlocInit) {
_log.info("[_initBloc] Initialize bloc");
_reqQuery();
} else {
// process the current state
2021-07-23 22:05:57 +02:00
WidgetsBinding.instance!.addPostFrameCallback((_) {
2021-07-03 13:32:23 +02:00
setState(() {
_onStateChange(context, _bloc.state);
});
});
2021-04-10 06:28:12 +02:00
}
}
Widget _buildContent(BuildContext context, ListAlbumBlocState state) {
return Stack(
children: [
2021-08-22 22:03:13 +02:00
buildItemStreamListOuter(
context,
child: Theme(
data: Theme.of(context).copyWith(
colorScheme: Theme.of(context).colorScheme.copyWith(
secondary: AppTheme.getOverscrollIndicatorColor(context),
),
2021-08-22 22:03:13 +02:00
),
2021-11-18 14:09:36 +01:00
child: RefreshIndicator(
backgroundColor: Colors.grey[100],
onRefresh: () async {
_onRefreshPressed();
await _waitRefresh();
},
child: CustomScrollView(
slivers: [
_buildAppBar(context),
SliverPadding(
2022-05-16 19:57:31 +02:00
padding: const EdgeInsets.symmetric(horizontal: 8),
2021-11-18 14:09:36 +01:00
sliver: buildItemStreamList(
maxCrossAxisExtent: 256,
2022-05-16 19:57:31 +02:00
mainAxisSpacing: 6,
2021-11-18 14:09:36 +01:00
),
2021-08-22 22:03:13 +02:00
),
2022-04-09 12:45:17 +02:00
SliverToBoxAdapter(
child: SizedBox(
height: _calcBottomAppBarExtent(context),
),
),
2021-11-18 14:09:36 +01:00
],
),
2021-08-22 22:03:13 +02:00
),
2021-04-10 06:28:12 +02:00
),
),
2022-04-09 12:45:17 +02:00
Align(
alignment: Alignment.bottomCenter,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (state is ListAlbumBlocLoading)
const LinearProgressIndicator(),
SizedBox(
width: double.infinity,
height: _calcBottomAppBarExtent(context),
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 4, sigmaY: 4),
child: const ColoredBox(
color: Colors.transparent,
),
),
),
),
],
2021-04-10 06:28:12 +02:00
),
2022-04-09 12:45:17 +02:00
),
2021-04-10 06:28:12 +02:00
],
);
}
Widget _buildAppBar(BuildContext context) {
2021-08-22 22:03:13 +02:00
if (isSelectionMode) {
2021-04-10 06:28:12 +02:00
return _buildSelectionAppBar(context);
} else {
return _buildNormalAppBar(context);
}
}
Widget _buildSelectionAppBar(BuildContext conetxt) {
2021-07-25 16:27:19 +02:00
return SelectionAppBar(
2021-08-22 22:03:13 +02:00
count: selectedListItems.length,
2021-07-25 16:27:19 +02:00
onClosePressed: () {
setState(() {
2021-08-22 22:03:13 +02:00
clearSelectedItems();
2021-07-25 16:27:19 +02:00
});
},
actions: [
IconButton(
icon: const Icon(Icons.delete),
tooltip: L10n.global().deleteTooltip,
2021-04-10 06:28:12 +02:00
onPressed: () {
2021-09-29 16:55:49 +02:00
_onSelectionDeletePressed();
2021-04-10 06:28:12 +02:00
},
),
2021-07-25 16:27:19 +02:00
],
2021-04-10 06:28:12 +02:00
);
}
Widget _buildNormalAppBar(BuildContext context) {
return HomeSliverAppBar(
account: widget.account,
2021-07-16 09:55:04 +02:00
actions: [
IconButton(
onPressed: () => _onSearchPressed(context),
icon: const Icon(Icons.search),
tooltip: L10n.global().searchTooltip,
2021-07-16 09:55:04 +02:00
),
],
2021-07-01 13:32:22 +02:00
menuActions: [
2021-09-08 18:23:42 +02:00
PopupMenuItem(
value: _menuValueSort,
child: Text(L10n.global().sortTooltip),
),
2021-07-01 13:32:22 +02:00
PopupMenuItem(
value: _menuValueImport,
child: Text(L10n.global().importFoldersTooltip),
2021-07-01 13:32:22 +02:00
),
],
onSelectedMenuActions: (option) {
switch (option) {
2021-09-08 18:23:42 +02:00
case _menuValueSort:
_onSortPressed(context);
break;
2021-07-01 13:32:22 +02:00
case _menuValueImport:
2021-09-29 16:55:49 +02:00
_onImportPressed(context);
2021-07-01 13:32:22 +02:00
break;
}
},
2021-04-10 06:28:12 +02:00
);
}
2022-01-25 11:08:13 +01:00
SelectableItem _buildFavoriteItem(BuildContext context) {
return _ButtonListItem(
icon: Icons.star_border,
label: L10n.global().collectionFavoritesLabel,
onTap: () {
if (!isSelectionMode) {
Navigator.of(context).pushNamed(FavoriteBrowser.routeName,
arguments: FavoriteBrowserArguments(widget.account));
}
},
);
}
SelectableItem _buildPersonItem(BuildContext context) {
return _ButtonListItem(
icon: Icons.person_outlined,
label: L10n.global().collectionPeopleLabel,
onTap: () {
if (!isSelectionMode) {
Navigator.of(context).pushNamed(PeopleBrowser.routeName,
arguments: PeopleBrowserArguments(widget.account));
}
},
);
}
2021-08-22 22:03:13 +02:00
SelectableItem _buildArchiveItem(BuildContext context) {
return _ButtonListItem(
icon: Icons.archive_outlined,
label: L10n.global().albumArchiveLabel,
2021-08-22 22:03:13 +02:00
onTap: () {
if (!isSelectionMode) {
Navigator.of(context).pushNamed(ArchiveBrowser.routeName,
arguments: ArchiveBrowserArguments(widget.account));
}
},
2021-05-28 21:44:09 +02:00
);
}
2021-08-22 22:03:13 +02:00
SelectableItem _buildTrashbinItem(BuildContext context) {
return _ButtonListItem(
icon: Icons.delete_outlined,
label: L10n.global().albumTrashLabel,
2021-08-22 22:03:13 +02:00
onTap: () {
if (!isSelectionMode) {
Navigator.of(context).pushNamed(TrashbinBrowser.routeName,
arguments: TrashbinBrowserArguments(widget.account));
}
},
2021-08-01 22:46:16 +02:00
);
}
2021-10-06 22:32:36 +02:00
SelectableItem _buildSharingItem(BuildContext context) {
return _ButtonListItem(
icon: Icons.share_outlined,
label: L10n.global().collectionSharingLabel,
isShowIndicator: AccountPref.of(widget.account).hasNewSharedAlbumOr(),
2021-10-06 22:32:36 +02:00
onTap: () {
if (!isSelectionMode) {
Navigator.of(context).pushNamed(SharingBrowser.routeName,
arguments: SharingBrowserArguments(widget.account));
}
},
);
}
2022-05-06 11:16:56 +02:00
SelectableItem _buildEnhancedPhotosItem(BuildContext context) {
return _ButtonListItem(
icon: Icons.auto_fix_high_outlined,
label: L10n.global().collectionEnhancedPhotosLabel,
onTap: () {
if (!isSelectionMode) {
Navigator.of(context).pushNamed(EnhancedPhotoBrowser.routeName,
arguments: const EnhancedPhotoBrowserArguments(null));
}
},
);
}
2021-08-22 22:03:13 +02:00
SelectableItem _buildNewAlbumItem(BuildContext context) {
return _ButtonListItem(
icon: Icons.add,
2022-01-27 22:03:15 +01:00
label: L10n.global().createCollectionTooltip,
2021-08-22 22:03:13 +02:00
onTap: () {
if (!isSelectionMode) {
_onNewAlbumItemTap(context);
}
},
2021-04-10 06:28:12 +02:00
);
}
void _onStateChange(BuildContext context, ListAlbumBlocState state) {
if (state is ListAlbumBlocInit) {
2021-08-22 22:03:13 +02:00
itemStreamListItems = [];
2021-04-10 06:28:12 +02:00
} else if (state is ListAlbumBlocSuccess || state is ListAlbumBlocLoading) {
2021-08-13 12:38:46 +02:00
_transformItems(state.items);
2021-04-10 06:28:12 +02:00
} else if (state is ListAlbumBlocFailure) {
2021-08-13 12:38:46 +02:00
_transformItems(state.items);
if (isPageVisible()) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.exception)),
duration: k.snackBarDurationNormal,
));
}
2021-04-10 06:28:12 +02:00
} else if (state is ListAlbumBlocInconsistent) {
_reqQuery();
}
}
2021-12-10 19:44:56 +01:00
Future<void> _onNewAlbumItemTap(BuildContext context) async {
try {
final album = await showDialog<Album>(
context: context,
builder: (_) => NewAlbumDialog(
account: widget.account,
),
);
if (album == null) {
2021-06-29 11:44:35 +02:00
return;
}
if (album.provider is AlbumDynamicProvider) {
// open the album automatically to refresh its content, otherwise it'll
// be empty
Navigator.of(context).pushNamed(DynamicAlbumBrowser.routeName,
arguments: DynamicAlbumBrowserArguments(widget.account, album));
2021-06-29 11:44:35 +02:00
}
2021-12-10 19:44:56 +01:00
} catch (e, stacktrace) {
_log.shout("[_onNewAlbumItemTap] Failed", e, stacktrace);
2021-04-10 06:28:12 +02:00
SnackBarManager().showSnackBar(SnackBar(
content: Text(L10n.global().createAlbumFailureNotification),
2021-04-10 06:28:12 +02:00
duration: k.snackBarDurationNormal,
));
2021-12-10 19:44:56 +01:00
}
2021-04-10 06:28:12 +02:00
}
2021-11-18 14:09:36 +01:00
void _onRefreshPressed() {
_reqQuery();
}
2021-09-29 16:55:49 +02:00
void _onSearchPressed(BuildContext context) {
showSearch(
context: context,
delegate: AlbumSearchDelegate(context, widget.account),
).then((value) {
if (value is Album) {
_openAlbum(context, value);
}
});
}
2021-09-08 18:23:42 +02:00
void _onSortPressed(BuildContext context) {
showDialog(
context: context,
builder: (context) => FancyOptionPicker(
title: L10n.global().sortOptionDialogTitle,
items: [
FancyOptionPickerItem(
label: L10n.global().sortOptionTimeDescendingLabel,
2021-12-10 19:44:56 +01:00
isSelected:
_getSortFromPref() == album_util.AlbumSort.dateDescending,
2021-09-08 18:23:42 +02:00
onSelect: () {
2021-12-10 19:44:56 +01:00
_onSortSelected(album_util.AlbumSort.dateDescending);
2021-09-08 18:23:42 +02:00
Navigator.of(context).pop();
},
),
FancyOptionPickerItem(
label: L10n.global().sortOptionTimeAscendingLabel,
2021-12-10 19:44:56 +01:00
isSelected:
_getSortFromPref() == album_util.AlbumSort.dateAscending,
2021-09-08 18:23:42 +02:00
onSelect: () {
2021-12-10 19:44:56 +01:00
_onSortSelected(album_util.AlbumSort.dateAscending);
2021-09-08 18:23:42 +02:00
Navigator.of(context).pop();
},
),
FancyOptionPickerItem(
label: L10n.global().sortOptionAlbumNameLabel,
2021-12-10 19:44:56 +01:00
isSelected:
_getSortFromPref() == album_util.AlbumSort.nameAscending,
2021-09-08 18:23:42 +02:00
onSelect: () {
2021-12-10 19:44:56 +01:00
_onSortSelected(album_util.AlbumSort.nameAscending);
2021-09-08 18:23:42 +02:00
Navigator.of(context).pop();
},
),
FancyOptionPickerItem(
label: L10n.global().sortOptionAlbumNameDescendingLabel,
2021-12-10 19:44:56 +01:00
isSelected:
_getSortFromPref() == album_util.AlbumSort.nameDescending,
2021-09-08 18:23:42 +02:00
onSelect: () {
2021-12-10 19:44:56 +01:00
_onSortSelected(album_util.AlbumSort.nameDescending);
2021-09-08 18:23:42 +02:00
Navigator.of(context).pop();
},
),
],
),
);
}
2021-12-10 19:44:56 +01:00
void _onSortSelected(album_util.AlbumSort sort) async {
2021-10-27 22:40:54 +02:00
await Pref().setHomeAlbumsSort(sort.index);
2021-09-08 18:23:42 +02:00
setState(() {
_transformItems(_bloc.state.items);
});
}
2021-09-29 16:55:49 +02:00
void _onImportPressed(BuildContext context) {
2021-07-01 13:32:22 +02:00
Navigator.of(context).pushNamed(AlbumImporter.routeName,
arguments: AlbumImporterArguments(widget.account));
}
2021-09-29 16:55:49 +02:00
Future<void> _onSelectionDeletePressed() async {
2021-08-22 22:03:13 +02:00
final selected = selectedListItems
.whereType<_AlbumListItem>()
.map((e) => e.album)
.toList();
2021-04-10 06:28:12 +02:00
SnackBarManager().showSnackBar(SnackBar(
content: Text(
L10n.global().deleteSelectedProcessingNotification(selected.length)),
2021-04-10 06:28:12 +02:00
duration: k.snackBarDurationShort,
));
setState(() {
2021-08-22 22:03:13 +02:00
clearSelectedItems();
2021-04-10 06:28:12 +02:00
});
2021-10-25 13:20:56 +02:00
final failures = <Album>[];
2021-11-28 17:07:43 +01:00
for (final a in selected) {
2021-04-10 06:28:12 +02:00
try {
if (a.albumFile?.isOwned(widget.account.username) == true) {
// delete owned albums
await RemoveAlbum(KiwiContainer().resolve<DiContainer>())(
widget.account, a);
} else {
// remove shared albums from collection
await UnimportSharedAlbum(KiwiContainer().resolve<DiContainer>())(
widget.account, a);
}
2021-10-25 13:20:56 +02:00
} catch (e, stackTrace) {
2021-04-27 22:06:16 +02:00
_log.shout(
2021-10-25 13:20:56 +02:00
"[_onSelectionDeletePressed] Failed while removing album: '${a.name}'",
2021-04-10 06:28:12 +02:00
e,
2021-10-25 13:20:56 +02:00
stackTrace);
failures.add(a);
2021-04-10 06:28:12 +02:00
}
}
if (failures.isEmpty) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(L10n.global().deleteSelectedSuccessNotification),
2021-04-10 06:28:12 +02:00
duration: k.snackBarDurationNormal,
));
} else {
SnackBarManager().showSnackBar(SnackBar(
content: Text(
L10n.global().deleteSelectedFailureNotification(failures.length)),
2021-04-10 06:28:12 +02:00
duration: k.snackBarDurationNormal,
));
}
}
void _onAccountPrefUpdatedEvent(AccountPrefUpdatedEvent ev) {
if (ev.key == PrefKey.isEnableFaceRecognitionApp ||
ev.key == PrefKey.hasNewSharedAlbum) {
if (identical(ev.pref, AccountPref.of(widget.account))) {
setState(() {
_transformItems(_bloc.state.items);
});
}
}
}
2021-04-10 06:28:12 +02:00
/// Transform an Album list to grid items
2021-08-13 12:38:46 +02:00
void _transformItems(List<ListAlbumBlocItem> items) {
2021-09-08 18:23:42 +02:00
final sort = _getSortFromPref();
2021-12-10 19:44:56 +01:00
final sortedAlbums =
album_util.sorted(items.map((e) => e.album).toList(), sort);
2021-08-22 22:03:13 +02:00
itemStreamListItems = [
2022-01-25 11:08:13 +01:00
_buildFavoriteItem(context),
2021-12-05 13:02:22 +01:00
if (AccountPref.of(widget.account).isEnableFaceRecognitionAppOr())
_buildPersonItem(context),
2021-10-06 22:32:36 +02:00
_buildSharingItem(context),
2022-05-06 11:16:56 +02:00
if (features.isSupportEnhancement) _buildEnhancedPhotosItem(context),
2021-08-22 22:03:13 +02:00
_buildArchiveItem(context),
_buildTrashbinItem(context),
_buildNewAlbumItem(context),
_SeparatorListItem(),
2021-12-10 19:44:56 +01:00
...sortedAlbums.map((a) => _AlbumListItem(
2021-08-22 22:03:13 +02:00
account: widget.account,
2021-12-10 19:44:56 +01:00
album: a,
2021-08-22 22:03:13 +02:00
onTap: () {
2021-12-10 19:44:56 +01:00
_openAlbum(context, a);
2021-08-22 22:03:13 +02:00
},
)),
];
2021-04-10 06:28:12 +02:00
}
2021-08-20 08:06:37 +02:00
void _openAlbum(BuildContext context, Album album) {
2021-11-21 14:36:13 +01:00
album_browser_util.push(context, widget.account, album);
2021-07-16 09:55:04 +02:00
}
2021-04-10 06:28:12 +02:00
void _reqQuery() {
_bloc.add(ListAlbumBlocQuery(widget.account));
}
2021-11-18 14:09:36 +01:00
Future<void> _waitRefresh() async {
while (true) {
await Future.delayed(const Duration(seconds: 1));
if (_bloc.state is! ListAlbumBlocLoading) {
return;
}
}
}
2022-04-09 12:45:17 +02:00
double _calcBottomAppBarExtent(BuildContext context) => kToolbarHeight;
late final _bloc = ListAlbumBloc.of(widget.account);
late final _accountPrefUpdatedEventListener =
AppEventListener<AccountPrefUpdatedEvent>(_onAccountPrefUpdatedEvent);
2021-04-10 06:28:12 +02:00
static final _log = Logger("widget.home_albums._HomeAlbumsState");
2021-07-01 13:32:22 +02:00
static const _menuValueImport = 0;
2021-09-08 18:23:42 +02:00
static const _menuValueSort = 1;
2021-04-10 06:28:12 +02:00
}
2021-08-22 22:03:13 +02:00
abstract class _ListItem implements SelectableItem {
_ListItem({
VoidCallback? onTap,
2021-09-15 08:58:06 +02:00
}) : _myOnTap = onTap;
2021-04-10 06:28:12 +02:00
2021-08-22 22:03:13 +02:00
@override
2022-06-06 19:37:46 +02:00
get isTappable => _myOnTap != null;
2021-09-15 08:58:06 +02:00
get onTap => _myOnTap;
2021-08-22 22:03:13 +02:00
@override
get isSelectable => true;
@override
get staggeredTile => const StaggeredTile.count(1, 1);
2021-09-15 08:58:06 +02:00
final VoidCallback? _myOnTap;
2021-04-10 06:28:12 +02:00
}
2021-08-22 22:03:13 +02:00
class _ButtonListItem extends _ListItem {
_ButtonListItem({
required this.icon,
required this.label,
2021-08-22 22:03:13 +02:00
VoidCallback? onTap,
2021-08-20 19:02:13 +02:00
this.isShowIndicator = false,
2021-08-22 22:03:13 +02:00
}) : _onTap = onTap;
@override
2021-08-22 22:03:13 +02:00
get isSelectable => false;
@override
get staggeredTile => const StaggeredTile.fit(1);
@override
buildWidget(BuildContext context) {
return Padding(
2021-08-05 13:07:40 +02:00
padding: const EdgeInsets.symmetric(horizontal: 8),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Material(
type: MaterialType.transparency,
child: InkWell(
2021-08-22 22:03:13 +02:00
onTap: _onTap,
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: AppTheme.getListItemBackgroundColor(context),
width: 1,
),
borderRadius: BorderRadius.circular(8),
),
2022-05-16 19:57:31 +02:00
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
child: Row(
children: [
Icon(
icon,
color: AppTheme.getPrimaryTextColor(context),
size: 24,
),
const SizedBox(width: 8),
Expanded(
child: Text(label),
),
2021-08-20 19:02:13 +02:00
if (isShowIndicator)
2021-09-15 08:58:06 +02:00
const Icon(
2021-08-20 19:02:13 +02:00
Icons.circle,
color: Colors.red,
size: 8,
),
],
),
),
),
),
),
);
}
final IconData icon;
final String label;
2021-08-20 19:02:13 +02:00
final bool isShowIndicator;
2021-08-22 22:03:13 +02:00
final VoidCallback? _onTap;
}
class _SeparatorListItem extends _ListItem {
@override
get isSelectable => false;
@override
get staggeredTile => const StaggeredTile.extent(99, 1);
@override
buildWidget(BuildContext context) => Container();
}
class _AlbumListItem extends _ListItem {
_AlbumListItem({
required this.account,
required this.album,
VoidCallback? onTap,
}) : super(onTap: onTap);
@override
operator ==(Object other) {
return other is _AlbumListItem &&
album.albumFile!.path == other.album.albumFile!.path;
}
@override
get hashCode => album.albumFile!.path.hashCode;
@override
buildWidget(BuildContext context) {
return AlbumGridItemBuilder(
account: account,
album: album,
isShared: album.shares?.isNotEmpty == true,
2021-08-22 22:03:13 +02:00
).build(context);
}
final Account account;
final Album album;
}
2021-09-08 18:23:42 +02:00
2021-12-10 19:44:56 +01:00
album_util.AlbumSort _getSortFromPref() {
2021-09-08 18:23:42 +02:00
try {
2021-12-10 19:44:56 +01:00
return album_util.AlbumSort.values[Pref().getHomeAlbumsSort()!];
2021-09-08 18:23:42 +02:00
} catch (_) {
// default
2021-12-10 19:44:56 +01:00
return album_util.AlbumSort.dateDescending;
2021-09-08 18:23:42 +02:00
}
}