ente/lib/ui/home/memories/full_screen_memory.dart

287 lines
8.4 KiB
Dart
Raw Normal View History

import "dart:io";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";
2023-05-10 06:27:11 +00:00
import "package:intl/intl.dart";
import "package:photos/models/memory.dart";
import "package:photos/services/memories_service.dart";
import "package:photos/theme/text_style.dart";
2023-02-22 09:53:50 +00:00
import "package:photos/ui/actions/file/file_actions.dart";
2023-02-25 12:13:37 +00:00
import "package:photos/ui/extents_page_view.dart";
import "package:photos/ui/viewer/file/file_widget.dart";
import "package:photos/utils/file_util.dart";
import "package:photos/utils/share_util.dart";
import "package:step_progress_indicator/step_progress_indicator.dart";
2020-07-21 10:25:19 +00:00
class FullScreenMemory extends StatefulWidget {
2020-07-21 12:11:33 +00:00
final String title;
2020-07-21 22:01:44 +00:00
final List<Memory> memories;
final int index;
2020-07-21 10:25:19 +00:00
const FullScreenMemory(this.title, this.memories, this.index, {Key? key})
2020-07-21 22:01:44 +00:00
: super(key: key);
2020-07-21 10:25:19 +00:00
@override
2022-07-03 09:45:00 +00:00
State<FullScreenMemory> createState() => _FullScreenMemoryState();
2020-07-21 10:25:19 +00:00
}
class _FullScreenMemoryState extends State<FullScreenMemory> {
2020-07-21 22:01:44 +00:00
int _index = 0;
double _opacity = 1;
// shows memory counter as index+1/totalFiles for large number of memories
// when the top step indicator isn't visible.
bool _showCounter = false;
bool _showStepIndicator = true;
PageController? _pageController;
bool _shouldDisableScroll = false;
final GlobalKey shareButtonKey = GlobalKey();
2020-07-21 12:11:33 +00:00
@override
void initState() {
super.initState();
2020-07-21 22:01:44 +00:00
_index = widget.index;
_showStepIndicator = widget.memories.length <= 60;
2022-07-04 06:02:17 +00:00
Future.delayed(const Duration(seconds: 3), () {
2020-07-21 22:01:44 +00:00
if (mounted) {
setState(() {
_opacity = 0;
_showCounter = !_showStepIndicator;
2020-07-21 22:01:44 +00:00
});
}
2020-07-21 12:11:33 +00:00
});
2020-07-21 22:01:44 +00:00
MemoriesService.instance.markMemoryAsSeen(widget.memories[_index]);
2020-07-21 12:11:33 +00:00
}
2020-07-21 10:25:19 +00:00
@override
Widget build(BuildContext context) {
2020-07-29 19:07:23 +00:00
final file = widget.memories[_index].file;
return Scaffold(
2020-07-21 22:54:36 +00:00
appBar: AppBar(
2022-04-25 14:27:10 +00:00
toolbarHeight: 84,
automaticallyImplyLeading: false,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_showStepIndicator
? StepProgressIndicator(
totalSteps: widget.memories.length,
currentStep: _index + 1,
size: 2,
selectedColor: Colors.white, //same for both themes
unselectedColor: Colors.white.withOpacity(0.4),
)
: const SizedBox.shrink(),
2022-07-04 06:02:17 +00:00
const SizedBox(
2022-04-25 14:27:10 +00:00
height: 18,
),
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 16),
child: InkWell(
onTap: () {
Navigator.pop(context);
},
2022-07-04 06:02:17 +00:00
child: const Icon(
2022-04-25 14:27:10 +00:00
Icons.close,
color: Colors.white, //same for both themes
),
),
),
Text(
2023-05-10 06:27:11 +00:00
DateFormat.yMMMd(Localizations.localeOf(context).languageCode)
.format(
DateTime.fromMicrosecondsSinceEpoch(
file.creationTime!,
),
2022-06-11 08:23:52 +00:00
),
style: Theme.of(context).textTheme.subtitle1!.copyWith(
2022-06-11 08:23:52 +00:00
fontSize: 14,
color: Colors.white,
), //same for both themes
2022-04-25 14:27:10 +00:00
),
],
),
],
),
flexibleSpace: Container(
decoration: BoxDecoration(
2022-06-11 08:23:52 +00:00
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.black.withOpacity(0.6),
Colors.black.withOpacity(0.5),
Colors.transparent,
],
stops: const [0, 0.6, 1],
),
),
2022-04-25 14:27:10 +00:00
),
2022-07-04 06:02:17 +00:00
backgroundColor: const Color(0x00000000),
2020-07-21 22:54:36 +00:00
elevation: 0,
),
extendBodyBehindAppBar: true,
2020-07-21 22:31:18 +00:00
body: Container(
color: Colors.black,
2022-06-11 08:23:52 +00:00
child: Stack(
alignment: Alignment.bottomCenter,
children: [
_buildSwiper(),
bottomGradient(),
_buildInfoText(),
2022-06-11 08:23:52 +00:00
_buildBottomIcons(),
],
),
2020-07-29 19:07:23 +00:00
),
);
}
void onFileDeleted() {
if (widget.memories.length == 1) {
Navigator.pop(context);
} else {
setState(() {
if (_index != 0) {
_pageController?.jumpToPage(_index - 1);
}
widget.memories.removeAt(_index);
if (_index != 0) {
_index--;
}
});
}
}
Hero _buildInfoText() {
2020-07-29 19:07:23 +00:00
return Hero(
tag: widget.title,
child: SafeArea(
child: Container(
alignment: Alignment.bottomCenter,
padding: const EdgeInsets.fromLTRB(0, 0, 0, 72),
child: _showCounter
? Text(
'${_index + 1}/${widget.memories.length}',
style: darkTextTheme.bodyMuted,
)
: AnimatedOpacity(
opacity: _opacity,
duration: const Duration(milliseconds: 500),
child: Text(
widget.title,
style: darkTextTheme.h2,
),
),
),
2020-07-21 22:31:18 +00:00
),
2020-07-21 10:25:19 +00:00
);
}
2020-07-21 22:01:44 +00:00
2022-04-25 14:27:10 +00:00
Widget _buildBottomIcons() {
final file = widget.memories[_index].file;
return SafeArea(
child: Container(
alignment: Alignment.bottomRight,
padding: const EdgeInsets.fromLTRB(26, 0, 26, 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: Icon(
Platform.isAndroid ? Icons.info_outline : CupertinoIcons.info,
color: Colors.white, //same for both themes
),
onPressed: () {
2023-03-20 05:46:51 +00:00
showDetailsSheet(context, file);
},
),
IconButton(
2023-02-22 10:57:14 +00:00
icon: Icon(
Platform.isAndroid
? Icons.delete_outline
: CupertinoIcons.delete,
color: Colors.white, //same for both themes
),
onPressed: () async {
await showSingleFileDeleteSheet(
context,
file,
onFileRemoved: (file) => {onFileDeleted()},
);
},
),
IconButton(
icon: Icon(
Icons.adaptive.share,
color: Colors.white, //same for both themes
),
onPressed: () {
share(context, [file]);
},
),
],
),
2022-06-11 08:23:52 +00:00
),
);
2022-04-25 14:27:10 +00:00
}
Widget bottomGradient() {
return Container(
height: 124,
width: double.infinity,
decoration: BoxDecoration(
2022-06-11 08:23:52 +00:00
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [
Colors.black.withOpacity(0.5), //same for both themes
Colors.transparent,
],
stops: const [0, 0.8],
),
),
2020-07-29 19:07:23 +00:00
);
}
Widget _buildSwiper() {
_pageController = PageController(initialPage: _index);
2023-02-25 12:13:37 +00:00
return ExtentsPageView.extents(
2020-07-21 22:01:44 +00:00
itemBuilder: (BuildContext context, int index) {
2020-07-29 19:07:23 +00:00
if (index < widget.memories.length - 1) {
final nextFile = widget.memories[index + 1].file;
2021-04-27 16:29:58 +00:00
preloadThumbnail(nextFile);
2021-04-27 16:36:07 +00:00
preloadFile(nextFile);
2020-07-29 19:07:23 +00:00
}
2020-07-21 22:01:44 +00:00
final file = widget.memories[index].file;
return FileWidget(
file,
autoPlay: false,
tagPrefix: "memories",
shouldDisableScroll: (value) {
setState(() {
_shouldDisableScroll = value;
});
},
2022-07-04 06:02:17 +00:00
backgroundDecoration: const BoxDecoration(
color: Colors.transparent,
),
);
2020-07-21 22:01:44 +00:00
},
itemCount: widget.memories.length,
2020-07-29 19:07:23 +00:00
controller: _pageController,
onPageChanged: (index) async {
2020-07-21 22:01:44 +00:00
await MemoriesService.instance.markMemoryAsSeen(widget.memories[index]);
2022-10-21 08:05:16 +00:00
if (mounted) {
setState(() {
_index = index;
});
}
2020-07-21 22:01:44 +00:00
},
physics: _shouldDisableScroll
2022-07-04 06:02:17 +00:00
? const NeverScrollableScrollPhysics()
: const PageScrollPhysics(),
2020-07-21 22:01:44 +00:00
);
}
2020-07-21 10:25:19 +00:00
}