2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-04-29 06:46:37 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-09 17:19:53 +01:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2024-05-02 22:59:14 +02:00
|
|
|
import 'package:immich_mobile/providers/album/album_viewer.provider.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/entities/album.entity.dart';
|
2022-04-29 06:46:37 +02:00
|
|
|
|
|
|
|
class AlbumViewerEditableTitle extends HookConsumerWidget {
|
2023-02-06 08:13:32 +01:00
|
|
|
final Album album;
|
2022-04-29 06:46:37 +02:00
|
|
|
final FocusNode titleFocusNode;
|
2022-07-13 14:23:48 +02:00
|
|
|
const AlbumViewerEditableTitle({
|
2024-01-27 17:14:32 +01:00
|
|
|
super.key,
|
2023-02-06 08:13:32 +01:00
|
|
|
required this.album,
|
2022-07-13 14:23:48 +02:00
|
|
|
required this.titleFocusNode,
|
2024-01-27 17:14:32 +01:00
|
|
|
});
|
2022-04-29 06:46:37 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-02-06 08:13:32 +01:00
|
|
|
final titleTextEditController = useTextEditingController(text: album.name);
|
2022-04-29 06:46:37 +02:00
|
|
|
|
|
|
|
void onFocusModeChange() {
|
|
|
|
if (!titleFocusNode.hasFocus && titleTextEditController.text.isEmpty) {
|
|
|
|
ref.watch(albumViewerProvider.notifier).setEditTitleText("Untitled");
|
|
|
|
titleTextEditController.text = "Untitled";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
titleFocusNode.addListener(onFocusModeChange);
|
|
|
|
return () {
|
|
|
|
titleFocusNode.removeListener(onFocusModeChange);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-04-29 06:46:37 +02:00
|
|
|
|
2024-05-27 02:13:32 +02:00
|
|
|
return Material(
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (value) {
|
|
|
|
if (value.isEmpty) {
|
|
|
|
} else {
|
|
|
|
ref.watch(albumViewerProvider.notifier).setEditTitleText(value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
focusNode: titleFocusNode,
|
|
|
|
style: context.textTheme.headlineMedium,
|
|
|
|
controller: titleTextEditController,
|
|
|
|
onTap: () {
|
|
|
|
FocusScope.of(context).requestFocus(titleFocusNode);
|
2022-04-29 06:46:37 +02:00
|
|
|
|
2024-05-27 02:13:32 +02:00
|
|
|
ref.watch(albumViewerProvider.notifier).setEditTitleText(album.name);
|
|
|
|
ref.watch(albumViewerProvider.notifier).enableEditAlbum();
|
2022-04-29 06:46:37 +02:00
|
|
|
|
2024-05-27 02:13:32 +02:00
|
|
|
if (titleTextEditController.text == 'Untitled') {
|
|
|
|
titleTextEditController.clear();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
contentPadding:
|
|
|
|
const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
|
|
|
suffixIcon: titleFocusNode.hasFocus
|
|
|
|
? IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
titleTextEditController.clear();
|
|
|
|
},
|
|
|
|
icon: Icon(
|
|
|
|
Icons.cancel_rounded,
|
|
|
|
color: context.primaryColor,
|
|
|
|
),
|
|
|
|
splashRadius: 10,
|
|
|
|
)
|
|
|
|
: null,
|
2024-08-06 16:20:27 +02:00
|
|
|
enabledBorder: const OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: Colors.transparent),
|
2024-05-27 02:13:32 +02:00
|
|
|
),
|
2024-08-06 16:20:27 +02:00
|
|
|
focusedBorder: const OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: Colors.transparent),
|
2024-05-27 02:13:32 +02:00
|
|
|
),
|
|
|
|
focusColor: Colors.grey[300],
|
2024-08-06 16:20:27 +02:00
|
|
|
fillColor: context.scaffoldBackgroundColor,
|
2024-05-27 02:13:32 +02:00
|
|
|
filled: titleFocusNode.hasFocus,
|
|
|
|
hintText: 'share_add_title'.tr(),
|
2024-08-06 16:20:27 +02:00
|
|
|
hintStyle: context.themeData.inputDecorationTheme.hintStyle?.copyWith(
|
2024-05-27 02:13:32 +02:00
|
|
|
fontSize: 28,
|
|
|
|
),
|
2023-08-18 06:26:12 +02:00
|
|
|
),
|
2022-04-29 06:46:37 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|