2022-08-05 10:11:34 +02:00
|
|
|
import 'dart:ui';
|
|
|
|
|
2021-09-08 12:44:14 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2021-12-10 05:53:22 +01:00
|
|
|
import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart';
|
2021-09-08 12:44:14 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-09-10 19:10:26 +02:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2022-01-22 13:02:24 +01:00
|
|
|
import 'package:kiwi/kiwi.dart';
|
2021-09-08 12:44:14 +02:00
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:nc_photos/account.dart';
|
|
|
|
import 'package:nc_photos/api/api.dart';
|
|
|
|
import 'package:nc_photos/api/api_util.dart' as api_util;
|
|
|
|
import 'package:nc_photos/app_localizations.dart';
|
2022-08-05 10:11:34 +02:00
|
|
|
import 'package:nc_photos/bloc/list_face_file.dart';
|
2021-09-16 12:10:50 +02:00
|
|
|
import 'package:nc_photos/cache_manager_util.dart';
|
2022-08-05 10:11:34 +02:00
|
|
|
import 'package:nc_photos/compute_queue.dart';
|
2022-01-22 13:02:24 +01:00
|
|
|
import 'package:nc_photos/di_container.dart';
|
2021-09-28 22:56:44 +02:00
|
|
|
import 'package:nc_photos/download_handler.dart';
|
2021-09-08 12:44:14 +02:00
|
|
|
import 'package:nc_photos/entity/file.dart';
|
|
|
|
import 'package:nc_photos/entity/person.dart';
|
|
|
|
import 'package:nc_photos/event/event.dart';
|
2021-09-10 19:10:26 +02:00
|
|
|
import 'package:nc_photos/exception_util.dart' as exception_util;
|
2021-09-08 12:44:14 +02:00
|
|
|
import 'package:nc_photos/iterable_extension.dart';
|
2021-09-10 19:10:26 +02:00
|
|
|
import 'package:nc_photos/k.dart' as k;
|
2022-08-05 10:11:34 +02:00
|
|
|
import 'package:nc_photos/language_util.dart' as language_util;
|
2022-06-06 19:37:46 +02:00
|
|
|
import 'package:nc_photos/object_extension.dart';
|
2021-09-08 12:44:14 +02:00
|
|
|
import 'package:nc_photos/pref.dart';
|
|
|
|
import 'package:nc_photos/share_handler.dart';
|
2021-09-10 19:10:26 +02:00
|
|
|
import 'package:nc_photos/snack_bar_manager.dart';
|
2021-09-08 12:44:14 +02:00
|
|
|
import 'package:nc_photos/theme.dart';
|
|
|
|
import 'package:nc_photos/throttler.dart';
|
2022-08-05 10:11:34 +02:00
|
|
|
import 'package:nc_photos/widget/builder/photo_list_item_builder.dart';
|
2021-11-17 21:21:21 +01:00
|
|
|
import 'package:nc_photos/widget/handler/add_selection_to_album_handler.dart';
|
2022-01-22 13:02:24 +01:00
|
|
|
import 'package:nc_photos/widget/handler/archive_selection_handler.dart';
|
2021-12-02 11:47:37 +01:00
|
|
|
import 'package:nc_photos/widget/handler/remove_selection_handler.dart';
|
2021-09-08 12:44:14 +02:00
|
|
|
import 'package:nc_photos/widget/photo_list_item.dart';
|
2021-12-19 12:44:41 +01:00
|
|
|
import 'package:nc_photos/widget/photo_list_util.dart' as photo_list_util;
|
2021-09-08 12:44:14 +02:00
|
|
|
import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart';
|
|
|
|
import 'package:nc_photos/widget/selection_app_bar.dart';
|
|
|
|
import 'package:nc_photos/widget/viewer.dart';
|
|
|
|
import 'package:nc_photos/widget/zoom_menu_button.dart';
|
|
|
|
|
|
|
|
class PersonBrowserArguments {
|
|
|
|
PersonBrowserArguments(this.account, this.person);
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final Person person;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Show a list of all faces associated with this person
|
|
|
|
class PersonBrowser extends StatefulWidget {
|
|
|
|
static const routeName = "/person-browser";
|
|
|
|
|
|
|
|
static Route buildRoute(PersonBrowserArguments args) => MaterialPageRoute(
|
|
|
|
builder: (context) => PersonBrowser.fromArgs(args),
|
|
|
|
);
|
|
|
|
|
2021-09-15 08:58:06 +02:00
|
|
|
const PersonBrowser({
|
2021-09-08 12:44:14 +02:00
|
|
|
Key? key,
|
|
|
|
required this.account,
|
|
|
|
required this.person,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
PersonBrowser.fromArgs(PersonBrowserArguments args, {Key? key})
|
|
|
|
: this(
|
|
|
|
key: key,
|
|
|
|
account: args.account,
|
|
|
|
person: args.person,
|
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
|
|
|
createState() => _PersonBrowserState();
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final Person person;
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PersonBrowserState extends State<PersonBrowser>
|
|
|
|
with SelectableItemStreamListMixin<PersonBrowser> {
|
2022-07-05 22:20:24 +02:00
|
|
|
_PersonBrowserState() {
|
|
|
|
final c = KiwiContainer().resolve<DiContainer>();
|
|
|
|
assert(require(c));
|
2022-08-05 10:11:34 +02:00
|
|
|
assert(ListFaceFileBloc.require(c));
|
2022-07-05 22:20:24 +02:00
|
|
|
_c = c;
|
|
|
|
}
|
|
|
|
|
2022-08-05 10:11:34 +02:00
|
|
|
static bool require(DiContainer c) => true;
|
2022-07-05 22:20:24 +02:00
|
|
|
|
2021-09-08 12:44:14 +02:00
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
2021-09-10 19:10:26 +02:00
|
|
|
_initBloc();
|
2021-10-27 22:40:54 +02:00
|
|
|
_thumbZoomLevel = Pref().getAlbumBrowserZoomLevelOr(0);
|
2021-09-08 12:44:14 +02:00
|
|
|
|
|
|
|
_filePropertyUpdatedListener.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
dispose() {
|
|
|
|
_filePropertyUpdatedListener.end();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context) {
|
|
|
|
return AppTheme(
|
|
|
|
child: Scaffold(
|
2022-08-05 10:11:34 +02:00
|
|
|
body: BlocListener<ListFaceFileBloc, ListFaceFileBlocState>(
|
2021-09-10 19:10:26 +02:00
|
|
|
bloc: _bloc,
|
|
|
|
listener: (context, state) => _onStateChange(context, state),
|
2022-08-05 10:11:34 +02:00
|
|
|
child: BlocBuilder<ListFaceFileBloc, ListFaceFileBlocState>(
|
2021-09-10 19:10:26 +02:00
|
|
|
bloc: _bloc,
|
2022-08-05 10:11:34 +02:00
|
|
|
builder: (context, state) => _buildContent(context, state),
|
2021-09-10 19:10:26 +02:00
|
|
|
),
|
2021-09-08 12:44:14 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:37:46 +02:00
|
|
|
@override
|
|
|
|
onItemTap(SelectableItem item, int index) {
|
2022-08-05 10:11:34 +02:00
|
|
|
item.as<PhotoListFileItem>()?.run((fileItem) {
|
2022-08-07 13:55:00 +02:00
|
|
|
Navigator.pushNamed(
|
|
|
|
context,
|
|
|
|
Viewer.routeName,
|
|
|
|
arguments:
|
|
|
|
ViewerArguments(widget.account, _backingFiles, fileItem.fileIndex),
|
|
|
|
);
|
2022-08-05 10:11:34 +02:00
|
|
|
});
|
2022-06-06 19:37:46 +02:00
|
|
|
}
|
|
|
|
|
2021-09-10 19:10:26 +02:00
|
|
|
void _initBloc() {
|
|
|
|
_log.info("[_initBloc] Initialize bloc");
|
|
|
|
_reqQuery();
|
2021-09-08 12:44:14 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 10:11:34 +02:00
|
|
|
Widget _buildContent(BuildContext context, ListFaceFileBlocState state) {
|
|
|
|
return buildItemStreamListOuter(
|
|
|
|
context,
|
|
|
|
child: Theme(
|
|
|
|
data: Theme.of(context).copyWith(
|
|
|
|
colorScheme: Theme.of(context).colorScheme.copyWith(
|
|
|
|
secondary: AppTheme.getOverscrollIndicatorColor(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: CustomScrollView(
|
|
|
|
slivers: [
|
2022-08-05 16:46:33 +02:00
|
|
|
_buildAppBar(context, state),
|
2022-08-05 10:11:34 +02:00
|
|
|
if (state is ListFaceFileBlocLoading ||
|
|
|
|
_buildItemQueue.isProcessing)
|
|
|
|
const SliverToBoxAdapter(
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: LinearProgressIndicator(),
|
2021-09-15 18:29:37 +02:00
|
|
|
),
|
2021-09-08 12:44:14 +02:00
|
|
|
),
|
2022-08-05 10:11:34 +02:00
|
|
|
buildItemStreamList(
|
|
|
|
maxCrossAxisExtent: _thumbSize.toDouble(),
|
|
|
|
),
|
|
|
|
],
|
2021-09-08 12:44:14 +02:00
|
|
|
),
|
2022-08-05 10:11:34 +02:00
|
|
|
),
|
|
|
|
);
|
2021-09-08 12:44:14 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 16:46:33 +02:00
|
|
|
Widget _buildAppBar(BuildContext context, ListFaceFileBlocState state) {
|
2021-09-08 12:44:14 +02:00
|
|
|
if (isSelectionMode) {
|
|
|
|
return _buildSelectionAppBar(context);
|
|
|
|
} else {
|
2022-08-05 16:46:33 +02:00
|
|
|
return _buildNormalAppBar(context, state);
|
2021-09-08 12:44:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-05 16:46:33 +02:00
|
|
|
Widget _buildNormalAppBar(BuildContext context, ListFaceFileBlocState state) {
|
2021-09-08 12:44:14 +02:00
|
|
|
return SliverAppBar(
|
|
|
|
floating: true,
|
|
|
|
titleSpacing: 0,
|
|
|
|
title: Row(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 40,
|
|
|
|
width: 40,
|
|
|
|
child: _buildFaceImage(context),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text(
|
2021-09-10 19:10:26 +02:00
|
|
|
widget.person.name,
|
2021-09-08 12:44:14 +02:00
|
|
|
style: TextStyle(
|
|
|
|
color: AppTheme.getPrimaryTextColor(context),
|
|
|
|
),
|
|
|
|
maxLines: 1,
|
|
|
|
softWrap: false,
|
|
|
|
overflow: TextOverflow.clip,
|
|
|
|
),
|
2022-08-05 16:46:33 +02:00
|
|
|
if (state is! ListFaceFileBlocLoading &&
|
|
|
|
!_buildItemQueue.isProcessing)
|
2021-09-08 12:44:14 +02:00
|
|
|
Text(
|
2022-08-17 16:43:52 +02:00
|
|
|
L10n.global().personPhotoCountText(_backingFiles.length),
|
2021-09-08 12:44:14 +02:00
|
|
|
style: TextStyle(
|
|
|
|
color: AppTheme.getSecondaryTextColor(context),
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
// ),
|
|
|
|
actions: [
|
|
|
|
ZoomMenuButton(
|
|
|
|
initialZoom: _thumbZoomLevel,
|
|
|
|
minZoom: 0,
|
|
|
|
maxZoom: 2,
|
|
|
|
onZoomChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_thumbZoomLevel = value.round();
|
|
|
|
});
|
2021-10-27 22:40:54 +02:00
|
|
|
Pref().setAlbumBrowserZoomLevel(_thumbZoomLevel);
|
2021-09-08 12:44:14 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildFaceImage(BuildContext context) {
|
|
|
|
Widget cover;
|
|
|
|
try {
|
|
|
|
cover = FittedBox(
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
child: CachedNetworkImage(
|
2021-09-16 12:10:50 +02:00
|
|
|
cacheManager: ThumbnailCacheManager.inst,
|
2021-09-08 12:44:14 +02:00
|
|
|
imageUrl: api_util.getFacePreviewUrl(
|
2021-09-10 19:10:26 +02:00
|
|
|
widget.account, widget.person.thumbFaceId,
|
2021-09-16 12:25:08 +02:00
|
|
|
size: k.faceThumbSize),
|
2021-09-08 12:44:14 +02:00
|
|
|
httpHeaders: {
|
|
|
|
"Authorization": Api.getAuthorizationHeaderValue(widget.account),
|
|
|
|
},
|
|
|
|
fadeInDuration: const Duration(),
|
|
|
|
filterQuality: FilterQuality.high,
|
|
|
|
errorWidget: (context, url, error) {
|
|
|
|
// just leave it empty
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} catch (_) {
|
|
|
|
cover = Icon(
|
|
|
|
Icons.person,
|
|
|
|
color: Colors.white.withOpacity(.8),
|
|
|
|
size: 24,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(64),
|
|
|
|
child: Container(
|
|
|
|
color: AppTheme.getListItemBackgroundColor(context),
|
|
|
|
constraints: const BoxConstraints.expand(),
|
|
|
|
child: cover,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildSelectionAppBar(BuildContext context) {
|
|
|
|
return SelectionAppBar(
|
|
|
|
count: selectedListItems.length,
|
|
|
|
onClosePressed: () {
|
|
|
|
setState(() {
|
|
|
|
clearSelectedItems();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
actions: [
|
2021-10-09 10:42:18 +02:00
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.share),
|
|
|
|
tooltip: L10n.global().shareTooltip,
|
|
|
|
onPressed: () {
|
|
|
|
_onSelectionSharePressed(context);
|
|
|
|
},
|
|
|
|
),
|
2021-09-08 12:44:14 +02:00
|
|
|
IconButton(
|
2022-01-22 13:04:18 +01:00
|
|
|
icon: const Icon(Icons.add),
|
2021-09-08 12:44:14 +02:00
|
|
|
tooltip: L10n.global().addToAlbumTooltip,
|
|
|
|
onPressed: () {
|
2021-09-29 16:55:49 +02:00
|
|
|
_onSelectionAddToAlbumPressed(context);
|
2021-09-08 12:44:14 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
PopupMenuButton<_SelectionMenuOption>(
|
|
|
|
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-09-08 12:44:14 +02:00
|
|
|
PopupMenuItem(
|
|
|
|
value: _SelectionMenuOption.archive,
|
|
|
|
child: Text(L10n.global().archiveTooltip),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: _SelectionMenuOption.delete,
|
|
|
|
child: Text(L10n.global().deleteTooltip),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
onSelected: (option) {
|
2021-09-29 16:55:49 +02:00
|
|
|
_onSelectionMenuSelected(context, option);
|
2021-09-08 12:44:14 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-05 10:11:34 +02:00
|
|
|
void _onStateChange(BuildContext context, ListFaceFileBlocState state) {
|
|
|
|
if (state is ListFaceFileBlocInit) {
|
|
|
|
itemStreamListItems = [];
|
|
|
|
} else if (state is ListFaceFileBlocSuccess ||
|
|
|
|
state is ListFaceFileBlocLoading) {
|
2021-09-10 19:10:26 +02:00
|
|
|
_transformItems(state.items);
|
2022-08-05 10:11:34 +02:00
|
|
|
} else if (state is ListFaceFileBlocFailure) {
|
2021-09-10 19:10:26 +02:00
|
|
|
_transformItems(state.items);
|
|
|
|
SnackBarManager().showSnackBar(SnackBar(
|
|
|
|
content: Text(exception_util.toUserString(state.exception)),
|
|
|
|
duration: k.snackBarDurationNormal,
|
|
|
|
));
|
2022-08-07 13:55:00 +02:00
|
|
|
} else if (state is ListFaceFileBlocInconsistent) {
|
|
|
|
_reqQuery();
|
2021-09-10 19:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 16:55:49 +02:00
|
|
|
void _onSelectionMenuSelected(
|
|
|
|
BuildContext context, _SelectionMenuOption option) {
|
|
|
|
switch (option) {
|
|
|
|
case _SelectionMenuOption.archive:
|
|
|
|
_onSelectionArchivePressed(context);
|
|
|
|
break;
|
|
|
|
case _SelectionMenuOption.delete:
|
|
|
|
_onSelectionDeletePressed(context);
|
|
|
|
break;
|
|
|
|
case _SelectionMenuOption.download:
|
|
|
|
_onSelectionDownloadPressed();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_log.shout("[_onSelectionMenuSelected] Unknown option: $option");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _onSelectionSharePressed(BuildContext context) {
|
2022-08-05 10:11:34 +02:00
|
|
|
final selected = selectedListItems
|
|
|
|
.whereType<PhotoListFileItem>()
|
|
|
|
.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-08 12:44:14 +02:00
|
|
|
}
|
|
|
|
|
2021-11-17 21:21:21 +01:00
|
|
|
Future<void> _onSelectionAddToAlbumPressed(BuildContext context) {
|
|
|
|
return AddSelectionToAlbumHandler()(
|
|
|
|
context: context,
|
|
|
|
account: widget.account,
|
2022-08-05 10:11:34 +02:00
|
|
|
selectedFiles: selectedListItems
|
|
|
|
.whereType<PhotoListFileItem>()
|
|
|
|
.map((e) => e.file)
|
|
|
|
.toList(),
|
2021-11-17 21:21:21 +01:00
|
|
|
clearSelection: () {
|
|
|
|
if (mounted) {
|
2021-09-08 12:44:14 +02:00
|
|
|
setState(() {
|
|
|
|
clearSelectedItems();
|
|
|
|
});
|
2021-11-17 21:21:21 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-09-08 12:44:14 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 16:55:49 +02:00
|
|
|
void _onSelectionDownloadPressed() {
|
2022-08-05 10:11:34 +02:00
|
|
|
final selected = selectedListItems
|
|
|
|
.whereType<PhotoListFileItem>()
|
|
|
|
.map((e) => e.file)
|
|
|
|
.toList();
|
2021-09-28 22:56:44 +02:00
|
|
|
DownloadHandler().downloadFiles(widget.account, selected);
|
|
|
|
setState(() {
|
|
|
|
clearSelectedItems();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-29 16:55:49 +02:00
|
|
|
Future<void> _onSelectionArchivePressed(BuildContext context) async {
|
2022-08-05 10:11:34 +02:00
|
|
|
final selectedFiles = selectedListItems
|
|
|
|
.whereType<PhotoListFileItem>()
|
|
|
|
.map((e) => e.file)
|
|
|
|
.toList();
|
2021-09-08 12:44:14 +02:00
|
|
|
setState(() {
|
|
|
|
clearSelectedItems();
|
|
|
|
});
|
2022-01-22 13:02:24 +01:00
|
|
|
await ArchiveSelectionHandler(KiwiContainer().resolve<DiContainer>())(
|
|
|
|
account: widget.account,
|
|
|
|
selectedFiles: selectedFiles,
|
|
|
|
);
|
2021-09-08 12:44:14 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 16:55:49 +02:00
|
|
|
Future<void> _onSelectionDeletePressed(BuildContext context) async {
|
2022-08-05 10:11:34 +02:00
|
|
|
final selectedFiles = selectedListItems
|
|
|
|
.whereType<PhotoListFileItem>()
|
|
|
|
.map((e) => e.file)
|
|
|
|
.toList();
|
2021-09-08 12:44:14 +02:00
|
|
|
setState(() {
|
|
|
|
clearSelectedItems();
|
|
|
|
});
|
2021-12-02 11:47:37 +01:00
|
|
|
await RemoveSelectionHandler()(
|
|
|
|
account: widget.account,
|
|
|
|
selectedFiles: selectedFiles,
|
2022-04-22 21:09:44 +02:00
|
|
|
isMoveToTrash: true,
|
2021-12-02 11:47:37 +01:00
|
|
|
);
|
2021-09-08 12:44:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void _onFilePropertyUpdated(FilePropertyUpdatedEvent ev) {
|
2022-08-05 10:11:34 +02:00
|
|
|
if (_backingFiles.containsIf(ev.file, (a, b) => a.fileId == b.fileId) !=
|
2021-09-08 12:44:14 +02:00
|
|
|
true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_refreshThrottler.trigger(
|
|
|
|
maxResponceTime: const Duration(seconds: 3),
|
|
|
|
maxPendingCount: 10,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-05 10:11:34 +02:00
|
|
|
Future<void> _transformItems(List<File> files) async {
|
2022-08-07 13:55:00 +02:00
|
|
|
final PhotoListItemSorter? sorter;
|
|
|
|
final PhotoListItemGrouper? grouper;
|
|
|
|
if (Pref().isPhotosTabSortByNameOr()) {
|
|
|
|
sorter = photoListFilenameSorter;
|
|
|
|
grouper = null;
|
|
|
|
} else {
|
|
|
|
sorter = photoListFileDateTimeSorter;
|
|
|
|
grouper = PhotoListFileDateGrouper(isMonthOnly: _thumbZoomLevel < 0);
|
|
|
|
}
|
|
|
|
|
2022-08-05 10:11:34 +02:00
|
|
|
_buildItemQueue.addJob(
|
|
|
|
PhotoListItemBuilderArguments(
|
|
|
|
widget.account,
|
|
|
|
files,
|
2022-08-07 13:55:00 +02:00
|
|
|
sorter: sorter,
|
|
|
|
grouper: grouper,
|
|
|
|
shouldShowFavoriteBadge: true,
|
2022-08-05 10:11:34 +02:00
|
|
|
locale: language_util.getSelectedLocale() ??
|
|
|
|
PlatformDispatcher.instance.locale,
|
|
|
|
),
|
|
|
|
buildPhotoListItem,
|
|
|
|
(result) {
|
|
|
|
if (mounted) {
|
|
|
|
setState(() {
|
|
|
|
_backingFiles = result.backingFiles;
|
|
|
|
itemStreamListItems = result.listItems;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-09-10 19:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void _reqQuery() {
|
2022-08-05 10:11:34 +02:00
|
|
|
_bloc.add(ListFaceFileBlocQuery(widget.account, widget.person));
|
2021-09-08 12:44:14 +02:00
|
|
|
}
|
|
|
|
|
2022-07-05 22:20:24 +02:00
|
|
|
late final DiContainer _c;
|
|
|
|
|
2022-08-05 10:11:34 +02:00
|
|
|
late final ListFaceFileBloc _bloc = ListFaceFileBloc(_c);
|
|
|
|
var _backingFiles = <File>[];
|
|
|
|
|
|
|
|
final _buildItemQueue =
|
|
|
|
ComputeQueue<PhotoListItemBuilderArguments, PhotoListItemBuilderResult>();
|
2021-09-08 12:44:14 +02:00
|
|
|
|
|
|
|
var _thumbZoomLevel = 0;
|
2021-12-19 12:44:41 +01:00
|
|
|
int get _thumbSize => photo_list_util.getThumbSize(_thumbZoomLevel);
|
2021-09-08 12:44:14 +02:00
|
|
|
|
|
|
|
late final Throttler _refreshThrottler = Throttler(
|
|
|
|
onTriggered: (_) {
|
2021-09-10 19:10:26 +02:00
|
|
|
if (mounted) {
|
|
|
|
_transformItems(_bloc.state.items);
|
|
|
|
}
|
2021-09-08 12:44:14 +02:00
|
|
|
},
|
|
|
|
logTag: "_PersonBrowserState.refresh",
|
|
|
|
);
|
|
|
|
|
|
|
|
late final _filePropertyUpdatedListener =
|
|
|
|
AppEventListener<FilePropertyUpdatedEvent>(_onFilePropertyUpdated);
|
|
|
|
|
|
|
|
static final _log = Logger("widget.person_browser._PersonBrowserState");
|
|
|
|
}
|
|
|
|
|
|
|
|
enum _SelectionMenuOption {
|
|
|
|
archive,
|
|
|
|
delete,
|
2021-09-28 22:56:44 +02:00
|
|
|
download,
|
2021-09-08 12:44:14 +02:00
|
|
|
}
|