2021-07-25 10:42:27 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:nc_photos/account.dart';
|
|
|
|
import 'package:nc_photos/api/api.dart';
|
|
|
|
import 'package:nc_photos/app_localizations.dart';
|
|
|
|
import 'package:nc_photos/entity/album.dart';
|
|
|
|
import 'package:nc_photos/theme.dart';
|
|
|
|
|
2021-07-31 19:16:14 +02:00
|
|
|
class AlbumBrowserAppBar extends StatelessWidget {
|
|
|
|
AlbumBrowserAppBar({
|
2021-07-25 10:42:27 +02:00
|
|
|
Key? key,
|
|
|
|
required this.account,
|
|
|
|
required this.album,
|
|
|
|
this.coverPreviewUrl,
|
|
|
|
this.actions,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context) {
|
|
|
|
return SliverAppBar(
|
|
|
|
floating: true,
|
|
|
|
expandedHeight: 160,
|
|
|
|
flexibleSpace: FlexibleSpaceBar(
|
|
|
|
background: _getAppBarCover(context, account, coverPreviewUrl),
|
|
|
|
title: Text(
|
|
|
|
album.name,
|
|
|
|
style: TextStyle(
|
|
|
|
color: AppTheme.getPrimaryTextColor(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: actions,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final Album album;
|
|
|
|
final String? coverPreviewUrl;
|
|
|
|
final List<Widget>? actions;
|
|
|
|
}
|
|
|
|
|
2021-07-31 19:16:14 +02:00
|
|
|
class AlbumBrowserEditAppBar extends StatefulWidget {
|
|
|
|
AlbumBrowserEditAppBar({
|
2021-07-25 10:42:27 +02:00
|
|
|
Key? key,
|
|
|
|
required this.account,
|
|
|
|
required this.album,
|
|
|
|
this.coverPreviewUrl,
|
|
|
|
this.actions,
|
|
|
|
required this.onDonePressed,
|
|
|
|
required this.onAlbumNameSaved,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
2021-07-31 19:16:14 +02:00
|
|
|
createState() => _AlbumBrowserEditAppBarState();
|
2021-07-25 10:42:27 +02:00
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final Album album;
|
|
|
|
final String? coverPreviewUrl;
|
|
|
|
final List<Widget>? actions;
|
|
|
|
final VoidCallback? onDonePressed;
|
|
|
|
final ValueChanged<String>? onAlbumNameSaved;
|
|
|
|
}
|
|
|
|
|
2021-07-31 19:16:14 +02:00
|
|
|
class _AlbumBrowserEditAppBarState extends State<AlbumBrowserEditAppBar> {
|
2021-07-25 10:42:27 +02:00
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
2021-07-25 13:41:05 +02:00
|
|
|
_controller = TextEditingController(text: widget.album.name);
|
2021-07-25 10:42:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context) {
|
|
|
|
return SliverAppBar(
|
|
|
|
floating: true,
|
|
|
|
expandedHeight: 160,
|
|
|
|
flexibleSpace: FlexibleSpaceBar(
|
|
|
|
background:
|
|
|
|
_getAppBarCover(context, widget.account, widget.coverPreviewUrl),
|
|
|
|
title: TextFormField(
|
2021-07-25 13:41:05 +02:00
|
|
|
controller: _controller,
|
2021-07-25 10:42:27 +02:00
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: L10n.of(context).nameInputHint,
|
|
|
|
),
|
2021-07-25 13:41:05 +02:00
|
|
|
validator: (_) {
|
|
|
|
// use _controller.text here because the value might be wrong if
|
|
|
|
// user scrolled the app bar off screen
|
|
|
|
if (_controller.text.isNotEmpty == true) {
|
2021-07-25 10:42:27 +02:00
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return L10n.of(context).albumNameInputInvalidEmpty;
|
|
|
|
}
|
|
|
|
},
|
2021-07-25 13:41:05 +02:00
|
|
|
onSaved: (_) {
|
|
|
|
widget.onAlbumNameSaved?.call(_controller.text);
|
2021-07-25 10:42:27 +02:00
|
|
|
},
|
|
|
|
style: TextStyle(
|
|
|
|
color: AppTheme.getPrimaryTextColor(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.check),
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
tooltip: L10n.of(context).doneButtonTooltip,
|
|
|
|
onPressed: widget.onDonePressed,
|
|
|
|
),
|
|
|
|
actions: widget.actions,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-25 13:41:05 +02:00
|
|
|
late TextEditingController _controller;
|
2021-07-25 10:42:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget? _getAppBarCover(
|
|
|
|
BuildContext context, Account account, String? coverPreviewUrl) {
|
|
|
|
try {
|
|
|
|
if (coverPreviewUrl != null) {
|
|
|
|
return Opacity(
|
|
|
|
opacity: Theme.of(context).brightness == Brightness.light ? 0.25 : 0.35,
|
|
|
|
child: FittedBox(
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
child: CachedNetworkImage(
|
|
|
|
imageUrl: coverPreviewUrl,
|
|
|
|
httpHeaders: {
|
|
|
|
"Authorization": Api.getAuthorizationHeaderValue(account),
|
|
|
|
},
|
|
|
|
filterQuality: FilterQuality.high,
|
|
|
|
errorWidget: (context, url, error) {
|
|
|
|
// just leave it empty
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (_) {}
|
|
|
|
return null;
|
|
|
|
}
|