ente/lib/ui/loading_photos_widget.dart

184 lines
6.1 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'package:flutter/material.dart';
2022-04-22 06:44:20 +00:00
import 'package:lottie/lottie.dart';
import 'package:photos/core/event_bus.dart';
2022-04-22 06:44:20 +00:00
import 'package:photos/ente_theme_data.dart';
import 'package:photos/events/sync_status_update_event.dart';
import 'package:photos/services/local_sync_service.dart';
import 'package:photos/ui/backup_folder_selection_page.dart';
2022-07-03 10:09:01 +00:00
import 'package:photos/ui/common/bottom_shadow.dart';
2021-05-29 17:01:59 +00:00
import 'package:photos/utils/navigation_util.dart';
2021-05-29 17:01:59 +00:00
class LoadingPhotosWidget extends StatefulWidget {
const LoadingPhotosWidget({Key key}) : super(key: key);
@override
2022-07-03 09:45:00 +00:00
State<LoadingPhotosWidget> createState() => _LoadingPhotosWidgetState();
}
2021-05-29 17:01:59 +00:00
class _LoadingPhotosWidgetState extends State<LoadingPhotosWidget> {
StreamSubscription<SyncStatusUpdate> _firstImportEvent;
int _currentPage = 0;
final PageController _pageController = PageController(
initialPage: 0,
);
final List<String> _messages = [
"web.ente.io has a slick uploader",
2022-06-03 15:24:14 +00:00
"We have preserved over 3 million memories so far",
"All our apps are open source",
"Our encryption protocols have been reviewed by engineers at Google, Apple, Amazon, and Facebook",
2022-06-10 14:21:50 +00:00
"You can share links to your albums with your loved ones",
"Our mobile apps run in the background to encrypt and backup new photos you take",
"We use Xchacha20Poly1305 to safely encrypt your data",
2022-06-10 14:21:50 +00:00
"One of our data centers is in an underground fall out shelter in Paris",
];
@override
void initState() {
super.initState();
2022-07-03 09:49:33 +00:00
_firstImportEvent =
Bus.instance.on<SyncStatusUpdate>().listen((event) async {
2022-07-03 07:47:15 +00:00
if (mounted && event.status == SyncStatus.completedFirstGalleryImport) {
if (LocalSyncService.instance.hasGrantedLimitedPermissions()) {
// Do nothing, let HomeWidget refresh
} else {
2021-07-11 18:05:07 +00:00
routeToPage(
2022-06-11 08:23:52 +00:00
context,
2022-07-04 06:02:17 +00:00
const BackupFolderSelectionPage(
isOnboarding: true,
2022-06-11 08:23:52 +00:00
buttonText: "Start backup",
),
);
}
}
});
2022-07-04 06:02:17 +00:00
Timer.periodic(const Duration(seconds: 5), (Timer timer) {
if (!mounted) {
return;
}
if (_currentPage < _messages.length - 1) {
_currentPage++;
} else {
_currentPage = 0;
}
_pageController.animateToPage(
_currentPage,
2022-07-04 06:02:17 +00:00
duration: const Duration(milliseconds: 300),
curve: Curves.easeIn,
);
});
}
@override
void dispose() {
_firstImportEvent.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
2022-07-03 09:49:33 +00:00
final isLightMode =
MediaQuery.of(context).platformBrightness == Brightness.light;
return Scaffold(
2022-06-13 14:44:47 +00:00
body: SingleChildScrollView(
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Stack(
alignment: Alignment.center,
children: [
isLightMode
? Image.asset(
2022-06-24 15:29:24 +00:00
'assets/loading_photos_background.png',
2022-06-13 14:44:47 +00:00
color: Colors.white.withOpacity(0.5),
colorBlendMode: BlendMode.modulate,
)
: Image.asset(
2022-06-24 15:29:24 +00:00
'assets/loading_photos_background_dark.png',
2022-06-13 14:44:47 +00:00
color: Colors.white.withOpacity(0.25),
colorBlendMode: BlendMode.modulate,
),
const SizedBox(height: 20),
Column(
children: [
const SizedBox(height: 50),
Lottie.asset(
'assets/loadingGalleryLottie.json',
height: 400,
),
],
2022-06-13 14:44:47 +00:00
)
],
),
2022-06-13 14:44:47 +00:00
Text(
"Loading your photos...",
style: TextStyle(
color: Theme.of(context).colorScheme.subTextColor,
2022-06-03 15:24:14 +00:00
),
2022-06-13 14:44:47 +00:00
),
const SizedBox(height: 54),
Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
2022-06-11 08:23:52 +00:00
children: [
2022-06-13 14:44:47 +00:00
Text(
"Did you know?",
style: Theme.of(context).textTheme.headline6.copyWith(
color: Theme.of(context).colorScheme.greenText,
),
2022-06-11 08:23:52 +00:00
),
],
),
2022-06-13 14:44:47 +00:00
const SizedBox(
height: 16,
),
SizedBox(
height: 175,
child: Stack(
children: [
PageView.builder(
scrollDirection: Axis.vertical,
controller: _pageController,
itemBuilder: (context, index) {
return _getMessage(_messages[index]);
},
itemCount: _messages.length,
2022-07-04 06:02:17 +00:00
physics: const NeverScrollableScrollPhysics(),
2022-06-13 14:44:47 +00:00
),
2022-07-04 06:02:17 +00:00
const Positioned(
2022-06-13 14:44:47 +00:00
bottom: 0,
left: 0,
right: 0,
child: BottomShadowWidget(),
)
],
),
),
],
),
],
),
2022-06-03 15:24:14 +00:00
),
),
),
);
}
2021-05-10 15:43:20 +00:00
Widget _getMessage(String text) {
2022-06-03 15:24:14 +00:00
return Text(
text,
textAlign: TextAlign.start,
style: Theme.of(context)
.textTheme
.headline5
.copyWith(color: Theme.of(context).colorScheme.defaultTextColor),
2021-05-10 15:43:20 +00:00
);
}
}