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 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/album_viewer.provider.dart';
|
2023-02-06 09:13:32 +02:00
|
|
|
import 'package:immich_mobile/shared/models/album.dart';
|
2022-04-29 06:46:37 +02:00
|
|
|
|
|
|
|
class AlbumViewerEditableTitle extends HookConsumerWidget {
|
2023-02-06 09:13:32 +02: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 18:14:32 +02:00
|
|
|
super.key,
|
2023-02-06 09:13:32 +02:00
|
|
|
required this.album,
|
2022-07-13 14:23:48 +02:00
|
|
|
required this.titleFocusNode,
|
2024-01-27 18:14:32 +02:00
|
|
|
});
|
2022-04-29 06:46:37 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-02-06 09:13:32 +02: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
|
|
|
|
|
|
|
return TextField(
|
|
|
|
onChanged: (value) {
|
|
|
|
if (value.isEmpty) {
|
|
|
|
} else {
|
|
|
|
ref.watch(albumViewerProvider.notifier).setEditTitleText(value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
focusNode: titleFocusNode,
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.headlineMedium,
|
2022-04-29 06:46:37 +02:00
|
|
|
controller: titleTextEditController,
|
|
|
|
onTap: () {
|
|
|
|
FocusScope.of(context).requestFocus(titleFocusNode);
|
|
|
|
|
2023-02-06 09:13:32 +02:00
|
|
|
ref.watch(albumViewerProvider.notifier).setEditTitleText(album.name);
|
2022-04-29 06:46:37 +02:00
|
|
|
ref.watch(albumViewerProvider.notifier).enableEditAlbum();
|
|
|
|
|
|
|
|
if (titleTextEditController.text == 'Untitled') {
|
|
|
|
titleTextEditController.clear();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
|
|
|
suffixIcon: titleFocusNode.hasFocus
|
|
|
|
? IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
titleTextEditController.clear();
|
|
|
|
},
|
2022-08-16 01:53:30 +02:00
|
|
|
icon: Icon(
|
|
|
|
Icons.cancel_rounded,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2022-08-16 01:53:30 +02:00
|
|
|
),
|
2022-04-29 06:46:37 +02:00
|
|
|
splashRadius: 10,
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
borderSide: const BorderSide(color: Colors.transparent),
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
borderSide: const BorderSide(color: Colors.transparent),
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
focusColor: Colors.grey[300],
|
2023-11-09 18:19:53 +02:00
|
|
|
fillColor: context.isDarkTheme
|
2022-08-16 01:53:30 +02:00
|
|
|
? const Color.fromARGB(255, 32, 33, 35)
|
|
|
|
: Colors.grey[200],
|
2022-04-29 06:46:37 +02:00
|
|
|
filled: titleFocusNode.hasFocus,
|
2022-07-07 20:40:54 +02:00
|
|
|
hintText: 'share_add_title'.tr(),
|
2023-08-18 06:26:12 +02:00
|
|
|
hintStyle: TextStyle(
|
|
|
|
fontSize: 28,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.isDarkTheme ? Colors.grey[300] : Colors.grey[700],
|
2023-08-18 06:26:12 +02:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-04-29 06:46:37 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|