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/album.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/providers/album_title.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/providers/asset_selection.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/ui/album_action_outlined_button.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/ui/album_title_text_field.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/ui/shared_album_thumbnail_image.dart';
|
2022-04-23 19:08:45 -07:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
|
|
|
|
2022-08-02 22:04:34 -07:00
|
|
|
// ignore: must_be_immutable
|
|
|
|
class CreateAlbumPage extends HookConsumerWidget {
|
|
|
|
bool isSharedAlbum;
|
|
|
|
|
|
|
|
CreateAlbumPage({Key? key, required this.isSharedAlbum}) : super(key: key);
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-06-21 22:23:35 -07:00
|
|
|
final albumTitleController =
|
|
|
|
useTextEditingController.fromValue(TextEditingValue.empty);
|
2022-04-23 19:08:45 -07:00
|
|
|
final albumTitleTextFieldFocusNode = useFocusNode();
|
|
|
|
final isAlbumTitleTextFieldFocus = useState(false);
|
|
|
|
final isAlbumTitleEmpty = useState(true);
|
2022-06-21 22:23:35 -07:00
|
|
|
final selectedAssets =
|
|
|
|
ref.watch(assetSelectionProvider).selectedNewAssetsForAlbum;
|
2022-08-15 16:53:30 -07:00
|
|
|
final isDarkTheme = Theme.of(context).brightness == Brightness.dark;
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
_showSelectUserPage() {
|
|
|
|
AutoRouter.of(context).push(const SelectUserForSharingRoute());
|
|
|
|
}
|
|
|
|
|
|
|
|
void _onBackgroundTapped() {
|
|
|
|
albumTitleTextFieldFocusNode.unfocus();
|
|
|
|
isAlbumTitleTextFieldFocus.value = false;
|
|
|
|
|
|
|
|
if (albumTitleController.text.isEmpty) {
|
2022-08-08 06:11:56 -07:00
|
|
|
albumTitleController.text = 'create_album_page_untitled'.tr();
|
|
|
|
ref
|
|
|
|
.watch(albumTitleProvider.notifier)
|
|
|
|
.setAlbumTitle('create_album_page_untitled'.tr());
|
2022-04-23 19:08:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onSelectPhotosButtonPressed() async {
|
|
|
|
ref.watch(assetSelectionProvider.notifier).setIsAlbumExist(false);
|
|
|
|
|
2022-06-21 22:23:35 -07:00
|
|
|
AssetSelectionPageResult? selectedAsset = await AutoRouter.of(context)
|
|
|
|
.push<AssetSelectionPageResult?>(const AssetSelectionRoute());
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
if (selectedAsset == null) {
|
|
|
|
ref.watch(assetSelectionProvider.notifier).removeAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_buildTitleInputField() {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
right: 10,
|
|
|
|
left: 10,
|
|
|
|
),
|
|
|
|
child: AlbumTitleTextField(
|
2022-07-13 05:23:48 -07:00
|
|
|
isAlbumTitleEmpty: isAlbumTitleEmpty,
|
|
|
|
albumTitleTextFieldFocusNode: albumTitleTextFieldFocusNode,
|
|
|
|
albumTitleController: albumTitleController,
|
|
|
|
isAlbumTitleTextFieldFocus: isAlbumTitleTextFieldFocus,
|
|
|
|
),
|
2022-04-23 19:08:45 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_buildTitle() {
|
|
|
|
if (selectedAssets.isEmpty) {
|
2022-07-07 11:40:54 -07:00
|
|
|
return SliverToBoxAdapter(
|
2022-04-23 19:08:45 -07:00
|
|
|
child: Padding(
|
2022-07-13 05:23:48 -07:00
|
|
|
padding: const EdgeInsets.only(top: 200, left: 18),
|
2022-08-15 16:53:30 -07:00
|
|
|
child: Text(
|
2022-07-07 11:40:54 -07:00
|
|
|
'create_shared_album_page_share_add_assets',
|
2022-08-15 16:53:30 -07:00
|
|
|
style: Theme.of(context).textTheme.headline2?.copyWith(
|
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
),
|
2022-07-07 11:40:54 -07:00
|
|
|
).tr(),
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return const SliverToBoxAdapter();
|
|
|
|
}
|
|
|
|
|
|
|
|
_buildSelectPhotosButton() {
|
|
|
|
if (selectedAssets.isEmpty) {
|
|
|
|
return SliverToBoxAdapter(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 16, left: 18, right: 18),
|
|
|
|
child: OutlinedButton.icon(
|
2022-05-29 15:32:30 -07:00
|
|
|
style: OutlinedButton.styleFrom(
|
2022-07-13 05:23:48 -07:00
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 22, horizontal: 16),
|
2022-08-15 16:53:30 -07:00
|
|
|
side: BorderSide(
|
|
|
|
color: isDarkTheme
|
|
|
|
? const Color.fromARGB(255, 63, 63, 63)
|
|
|
|
: const Color.fromARGB(255, 206, 206, 206),
|
2022-07-13 05:23:48 -07:00
|
|
|
),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
),
|
|
|
|
),
|
2022-04-23 19:08:45 -07:00
|
|
|
onPressed: _onSelectPhotosButtonPressed,
|
2022-08-15 16:53:30 -07:00
|
|
|
icon: Icon(
|
|
|
|
Icons.add_rounded,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
2022-04-23 19:08:45 -07:00
|
|
|
label: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
|
|
child: Text(
|
2022-07-07 11:40:54 -07:00
|
|
|
'create_shared_album_page_share_select_photos',
|
2022-08-15 16:53:30 -07:00
|
|
|
style: Theme.of(context).textTheme.labelLarge?.copyWith(
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-07-07 11:40:54 -07:00
|
|
|
).tr(),
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return const SliverToBoxAdapter();
|
|
|
|
}
|
|
|
|
|
|
|
|
_buildControlButton() {
|
2022-06-30 18:08:49 -07:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 12.0, top: 16, bottom: 16),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 30,
|
|
|
|
child: ListView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
children: [
|
|
|
|
AlbumActionOutlinedButton(
|
|
|
|
iconData: Icons.add_photo_alternate_outlined,
|
|
|
|
onPressed: _onSelectPhotosButtonPressed,
|
2022-07-07 11:40:54 -07:00
|
|
|
labelText: "share_add_photos".tr(),
|
2022-06-30 18:08:49 -07:00
|
|
|
),
|
|
|
|
],
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
2022-06-30 18:08:49 -07:00
|
|
|
),
|
|
|
|
);
|
2022-04-23 19:08:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_buildSelectedImageGrid() {
|
|
|
|
if (selectedAssets.isNotEmpty) {
|
|
|
|
return SliverPadding(
|
|
|
|
padding: const EdgeInsets.only(top: 16),
|
|
|
|
sliver: SliverGrid(
|
|
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
|
|
crossAxisCount: 3,
|
|
|
|
crossAxisSpacing: 5.0,
|
|
|
|
mainAxisSpacing: 5,
|
|
|
|
),
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
(BuildContext context, int index) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: _onBackgroundTapped,
|
2022-06-21 22:23:35 -07:00
|
|
|
child: SharedAlbumThumbnailImage(
|
2022-07-13 05:23:48 -07:00
|
|
|
asset: selectedAssets.toList()[index],
|
|
|
|
),
|
2022-04-23 19:08:45 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
childCount: selectedAssets.length,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return const SliverToBoxAdapter();
|
|
|
|
}
|
|
|
|
|
2022-08-02 22:04:34 -07:00
|
|
|
_createNonSharedAlbum() async {
|
|
|
|
var newAlbum = await ref.watch(albumProvider.notifier).createAlbum(
|
|
|
|
ref.watch(albumTitleProvider),
|
|
|
|
ref.watch(assetSelectionProvider).selectedNewAssetsForAlbum,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (newAlbum != null) {
|
|
|
|
ref.watch(albumProvider.notifier).getAllAlbums();
|
|
|
|
ref.watch(assetSelectionProvider.notifier).removeAll();
|
|
|
|
ref.watch(albumTitleProvider.notifier).clearAlbumTitle();
|
|
|
|
|
|
|
|
AutoRouter.of(context).replace(AlbumViewerRoute(albumId: newAlbum.id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 19:08:45 -07:00
|
|
|
return Scaffold(
|
2022-07-13 05:23:48 -07:00
|
|
|
appBar: AppBar(
|
|
|
|
elevation: 0,
|
|
|
|
centerTitle: false,
|
2022-08-15 16:53:30 -07:00
|
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
2022-07-13 05:23:48 -07:00
|
|
|
leading: IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
ref.watch(assetSelectionProvider.notifier).removeAll();
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.close_rounded),
|
|
|
|
),
|
2022-08-15 16:53:30 -07:00
|
|
|
title: Text(
|
2022-07-13 05:23:48 -07:00
|
|
|
'share_create_album',
|
2022-08-15 16:53:30 -07:00
|
|
|
style: Theme.of(context).textTheme.headline2?.copyWith(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
2022-07-13 05:23:48 -07:00
|
|
|
).tr(),
|
|
|
|
actions: [
|
2022-08-02 22:04:34 -07:00
|
|
|
if (isSharedAlbum)
|
|
|
|
TextButton(
|
|
|
|
onPressed: albumTitleController.text.isNotEmpty
|
|
|
|
? _showSelectUserPage
|
|
|
|
: null,
|
|
|
|
child: Text(
|
|
|
|
'create_shared_album_page_share'.tr(),
|
2022-08-15 16:53:30 -07:00
|
|
|
style: TextStyle(
|
2022-08-02 22:04:34 -07:00
|
|
|
fontWeight: FontWeight.bold,
|
2022-08-15 16:53:30 -07:00
|
|
|
color: Theme.of(context).primaryColor,
|
2022-08-02 22:04:34 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (!isSharedAlbum)
|
|
|
|
TextButton(
|
|
|
|
onPressed: albumTitleController.text.isNotEmpty &&
|
|
|
|
selectedAssets.isNotEmpty
|
|
|
|
? _createNonSharedAlbum
|
|
|
|
: null,
|
|
|
|
child: Text(
|
|
|
|
'create_shared_album_page_create'.tr(),
|
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-07-13 05:23:48 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: GestureDetector(
|
|
|
|
onTap: _onBackgroundTapped,
|
|
|
|
child: CustomScrollView(
|
|
|
|
slivers: [
|
|
|
|
SliverAppBar(
|
2022-08-15 16:53:30 -07:00
|
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
2022-07-13 05:23:48 -07:00
|
|
|
elevation: 5,
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
pinned: true,
|
|
|
|
floating: false,
|
|
|
|
bottom: PreferredSize(
|
|
|
|
preferredSize: const Size.fromHeight(66.0),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
_buildTitleInputField(),
|
|
|
|
if (selectedAssets.isNotEmpty) _buildControlButton(),
|
|
|
|
],
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-07-13 05:23:48 -07:00
|
|
|
_buildTitle(),
|
|
|
|
_buildSelectPhotosButton(),
|
|
|
|
_buildSelectedImageGrid(),
|
2022-04-23 19:08:45 -07:00
|
|
|
],
|
|
|
|
),
|
2022-07-13 05:23:48 -07:00
|
|
|
),
|
|
|
|
);
|
2022-04-23 19:08:45 -07:00
|
|
|
}
|
|
|
|
}
|