2022-04-23 19:08:45 -07:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-07-07 11:40:54 -07:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-04-23 19:08:45 -07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-08-02 22:04:34 -07:00
|
|
|
import 'package:immich_mobile/modules/album/models/asset_selection_page_result.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/providers/asset_selection.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/ui/asset_grid_by_month.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/ui/month_group_title.dart';
|
2022-04-23 19:08:45 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/ui/draggable_scrollbar.dart';
|
|
|
|
|
|
|
|
class AssetSelectionPage extends HookConsumerWidget {
|
|
|
|
const AssetSelectionPage({Key? key}) : super(key: key);
|
2022-08-02 22:04:34 -07:00
|
|
|
|
2022-04-23 19:08:45 -07:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-06-21 22:23:35 -07:00
|
|
|
ScrollController scrollController = useScrollController();
|
2022-04-23 19:08:45 -07:00
|
|
|
var assetGroupMonthYear = ref.watch(assetGroupByMonthYearProvider);
|
2022-06-21 22:23:35 -07:00
|
|
|
final selectedAssets =
|
|
|
|
ref.watch(assetSelectionProvider).selectedNewAssetsForAlbum;
|
|
|
|
final newAssetsForAlbum =
|
|
|
|
ref.watch(assetSelectionProvider).selectedAdditionalAssetsForAlbum;
|
2022-04-23 19:08:45 -07:00
|
|
|
final isAlbumExist = ref.watch(assetSelectionProvider).isAlbumExist;
|
|
|
|
|
2022-06-21 22:23:35 -07:00
|
|
|
List<Widget> imageGridGroup = [];
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
String _buildAssetCountText() {
|
|
|
|
if (isAlbumExist) {
|
|
|
|
return (selectedAssets.length + newAssetsForAlbum.length).toString();
|
|
|
|
} else {
|
|
|
|
return selectedAssets.length.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildBody() {
|
|
|
|
assetGroupMonthYear.forEach((monthYear, assetGroup) {
|
2022-06-21 22:23:35 -07:00
|
|
|
imageGridGroup
|
|
|
|
.add(MonthGroupTitle(month: monthYear, assetGroup: assetGroup));
|
|
|
|
imageGridGroup.add(AssetGridByMonth(assetGroup: assetGroup));
|
2022-04-23 19:08:45 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
DraggableScrollbar.semicircle(
|
|
|
|
backgroundColor: Theme.of(context).primaryColor,
|
2022-06-21 22:23:35 -07:00
|
|
|
controller: scrollController,
|
2022-04-23 19:08:45 -07:00
|
|
|
heightScrollThumb: 48.0,
|
|
|
|
child: CustomScrollView(
|
2022-06-21 22:23:35 -07:00
|
|
|
controller: scrollController,
|
|
|
|
slivers: [...imageGridGroup],
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
elevation: 0,
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.close_rounded),
|
|
|
|
onPressed: () {
|
|
|
|
ref.watch(assetSelectionProvider.notifier).removeAll();
|
|
|
|
AutoRouter.of(context).pop(null);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
title: selectedAssets.isEmpty
|
|
|
|
? const Text(
|
2022-07-07 11:40:54 -07:00
|
|
|
'share_add_photos',
|
2022-04-23 19:08:45 -07:00
|
|
|
style: TextStyle(fontSize: 18),
|
2022-07-07 11:40:54 -07:00
|
|
|
).tr()
|
2022-04-23 19:08:45 -07:00
|
|
|
: Text(
|
|
|
|
_buildAssetCountText(),
|
|
|
|
style: const TextStyle(fontSize: 18),
|
|
|
|
),
|
|
|
|
centerTitle: false,
|
|
|
|
actions: [
|
2022-06-30 18:08:49 -07:00
|
|
|
if ((!isAlbumExist && selectedAssets.isNotEmpty) ||
|
|
|
|
(isAlbumExist && newAssetsForAlbum.isNotEmpty))
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
var payload = AssetSelectionPageResult(
|
|
|
|
isAlbumExist: isAlbumExist,
|
|
|
|
selectedAdditionalAsset: newAssetsForAlbum,
|
|
|
|
selectedNewAsset: selectedAssets,
|
|
|
|
);
|
|
|
|
AutoRouter.of(context).pop(payload);
|
|
|
|
},
|
|
|
|
child: const Text(
|
2022-07-07 11:40:54 -07:00
|
|
|
"share_add",
|
2022-06-30 18:08:49 -07:00
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
2022-07-07 11:40:54 -07:00
|
|
|
).tr(),
|
2022-06-30 18:08:49 -07:00
|
|
|
),
|
2022-04-23 19:08:45 -07:00
|
|
|
],
|
|
|
|
),
|
|
|
|
body: _buildBody(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|