123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- import 'package:flutter/material.dart';
- import 'package:photos/core/configuration.dart';
- import 'package:photos/core/event_bus.dart';
- import 'package:photos/db/files_db.dart';
- import 'package:photos/events/backup_folders_updated_event.dart';
- import 'package:photos/models/file.dart';
- import 'package:photos/ui/common_elements.dart';
- import 'package:photos/ui/loading_widget.dart';
- import 'package:photos/ui/thumbnail_widget.dart';
- class BackupFolderSelectionPage extends StatefulWidget {
- final bool shouldSelectAll;
- final String buttonText;
- const BackupFolderSelectionPage({
- @required this.buttonText,
- this.shouldSelectAll = false,
- Key key,
- }) : super(key: key);
- @override
- _BackupFolderSelectionPageState createState() =>
- _BackupFolderSelectionPageState();
- }
- class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {
- final Set<String> _allFolders = Set<String>();
- Set<String> _backedupFolders = Set<String>();
- List<File> _latestFiles;
- bool _isSelectAll = false;
- @override
- void initState() {
- _backedupFolders = Configuration.instance.getPathsToBackUp();
- FilesDB.instance.getLatestLocalFiles().then((files) {
- setState(() {
- _latestFiles = files;
- for (final file in _latestFiles) {
- _allFolders.add(file.deviceFolder);
- }
- if (widget.shouldSelectAll) {
- _backedupFolders.addAll(_allFolders);
- }
- _isSelectAll = _backedupFolders.length == _allFolders.length;
- });
- });
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(title: Text("select folders to backup")),
- body: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Padding(
- padding: EdgeInsets.all(12),
- ),
- Padding(
- padding: const EdgeInsets.only(left: 32, right: 32),
- child: Text(
- "the selected folders will be end-to-end encrypted and backed up",
- style: TextStyle(
- color: Colors.white.withOpacity(0.36),
- fontSize: 14,
- height: 1.3,
- ),
- textAlign: TextAlign.center,
- ),
- ),
- Padding(
- padding: EdgeInsets.all(6),
- ),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- child: Padding(
- padding: const EdgeInsets.fromLTRB(6, 6, 64, 6),
- child: Align(
- alignment: Alignment.centerRight,
- child: Text(
- _isSelectAll ? "unselect all" : "select all",
- textAlign: TextAlign.right,
- style: TextStyle(
- fontSize: 12,
- color: Colors.white.withOpacity(0.8),
- ),
- ),
- ),
- ),
- onTap: () {
- _isSelectAll = !_isSelectAll;
- if (_isSelectAll) {
- _backedupFolders.addAll(_allFolders);
- } else {
- _backedupFolders.clear();
- }
- setState(() {});
- }),
- Expanded(child: _getFolderList()),
- Padding(
- padding: EdgeInsets.all(20),
- ),
- Hero(
- tag: "select_folders",
- child: Container(
- padding: EdgeInsets.only(left: 60, right: 60, bottom: 32),
- child: button(
- widget.buttonText,
- fontSize: 18,
- onPressed: _backedupFolders.length == 0
- ? null
- : () async {
- await Configuration.instance
- .setPathsToBackUp(_backedupFolders);
- Bus.instance.fire(BackupFoldersUpdatedEvent());
- Navigator.of(context).pop();
- },
- padding: EdgeInsets.fromLTRB(60, 20, 60, 20),
- ),
- ),
- ),
- ],
- ),
- );
- }
- Widget _getFolderList() {
- Widget child;
- if (_latestFiles != null) {
- _latestFiles.sort((first, second) {
- return first.deviceFolder
- .toLowerCase()
- .compareTo(second.deviceFolder.toLowerCase());
- });
- final List<Widget> foldersWidget = [];
- for (final file in _latestFiles) {
- final isSelected = _backedupFolders.contains(file.deviceFolder);
- foldersWidget.add(
- Padding(
- padding: const EdgeInsets.only(bottom: 1, right: 4),
- child: Container(
- decoration: BoxDecoration(
- border: Border.all(
- color: Colors.black,
- ),
- borderRadius: BorderRadius.all(
- Radius.circular(10),
- ),
- color: isSelected
- ? Color.fromRGBO(16, 32, 32, 1)
- : Color.fromRGBO(8, 18, 18, 0.4),
- ),
- padding: EdgeInsets.fromLTRB(20, 16, 20, 16),
- child: InkWell(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Container(
- child: Expanded(
- child: Row(
- children: [
- _getThumbnail(file),
- Padding(padding: EdgeInsets.all(10)),
- Expanded(
- child: Text(
- file.deviceFolder,
- style: TextStyle(fontSize: 16, height: 1.5),
- overflow: TextOverflow.clip,
- ),
- ),
- ],
- ),
- ),
- ),
- Checkbox(
- value: isSelected,
- onChanged: (value) {
- if (value) {
- _backedupFolders.add(file.deviceFolder);
- } else {
- _backedupFolders.remove(file.deviceFolder);
- }
- setState(() {});
- },
- ),
- ],
- ),
- onTap: () {
- final value = !_backedupFolders.contains(file.deviceFolder);
- if (value) {
- _backedupFolders.add(file.deviceFolder);
- } else {
- _backedupFolders.remove(file.deviceFolder);
- }
- setState(() {});
- },
- ),
- ),
- ),
- );
- }
- final scrollController = ScrollController();
- child = Scrollbar(
- isAlwaysShown: true,
- controller: scrollController,
- child: SingleChildScrollView(
- controller: scrollController,
- child: Container(
- padding: EdgeInsets.only(right: 4),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: foldersWidget,
- ),
- ),
- ),
- );
- } else {
- child = loadWidget;
- }
- return Container(
- padding: EdgeInsets.only(left: 40, right: 40),
- child: child,
- );
- }
- Widget _getThumbnail(File file) {
- return ClipRRect(
- borderRadius: BorderRadius.circular(4.0),
- child: Container(
- child: ThumbnailWidget(
- file,
- shouldShowSyncStatus: false,
- key: Key("backup_selection_widget" + file.tag()),
- ),
- height: 60,
- width: 60,
- ),
- );
- }
- }
|