2021-08-15 19:06:00 +02:00
|
|
|
import 'dart:math' as math;
|
|
|
|
|
2021-05-19 21:11:06 +02:00
|
|
|
import 'package:draggable_scrollbar/draggable_scrollbar.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/widgets.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';
|
|
|
|
import 'package:nc_photos/api/api_util.dart' as api_util;
|
2021-11-01 10:50:13 +01:00
|
|
|
import 'package:nc_photos/app_db.dart';
|
2021-07-25 07:00:38 +02:00
|
|
|
import 'package:nc_photos/app_localizations.dart';
|
2021-11-16 21:02:24 +01:00
|
|
|
import 'package:nc_photos/bloc/scan_account_dir.dart';
|
2021-09-04 14:35:04 +02:00
|
|
|
import 'package:nc_photos/debug_util.dart';
|
2021-09-28 22:56:44 +02:00
|
|
|
import 'package:nc_photos/download_handler.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/entity/album.dart';
|
2021-07-05 09:54:01 +02:00
|
|
|
import 'package:nc_photos/entity/album/item.dart';
|
2021-06-24 18:26:56 +02:00
|
|
|
import 'package:nc_photos/entity/album/provider.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/entity/file.dart';
|
2021-05-24 09:09:25 +02:00
|
|
|
import 'package:nc_photos/entity/file/data_source.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
2021-10-23 06:47:32 +02:00
|
|
|
import 'package:nc_photos/entity/share.dart';
|
|
|
|
import 'package:nc_photos/entity/share/data_source.dart';
|
2021-08-15 19:06:00 +02:00
|
|
|
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/iterable_extension.dart';
|
|
|
|
import 'package:nc_photos/k.dart' as k;
|
2021-04-11 11:57:08 +02:00
|
|
|
import 'package:nc_photos/metadata_task_manager.dart';
|
2021-09-08 11:39:24 +02:00
|
|
|
import 'package:nc_photos/notified_action.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/pref.dart';
|
2021-05-25 15:59:27 +02:00
|
|
|
import 'package:nc_photos/primitive.dart';
|
2021-07-10 17:06:04 +02:00
|
|
|
import 'package:nc_photos/share_handler.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/snack_bar_manager.dart';
|
|
|
|
import 'package:nc_photos/theme.dart';
|
2021-09-08 10:17:51 +02:00
|
|
|
import 'package:nc_photos/use_case/add_to_album.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/use_case/remove.dart';
|
2021-05-28 21:44:09 +02:00
|
|
|
import 'package:nc_photos/use_case/update_property.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/widget/album_picker_dialog.dart';
|
|
|
|
import 'package:nc_photos/widget/home_app_bar.dart';
|
2021-05-19 21:11:06 +02:00
|
|
|
import 'package:nc_photos/widget/measure.dart';
|
2021-07-11 06:48:50 +02:00
|
|
|
import 'package:nc_photos/widget/page_visibility_mixin.dart';
|
2021-10-04 15:53:03 +02:00
|
|
|
import 'package:nc_photos/widget/photo_list_helper.dart';
|
2021-05-06 13:29:20 +02:00
|
|
|
import 'package:nc_photos/widget/photo_list_item.dart';
|
2021-04-23 09:55:53 +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-08-15 19:06:00 +02:00
|
|
|
import 'package:nc_photos/widget/settings.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/widget/viewer.dart';
|
2021-07-25 10:52:24 +02:00
|
|
|
import 'package:nc_photos/widget/zoom_menu_button.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
class HomePhotos extends StatefulWidget {
|
2021-09-15 08:58:06 +02:00
|
|
|
const HomePhotos({
|
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() => _HomePhotosState();
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
}
|
|
|
|
|
2021-04-23 09:55:53 +02:00
|
|
|
class _HomePhotosState extends State<HomePhotos>
|
2021-07-11 06:48:50 +02:00
|
|
|
with
|
|
|
|
SelectableItemStreamListMixin<HomePhotos>,
|
|
|
|
RouteAware,
|
2021-08-15 19:06:00 +02:00
|
|
|
PageVisibilityMixin,
|
|
|
|
TickerProviderStateMixin {
|
2021-04-10 06:28:12 +02:00
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
2021-10-27 22:40:54 +02:00
|
|
|
_thumbZoomLevel = Pref().getHomePhotosZoomLevelOr(0);
|
2021-06-27 07:18:13 +02:00
|
|
|
_initBloc();
|
2021-08-15 19:06:00 +02:00
|
|
|
_metadataTaskStateChangedListener.begin();
|
2021-09-12 12:59:20 +02:00
|
|
|
_prefUpdatedListener.begin();
|
2021-09-12 19:30:09 +02:00
|
|
|
_filePropertyUpdatedListener.begin();
|
2021-08-15 19:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
dispose() {
|
|
|
|
_metadataTaskIconController.stop();
|
|
|
|
_metadataTaskStateChangedListener.end();
|
2021-09-12 12:59:20 +02:00
|
|
|
_prefUpdatedListener.end();
|
2021-09-12 19:30:09 +02:00
|
|
|
_filePropertyUpdatedListener.end();
|
2021-08-15 19:06:00 +02:00
|
|
|
super.dispose();
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context) {
|
2021-11-16 21:02:24 +01:00
|
|
|
return BlocListener<ScanAccountDirBloc, ScanAccountDirBlocState>(
|
2021-04-10 06:28:12 +02:00
|
|
|
bloc: _bloc,
|
|
|
|
listener: (context, state) => _onStateChange(context, state),
|
2021-11-16 21:02:24 +01:00
|
|
|
child: BlocBuilder<ScanAccountDirBloc, ScanAccountDirBlocState>(
|
2021-04-10 06:28:12 +02:00
|
|
|
bloc: _bloc,
|
2021-04-23 09:55:53 +02:00
|
|
|
builder: (context, state) => _buildContent(context, state),
|
2021-04-10 06:28:12 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _initBloc() {
|
2021-11-16 21:02:24 +01:00
|
|
|
if (_bloc.state is ScanAccountDirBlocInit) {
|
2021-04-10 06:28:12 +02:00
|
|
|
_log.info("[_initBloc] Initialize bloc");
|
2021-04-11 11:52:39 +02:00
|
|
|
_reqQuery();
|
2021-04-10 06:28:12 +02:00
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 21:02:24 +01:00
|
|
|
Widget _buildContent(BuildContext context, ScanAccountDirBlocState state) {
|
2021-05-19 21:11:06 +02:00
|
|
|
return LayoutBuilder(builder: (context, constraints) {
|
|
|
|
final scrollExtent = _getScrollViewExtent(constraints);
|
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
buildItemStreamListOuter(
|
|
|
|
context,
|
|
|
|
child: Theme(
|
|
|
|
data: Theme.of(context).copyWith(
|
2021-09-15 18:29:37 +02:00
|
|
|
colorScheme: Theme.of(context).colorScheme.copyWith(
|
|
|
|
secondary: AppTheme.getOverscrollIndicatorColor(context),
|
|
|
|
),
|
2021-05-19 21:11:06 +02:00
|
|
|
),
|
|
|
|
child: DraggableScrollbar.semicircle(
|
|
|
|
controller: _scrollController,
|
|
|
|
overrideMaxScrollExtent: scrollExtent,
|
2021-05-20 22:35:36 +02:00
|
|
|
child: ScrollConfiguration(
|
|
|
|
behavior: ScrollConfiguration.of(context)
|
|
|
|
.copyWith(scrollbars: false),
|
2021-10-04 20:41:30 +02:00
|
|
|
child: RefreshIndicator(
|
|
|
|
backgroundColor: Colors.grey[100],
|
|
|
|
onRefresh: () async {
|
|
|
|
_onRefreshSelected();
|
|
|
|
},
|
|
|
|
child: CustomScrollView(
|
|
|
|
controller: _scrollController,
|
|
|
|
slivers: [
|
|
|
|
_buildAppBar(context),
|
|
|
|
if (_metadataTaskState != MetadataTaskState.idle)
|
|
|
|
_buildMetadataTaskHeader(context),
|
|
|
|
SliverPadding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
|
|
sliver: buildItemStreamList(
|
|
|
|
maxCrossAxisExtent: _thumbSize.toDouble(),
|
|
|
|
onMaxExtentChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_itemListMaxExtent = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
2021-07-06 07:10:36 +02:00
|
|
|
),
|
2021-10-04 20:41:30 +02:00
|
|
|
],
|
|
|
|
),
|
2021-05-20 22:35:36 +02:00
|
|
|
),
|
2021-04-10 06:28:12 +02:00
|
|
|
),
|
2021-05-19 21:11:06 +02:00
|
|
|
),
|
2021-04-23 09:55:53 +02:00
|
|
|
),
|
2021-04-10 06:28:12 +02:00
|
|
|
),
|
2021-11-16 21:02:24 +01:00
|
|
|
if (state is ScanAccountDirBlocLoading)
|
2021-09-15 08:58:06 +02:00
|
|
|
const Align(
|
2021-05-19 21:11:06 +02:00
|
|
|
alignment: Alignment.bottomCenter,
|
2021-09-15 08:58:06 +02:00
|
|
|
child: LinearProgressIndicator(),
|
2021-05-19 21:11:06 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildAppBar(BuildContext context) {
|
2021-04-23 09:55:53 +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(
|
|
|
|
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-07-25 16:27:19 +02:00
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.playlist_add),
|
2021-08-29 13:51:43 +02:00
|
|
|
tooltip: L10n.global().addToAlbumTooltip,
|
2021-07-25 16:27:19 +02:00
|
|
|
onPressed: () {
|
2021-09-29 16:55:49 +02:00
|
|
|
_onSelectionAddToAlbumPressed(context);
|
2021-07-25 16:27:19 +02:00
|
|
|
},
|
|
|
|
),
|
2021-09-08 11:39:24 +02:00
|
|
|
PopupMenuButton<_SelectionMenuOption>(
|
2021-07-25 16:27:19 +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-07-25 16:27:19 +02:00
|
|
|
PopupMenuItem(
|
2021-09-08 11:39:24 +02:00
|
|
|
value: _SelectionMenuOption.archive,
|
2021-08-29 13:51:43 +02:00
|
|
|
child: Text(L10n.global().archiveTooltip),
|
2021-07-25 16:27:19 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
2021-09-08 11:39:24 +02:00
|
|
|
value: _SelectionMenuOption.delete,
|
2021-08-29 13:51:43 +02:00
|
|
|
child: Text(L10n.global().deleteTooltip),
|
2021-07-25 16:27:19 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
onSelected: (option) {
|
2021-09-29 16:55:49 +02:00
|
|
|
_onSelectionMenuSelected(context, option);
|
2021-07-25 16:27:19 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2021-04-10 06:28:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildNormalAppBar(BuildContext context) {
|
2021-05-19 21:11:06 +02:00
|
|
|
return SliverMeasureExtent(
|
|
|
|
onChange: (extent) {
|
|
|
|
_appBarExtent = extent;
|
2021-04-11 11:57:08 +02:00
|
|
|
},
|
2021-05-19 21:11:06 +02:00
|
|
|
child: HomeSliverAppBar(
|
|
|
|
account: widget.account,
|
|
|
|
actions: [
|
2021-07-25 10:52:24 +02:00
|
|
|
ZoomMenuButton(
|
|
|
|
initialZoom: _thumbZoomLevel,
|
|
|
|
minZoom: -1,
|
|
|
|
maxZoom: 2,
|
|
|
|
onZoomChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_setThumbZoomLevel(value.round());
|
|
|
|
});
|
2021-10-27 22:40:54 +02:00
|
|
|
Pref().setHomePhotosZoomLevel(_thumbZoomLevel);
|
2021-07-25 10:52:24 +02:00
|
|
|
},
|
2021-05-19 21:11:06 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
menuActions: [
|
|
|
|
PopupMenuItem(
|
|
|
|
value: _menuValueRefresh,
|
2021-08-29 13:51:43 +02:00
|
|
|
child: Text(L10n.global().refreshMenuLabel),
|
2021-05-19 21:11:06 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
onSelectedMenuActions: (option) {
|
|
|
|
switch (option) {
|
|
|
|
case _menuValueRefresh:
|
|
|
|
_onRefreshSelected();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2021-04-10 06:28:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-15 19:06:00 +02:00
|
|
|
Widget _buildMetadataTaskHeader(BuildContext context) {
|
|
|
|
return SliverPersistentHeader(
|
|
|
|
pinned: true,
|
|
|
|
floating: false,
|
|
|
|
delegate: _MetadataTaskHeaderDelegate(
|
|
|
|
extent: _metadataTaskHeaderHeight,
|
|
|
|
builder: (context) => Container(
|
|
|
|
height: double.infinity,
|
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
alignment: AlignmentDirectional.centerStart,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
if (_metadataTaskState == MetadataTaskState.prcoessing)
|
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
_MetadataTaskLoadingIcon(
|
|
|
|
controller: _metadataTaskIconController,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
Text(
|
2021-09-12 19:30:09 +02:00
|
|
|
L10n.global().metadataTaskProcessingNotification +
|
|
|
|
_getMetadataTaskProgressString(),
|
2021-09-15 08:58:06 +02:00
|
|
|
style: const TextStyle(fontSize: 12),
|
2021-08-15 19:06:00 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
else if (_metadataTaskState == MetadataTaskState.waitingForWifi)
|
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2021-09-15 08:58:06 +02:00
|
|
|
const Icon(
|
2021-08-15 19:06:00 +02:00
|
|
|
Icons.sync_problem,
|
|
|
|
size: 16,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
Text(
|
2021-08-29 13:51:43 +02:00
|
|
|
L10n.global().metadataTaskPauseNoWiFiNotification,
|
2021-09-15 08:58:06 +02:00
|
|
|
style: const TextStyle(fontSize: 12),
|
2021-08-15 19:06:00 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(),
|
|
|
|
),
|
|
|
|
Material(
|
|
|
|
type: MaterialType.transparency,
|
|
|
|
child: InkWell(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 8, vertical: 4),
|
|
|
|
child: Text(
|
2021-08-29 13:51:43 +02:00
|
|
|
L10n.global().configButtonLabel,
|
2021-08-15 19:06:00 +02:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pushNamed(Settings.routeName,
|
|
|
|
arguments: SettingsArguments(widget.account));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-16 21:02:24 +01:00
|
|
|
void _onStateChange(BuildContext context, ScanAccountDirBlocState state) {
|
|
|
|
if (state is ScanAccountDirBlocInit) {
|
2021-04-23 09:55:53 +02:00
|
|
|
itemStreamListItems = [];
|
2021-11-16 21:02:24 +01:00
|
|
|
} else if (state is ScanAccountDirBlocSuccess ||
|
|
|
|
state is ScanAccountDirBlocLoading) {
|
2021-04-10 06:28:12 +02:00
|
|
|
_transformItems(state.files);
|
2021-11-16 21:02:24 +01:00
|
|
|
if (state is ScanAccountDirBlocSuccess) {
|
2021-09-12 12:59:20 +02:00
|
|
|
_tryStartMetadataTask();
|
2021-05-23 19:25:39 +02:00
|
|
|
}
|
2021-11-16 21:02:24 +01:00
|
|
|
} else if (state is ScanAccountDirBlocFailure) {
|
2021-07-03 13:37:17 +02:00
|
|
|
_transformItems(state.files);
|
2021-07-11 06:48:50 +02:00
|
|
|
if (isPageVisible()) {
|
|
|
|
SnackBarManager().showSnackBar(SnackBar(
|
2021-08-29 13:51:43 +02:00
|
|
|
content: Text(exception_util.toUserString(state.exception)),
|
2021-07-11 06:48:50 +02:00
|
|
|
duration: k.snackBarDurationNormal,
|
|
|
|
));
|
|
|
|
}
|
2021-11-16 21:02:24 +01:00
|
|
|
} else if (state is ScanAccountDirBlocInconsistent) {
|
2021-04-11 11:52:39 +02:00
|
|
|
_reqQuery();
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 09:55:53 +02:00
|
|
|
void _onItemTap(int index) {
|
|
|
|
Navigator.pushNamed(context, Viewer.routeName,
|
|
|
|
arguments: ViewerArguments(widget.account, _backingFiles, index));
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 16:55:49 +02:00
|
|
|
void _onRefreshSelected() {
|
|
|
|
_hasFiredMetadataTask.value = false;
|
|
|
|
_reqRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2021-07-10 17:06:04 +02:00
|
|
|
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-07-10 17:06:04 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 16:55:49 +02:00
|
|
|
Future<void> _onSelectionAddToAlbumPressed(BuildContext context) async {
|
2021-09-08 11:39:24 +02:00
|
|
|
try {
|
|
|
|
final value = await showDialog<Album>(
|
|
|
|
context: context,
|
|
|
|
builder: (_) => AlbumPickerDialog(
|
|
|
|
account: widget.account,
|
|
|
|
),
|
|
|
|
);
|
2021-04-10 06:28:12 +02:00
|
|
|
if (value == null) {
|
|
|
|
// user cancelled the dialog
|
2021-09-08 11:39:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-29 16:55:49 +02:00
|
|
|
_log.info("[_onSelectionAddToAlbumPressed] Album picked: ${value.name}");
|
2021-09-08 11:39:24 +02:00
|
|
|
await NotifiedAction(
|
|
|
|
() async {
|
|
|
|
assert(value.provider is AlbumStaticProvider);
|
|
|
|
final selected = selectedListItems
|
|
|
|
.whereType<_FileListItem>()
|
2021-10-23 20:13:06 +02:00
|
|
|
.map((e) => AlbumFileItem(
|
|
|
|
addedBy: widget.account.username,
|
|
|
|
addedAt: DateTime.now(),
|
|
|
|
file: e.file,
|
|
|
|
))
|
2021-09-08 11:39:24 +02:00
|
|
|
.toList();
|
2021-11-01 10:50:13 +01:00
|
|
|
final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb()));
|
2021-10-23 06:47:32 +02:00
|
|
|
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
2021-11-01 15:43:02 +01:00
|
|
|
await AddToAlbum(albumRepo, shareRepo, AppDb(), Pref())(
|
2021-10-23 06:47:32 +02:00
|
|
|
widget.account, value, selected);
|
2021-10-25 12:46:12 +02:00
|
|
|
if (mounted) {
|
|
|
|
setState(() {
|
|
|
|
clearSelectedItems();
|
|
|
|
});
|
|
|
|
}
|
2021-09-08 11:39:24 +02:00
|
|
|
},
|
|
|
|
null,
|
|
|
|
L10n.global().addSelectedToAlbumSuccessNotification(value.name),
|
|
|
|
failureText: L10n.global().addSelectedToAlbumFailureNotification,
|
|
|
|
)();
|
|
|
|
} catch (e, stackTrace) {
|
2021-09-29 16:55:49 +02:00
|
|
|
_log.shout("[_onSelectionAddToAlbumPressed] Exception", e, stackTrace);
|
2021-09-08 11:39:24 +02:00
|
|
|
}
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 16:55:49 +02:00
|
|
|
void _onSelectionDownloadPressed() {
|
2021-09-28 22:56:44 +02:00
|
|
|
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
|
|
|
Future<void> _onSelectionArchivePressed(BuildContext context) async {
|
2021-09-08 11:39:24 +02:00
|
|
|
final selectedFiles = selectedListItems
|
2021-04-23 09:55:53 +02:00
|
|
|
.whereType<_FileListItem>()
|
2021-09-08 11:39:24 +02:00
|
|
|
.map((e) => e.file)
|
2021-04-10 06:28:12 +02:00
|
|
|
.toList();
|
2021-09-08 11:39:24 +02:00
|
|
|
setState(() {
|
|
|
|
clearSelectedItems();
|
|
|
|
});
|
2021-11-01 10:50:13 +01:00
|
|
|
final fileRepo = FileRepo(FileCachedDataSource(AppDb()));
|
2021-09-08 11:39:24 +02:00
|
|
|
await NotifiedListAction<File>(
|
|
|
|
list: selectedFiles,
|
|
|
|
action: (file) async {
|
|
|
|
await UpdateProperty(fileRepo)
|
|
|
|
.updateIsArchived(widget.account, file, true);
|
|
|
|
},
|
|
|
|
processingText: L10n.global()
|
|
|
|
.archiveSelectedProcessingNotification(selectedFiles.length),
|
|
|
|
successText: L10n.global().archiveSelectedSuccessNotification,
|
|
|
|
getFailureText: (failures) =>
|
|
|
|
L10n.global().archiveSelectedFailureNotification(failures.length),
|
|
|
|
onActionError: (file, e, stackTrace) {
|
|
|
|
_log.shout(
|
2021-09-29 16:55:49 +02:00
|
|
|
"[_onSelectionArchivePressed] Failed while archiving file" +
|
2021-09-08 11:39:24 +02:00
|
|
|
(shouldLogFileName ? ": ${file.path}" : ""),
|
|
|
|
e,
|
|
|
|
stackTrace);
|
|
|
|
},
|
|
|
|
)();
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 16:55:49 +02:00
|
|
|
Future<void> _onSelectionDeletePressed(BuildContext context) async {
|
2021-04-23 09:55:53 +02:00
|
|
|
final selectedFiles = selectedListItems
|
|
|
|
.whereType<_FileListItem>()
|
|
|
|
.map((e) => e.file)
|
|
|
|
.toList();
|
2021-04-10 06:28:12 +02:00
|
|
|
setState(() {
|
2021-04-23 09:55:53 +02:00
|
|
|
clearSelectedItems();
|
2021-04-10 06:28:12 +02:00
|
|
|
});
|
2021-11-01 10:50:13 +01:00
|
|
|
final fileRepo = FileRepo(FileCachedDataSource(AppDb()));
|
|
|
|
final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb()));
|
2021-09-08 11:39:24 +02:00
|
|
|
await NotifiedListAction<File>(
|
|
|
|
list: selectedFiles,
|
|
|
|
action: (file) async {
|
|
|
|
await Remove(fileRepo, albumRepo)(widget.account, file);
|
|
|
|
},
|
|
|
|
processingText: L10n.global()
|
|
|
|
.deleteSelectedProcessingNotification(selectedFiles.length),
|
|
|
|
successText: L10n.global().deleteSelectedSuccessNotification,
|
|
|
|
getFailureText: (failures) =>
|
|
|
|
L10n.global().deleteSelectedFailureNotification(failures.length),
|
|
|
|
onActionError: (file, e, stackTrace) {
|
2021-04-27 22:06:16 +02:00
|
|
|
_log.shout(
|
2021-09-29 16:55:49 +02:00
|
|
|
"[_onSelectionDeletePressed] Failed while removing file" +
|
2021-09-08 11:39:24 +02:00
|
|
|
(shouldLogFileName ? ": ${file.path}" : ""),
|
2021-04-10 06:28:12 +02:00
|
|
|
e,
|
2021-09-08 11:39:24 +02:00
|
|
|
stackTrace);
|
|
|
|
},
|
|
|
|
)();
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
2021-08-15 19:06:00 +02:00
|
|
|
void _onMetadataTaskStateChanged(MetadataTaskStateChangedEvent ev) {
|
2021-09-12 19:30:09 +02:00
|
|
|
if (ev.state == MetadataTaskState.idle) {
|
|
|
|
_metadataTaskProcessCount = 0;
|
|
|
|
}
|
2021-08-15 19:06:00 +02:00
|
|
|
if (ev.state != _metadataTaskState) {
|
|
|
|
setState(() {
|
|
|
|
_metadataTaskState = ev.state;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 12:59:20 +02:00
|
|
|
void _onPrefUpdated(PrefUpdatedEvent ev) {
|
|
|
|
if (ev.key == PrefKey.enableExif && ev.value == true) {
|
|
|
|
_tryStartMetadataTask(ignoreFired: true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 19:30:09 +02:00
|
|
|
void _onFilePropertyUpdated(FilePropertyUpdatedEvent ev) {
|
|
|
|
if (!ev.hasAnyProperties([FilePropertyUpdatedEvent.propMetadata])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setState(() {
|
|
|
|
++_metadataTaskProcessCount;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-12 12:59:20 +02:00
|
|
|
void _tryStartMetadataTask({
|
|
|
|
bool ignoreFired = false,
|
|
|
|
}) {
|
2021-11-16 21:02:24 +01:00
|
|
|
if (_bloc.state is ScanAccountDirBlocSuccess &&
|
2021-10-27 22:40:54 +02:00
|
|
|
Pref().isEnableExifOr() &&
|
2021-09-12 12:59:20 +02:00
|
|
|
(!_hasFiredMetadataTask.value || ignoreFired)) {
|
|
|
|
MetadataTaskManager().addTask(MetadataTask(widget.account));
|
2021-09-12 19:30:09 +02:00
|
|
|
_metadataTaskProcessTotalCount = _backingFiles
|
2021-10-27 19:23:03 +02:00
|
|
|
.where(
|
|
|
|
(f) => file_util.isSupportedImageFormat(f) && f.metadata == null)
|
2021-09-12 19:30:09 +02:00
|
|
|
.length;
|
2021-09-12 12:59:20 +02:00
|
|
|
_hasFiredMetadataTask.value = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-10 06:28:12 +02:00
|
|
|
/// Transform a File list to grid items
|
|
|
|
void _transformItems(List<File> files) {
|
|
|
|
_backingFiles = files
|
2021-05-28 20:45:00 +02:00
|
|
|
.where((element) =>
|
|
|
|
file_util.isSupportedFormat(element) && element.isArchived != true)
|
2021-04-10 06:28:12 +02:00
|
|
|
.sorted(compareFileDateTimeDescending);
|
|
|
|
|
2021-06-27 07:18:13 +02:00
|
|
|
final isMonthOnly = _thumbZoomLevel < 0;
|
2021-10-04 15:53:03 +02:00
|
|
|
final dateHelper = PhotoListDateGroupHelper(
|
|
|
|
isMonthOnly: isMonthOnly,
|
|
|
|
);
|
2021-04-23 09:55:53 +02:00
|
|
|
itemStreamListItems = () sync* {
|
|
|
|
for (int i = 0; i < _backingFiles.length; ++i) {
|
|
|
|
final f = _backingFiles[i];
|
2021-10-04 15:53:03 +02:00
|
|
|
final date = dateHelper.onFile(f);
|
|
|
|
if (date != null) {
|
|
|
|
yield _DateListItem(date: date, isMonthOnly: isMonthOnly);
|
2021-04-23 09:55:53 +02:00
|
|
|
}
|
2021-04-28 14:55:26 +02:00
|
|
|
|
2021-05-05 22:03:39 +02:00
|
|
|
final previewUrl = api_util.getFilePreviewUrl(widget.account, f,
|
2021-09-16 12:25:08 +02:00
|
|
|
width: k.photoThumbSize, height: k.photoThumbSize);
|
2021-05-06 13:36:20 +02:00
|
|
|
if (file_util.isSupportedImageFormat(f)) {
|
|
|
|
yield _ImageListItem(
|
|
|
|
file: f,
|
|
|
|
account: widget.account,
|
|
|
|
previewUrl: previewUrl,
|
|
|
|
onTap: () => _onItemTap(i),
|
|
|
|
);
|
|
|
|
} else if (file_util.isSupportedVideoFormat(f)) {
|
|
|
|
yield _VideoListItem(
|
|
|
|
file: f,
|
|
|
|
account: widget.account,
|
|
|
|
previewUrl: previewUrl,
|
|
|
|
onTap: () => _onItemTap(i),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
_log.shout(
|
|
|
|
"[_transformItems] Unsupported file format: ${f.contentType}");
|
|
|
|
}
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
2021-07-07 20:51:34 +02:00
|
|
|
}()
|
|
|
|
.toList();
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
2021-04-11 11:52:39 +02:00
|
|
|
void _reqQuery() {
|
2021-11-16 21:02:24 +01:00
|
|
|
_bloc.add(const ScanAccountDirBlocQuery());
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 11:54:11 +02:00
|
|
|
void _reqRefresh() {
|
2021-11-16 21:02:24 +01:00
|
|
|
_bloc.add(const ScanAccountDirBlocRefresh());
|
2021-04-27 11:54:11 +02:00
|
|
|
}
|
|
|
|
|
2021-04-28 14:55:26 +02:00
|
|
|
void _setThumbZoomLevel(int level) {
|
|
|
|
final prevLevel = _thumbZoomLevel;
|
|
|
|
_thumbZoomLevel = level;
|
|
|
|
if ((prevLevel >= 0) != (level >= 0)) {
|
|
|
|
_transformItems(_backingFiles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 21:11:06 +02:00
|
|
|
/// Return the estimated scroll extent of the custom scroll view, or null
|
2021-07-23 22:05:57 +02:00
|
|
|
double? _getScrollViewExtent(BoxConstraints constraints) {
|
2021-07-06 07:10:36 +02:00
|
|
|
if (_itemListMaxExtent != null &&
|
2021-05-19 21:11:06 +02:00
|
|
|
constraints.hasBoundedHeight &&
|
|
|
|
_appBarExtent != null) {
|
2021-08-15 19:06:00 +02:00
|
|
|
final metadataTaskHeaderExtent =
|
|
|
|
_metadataTaskState == MetadataTaskState.idle
|
|
|
|
? 0
|
|
|
|
: _metadataTaskHeaderHeight;
|
|
|
|
// scroll extent = list height - widget viewport height + sliver app bar height + metadata task header height + list padding
|
|
|
|
final scrollExtent = _itemListMaxExtent! -
|
|
|
|
constraints.maxHeight +
|
|
|
|
_appBarExtent! +
|
|
|
|
metadataTaskHeaderExtent +
|
|
|
|
16;
|
2021-05-19 21:11:06 +02:00
|
|
|
_log.info(
|
2021-08-15 19:06:00 +02:00
|
|
|
"[_getScrollViewExtent] $_itemListMaxExtent - ${constraints.maxHeight} + $_appBarExtent + $metadataTaskHeaderExtent + 16 = $scrollExtent");
|
2021-05-19 21:11:06 +02:00
|
|
|
return scrollExtent;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 19:30:09 +02:00
|
|
|
String _getMetadataTaskProgressString() {
|
|
|
|
if (_metadataTaskProcessTotalCount == 0) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
final clippedCount =
|
|
|
|
math.min(_metadataTaskProcessCount, _metadataTaskProcessTotalCount - 1);
|
|
|
|
return " ($clippedCount/$_metadataTaskProcessTotalCount)";
|
|
|
|
}
|
|
|
|
|
2021-04-10 06:28:12 +02:00
|
|
|
int get _thumbSize {
|
|
|
|
switch (_thumbZoomLevel) {
|
2021-04-28 14:55:26 +02:00
|
|
|
case -1:
|
|
|
|
return 96;
|
|
|
|
|
2021-04-10 06:28:12 +02:00
|
|
|
case 1:
|
|
|
|
return 176;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
return 256;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
return 112;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-25 15:59:27 +02:00
|
|
|
Primitive<bool> get _hasFiredMetadataTask {
|
|
|
|
final blocId =
|
|
|
|
"${widget.account.scheme}://${widget.account.username}@${widget.account.address}";
|
|
|
|
try {
|
|
|
|
_log.fine("[_hasFiredMetadataTask] Resolving bloc for '$blocId'");
|
|
|
|
return KiwiContainer().resolve<Primitive<bool>>(
|
|
|
|
"HomePhotosState.hasFiredMetadataTask($blocId)");
|
|
|
|
} catch (_) {
|
|
|
|
_log.info(
|
|
|
|
"[_hasFiredMetadataTask] New bloc instance for account: ${widget.account}");
|
|
|
|
final obj = Primitive(false);
|
|
|
|
KiwiContainer().registerInstance<Primitive<bool>>(obj,
|
|
|
|
name: "HomePhotosState.hasFiredMetadataTask($blocId)");
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 21:02:24 +01:00
|
|
|
late final _bloc = ScanAccountDirBloc.of(widget.account);
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
var _backingFiles = <File>[];
|
|
|
|
|
|
|
|
var _thumbZoomLevel = 0;
|
|
|
|
|
2021-05-19 21:11:06 +02:00
|
|
|
final ScrollController _scrollController = ScrollController();
|
|
|
|
|
2021-07-23 22:05:57 +02:00
|
|
|
double? _appBarExtent;
|
|
|
|
double? _itemListMaxExtent;
|
2021-05-19 21:11:06 +02:00
|
|
|
|
2021-08-15 19:06:00 +02:00
|
|
|
late final _metadataTaskStateChangedListener =
|
|
|
|
AppEventListener<MetadataTaskStateChangedEvent>(
|
|
|
|
_onMetadataTaskStateChanged);
|
|
|
|
var _metadataTaskState = MetadataTaskManager().state;
|
2021-09-12 12:59:20 +02:00
|
|
|
late final _prefUpdatedListener =
|
|
|
|
AppEventListener<PrefUpdatedEvent>(_onPrefUpdated);
|
2021-09-12 19:30:09 +02:00
|
|
|
late final _filePropertyUpdatedListener =
|
|
|
|
AppEventListener<FilePropertyUpdatedEvent>(_onFilePropertyUpdated);
|
|
|
|
var _metadataTaskProcessCount = 0;
|
|
|
|
var _metadataTaskProcessTotalCount = 0;
|
2021-08-15 19:06:00 +02:00
|
|
|
late final _metadataTaskIconController = AnimationController(
|
|
|
|
upperBound: 2 * math.pi,
|
|
|
|
duration: const Duration(seconds: 10),
|
|
|
|
vsync: this,
|
|
|
|
)..repeat();
|
|
|
|
|
2021-04-10 06:28:12 +02:00
|
|
|
static final _log = Logger("widget.home_photos._HomePhotosState");
|
2021-04-11 11:57:08 +02:00
|
|
|
static const _menuValueRefresh = 0;
|
2021-08-15 19:06:00 +02:00
|
|
|
|
|
|
|
static const _metadataTaskHeaderHeight = 32.0;
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
2021-07-06 15:03:29 +02:00
|
|
|
abstract class _ListItem implements SelectableItem {
|
|
|
|
_ListItem({
|
2021-07-23 22:05:57 +02:00
|
|
|
VoidCallback? onTap,
|
2021-07-06 15:03:29 +02:00
|
|
|
}) : _onTap = onTap;
|
|
|
|
|
|
|
|
@override
|
|
|
|
get onTap => _onTap;
|
|
|
|
|
|
|
|
@override
|
|
|
|
get isSelectable => true;
|
|
|
|
|
|
|
|
@override
|
|
|
|
get staggeredTile => const StaggeredTile.count(1, 1);
|
|
|
|
|
2021-07-23 22:05:57 +02:00
|
|
|
final VoidCallback? _onTap;
|
2021-07-06 15:03:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class _DateListItem extends _ListItem {
|
2021-06-27 07:18:13 +02:00
|
|
|
_DateListItem({
|
2021-07-23 22:05:57 +02:00
|
|
|
required this.date,
|
2021-06-27 07:18:13 +02:00
|
|
|
this.isMonthOnly = false,
|
2021-07-06 15:03:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
get isSelectable => false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
get staggeredTile => const StaggeredTile.extent(99, 32);
|
2021-04-10 06:28:12 +02:00
|
|
|
|
2021-04-23 09:55:53 +02:00
|
|
|
@override
|
|
|
|
buildWidget(BuildContext context) {
|
2021-10-04 15:53:03 +02:00
|
|
|
return PhotoListDate(
|
|
|
|
date: date,
|
|
|
|
isMonthOnly: isMonthOnly,
|
2021-04-23 09:55:53 +02:00
|
|
|
);
|
|
|
|
}
|
2021-04-10 06:28:12 +02:00
|
|
|
|
2021-10-04 15:53:03 +02:00
|
|
|
final DateTime date;
|
2021-06-27 07:18:13 +02:00
|
|
|
final bool isMonthOnly;
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
2021-07-06 15:03:29 +02:00
|
|
|
abstract class _FileListItem extends _ListItem {
|
2021-04-23 09:55:53 +02:00
|
|
|
_FileListItem({
|
2021-07-23 22:05:57 +02:00
|
|
|
required this.file,
|
|
|
|
VoidCallback? onTap,
|
2021-07-06 15:03:29 +02:00
|
|
|
}) : super(onTap: onTap);
|
2021-04-10 06:28:12 +02:00
|
|
|
|
2021-04-23 09:55:53 +02:00
|
|
|
@override
|
|
|
|
operator ==(Object other) {
|
|
|
|
return other is _FileListItem && file.path == other.file.path;
|
|
|
|
}
|
2021-04-10 06:28:12 +02:00
|
|
|
|
2021-04-23 09:55:53 +02:00
|
|
|
@override
|
|
|
|
get hashCode => file.path.hashCode;
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
final File file;
|
|
|
|
}
|
|
|
|
|
2021-04-23 09:55:53 +02:00
|
|
|
class _ImageListItem extends _FileListItem {
|
|
|
|
_ImageListItem({
|
2021-07-23 22:05:57 +02:00
|
|
|
required File file,
|
|
|
|
required this.account,
|
|
|
|
required this.previewUrl,
|
|
|
|
VoidCallback? onTap,
|
2021-04-23 09:55:53 +02:00
|
|
|
}) : super(file: file, onTap: onTap);
|
|
|
|
|
|
|
|
@override
|
|
|
|
buildWidget(BuildContext context) {
|
2021-05-06 13:29:20 +02:00
|
|
|
return PhotoListImage(
|
|
|
|
account: account,
|
|
|
|
previewUrl: previewUrl,
|
2021-06-22 07:24:37 +02:00
|
|
|
isGif: file.contentType == "image/gif",
|
2021-04-23 09:55:53 +02:00
|
|
|
);
|
|
|
|
}
|
2021-04-10 06:28:12 +02:00
|
|
|
|
2021-04-23 09:55:53 +02:00
|
|
|
final Account account;
|
2021-04-10 06:28:12 +02:00
|
|
|
final String previewUrl;
|
|
|
|
}
|
|
|
|
|
2021-05-06 13:36:20 +02:00
|
|
|
class _VideoListItem extends _FileListItem {
|
|
|
|
_VideoListItem({
|
2021-07-23 22:05:57 +02:00
|
|
|
required File file,
|
|
|
|
required this.account,
|
|
|
|
required this.previewUrl,
|
|
|
|
VoidCallback? onTap,
|
2021-05-06 13:36:20 +02:00
|
|
|
}) : super(file: file, onTap: onTap);
|
|
|
|
|
|
|
|
@override
|
|
|
|
buildWidget(BuildContext context) {
|
|
|
|
return PhotoListVideo(
|
|
|
|
account: account,
|
|
|
|
previewUrl: previewUrl,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final String previewUrl;
|
|
|
|
}
|
|
|
|
|
2021-08-15 19:06:00 +02:00
|
|
|
class _MetadataTaskHeaderDelegate extends SliverPersistentHeaderDelegate {
|
|
|
|
const _MetadataTaskHeaderDelegate({
|
|
|
|
required this.extent,
|
|
|
|
required this.builder,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context, double shrinkOffset, bool overlapsContent) {
|
|
|
|
return builder(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
get maxExtent => extent;
|
|
|
|
|
|
|
|
@override
|
|
|
|
get minExtent => maxExtent;
|
|
|
|
|
|
|
|
@override
|
|
|
|
shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) => true;
|
|
|
|
|
|
|
|
final double extent;
|
|
|
|
final Widget Function(BuildContext context) builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MetadataTaskLoadingIcon extends AnimatedWidget {
|
|
|
|
const _MetadataTaskLoadingIcon({
|
|
|
|
Key? key,
|
|
|
|
required AnimationController controller,
|
|
|
|
}) : super(key: key, listenable: controller);
|
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context) {
|
|
|
|
return Transform.rotate(
|
|
|
|
angle: -_progress.value,
|
|
|
|
child: const Icon(
|
|
|
|
Icons.sync,
|
|
|
|
size: 16,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Animation<double> get _progress => listenable as Animation<double>;
|
|
|
|
}
|
|
|
|
|
2021-09-08 11:39:24 +02:00
|
|
|
enum _SelectionMenuOption {
|
2021-05-28 21:44:09 +02:00
|
|
|
archive,
|
2021-07-10 17:06:04 +02:00
|
|
|
delete,
|
2021-09-28 22:56:44 +02:00
|
|
|
download,
|
2021-05-28 21:44:09 +02:00
|
|
|
}
|