ente/lib/ui/device_folder_page.dart

110 lines
3.4 KiB
Dart
Raw Normal View History

2021-05-13 21:37:23 +00:00
import 'dart:io';
2020-04-18 18:46:38 +00:00
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/events/local_photos_updated_event.dart';
2020-05-17 14:35:31 +00:00
import 'package:photos/models/device_folder.dart';
import 'package:photos/models/selected_files.dart';
2020-05-01 18:20:12 +00:00
import 'package:photos/ui/gallery.dart';
import 'package:photos/ui/gallery_app_bar_widget.dart';
2020-04-18 18:46:38 +00:00
class DeviceFolderPage extends StatelessWidget {
2020-05-17 14:35:31 +00:00
final DeviceFolder folder;
final _selectedFiles = SelectedFiles();
2020-04-18 18:46:38 +00:00
DeviceFolderPage(this.folder, {Key key}) : super(key: key);
2020-04-18 18:46:38 +00:00
@override
Widget build(Object context) {
final gallery = Gallery(
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) {
2021-04-20 20:11:39 +00:00
return FilesDB.instance.getFilesInPath(
folder.path, creationStartTime, creationEndTime,
limit: limit, asc: asc);
2021-04-20 20:11:39 +00:00
},
reloadEvent: Bus.instance.on<LocalPhotosUpdatedEvent>(),
tagPrefix: "device_folder:" + folder.path,
selectedFiles: _selectedFiles,
2021-05-12 20:54:44 +00:00
header: Configuration.instance.hasConfiguredAccount()
? _getHeaderWidget()
: Container(),
2021-05-13 18:05:32 +00:00
initialFiles: [folder.thumbnail],
);
2020-04-18 18:46:38 +00:00
return Scaffold(
body: Stack(
children: [
Padding(
2021-05-13 21:37:23 +00:00
padding: EdgeInsets.only(top: Platform.isAndroid ? 80 : 100),
child: gallery,
),
SizedBox(
2021-05-13 21:37:23 +00:00
height: Platform.isAndroid ? 80 : 100,
child: GalleryAppBarWidget(
GalleryAppBarType.local_folder,
folder.name,
_selectedFiles,
path: folder.thumbnail.deviceFolder,
),
)
],
2020-04-18 18:46:38 +00:00
),
);
}
Widget _getHeaderWidget() {
return BackupConfigurationHeaderWidget(folder.path);
2021-03-25 16:58:30 +00:00
}
}
class BackupConfigurationHeaderWidget extends StatefulWidget {
final String path;
BackupConfigurationHeaderWidget(this.path, {Key key}) : super(key: key);
@override
_BackupConfigurationHeaderWidgetState createState() =>
_BackupConfigurationHeaderWidgetState();
}
class _BackupConfigurationHeaderWidgetState
extends State<BackupConfigurationHeaderWidget> {
@override
Widget build(BuildContext context) {
final isBackedUp =
Configuration.instance.getPathsToBackUp().contains(widget.path);
return Container(
padding: EdgeInsets.only(left: 20, right: 12, top: 4, bottom: 4),
2021-04-06 00:46:30 +00:00
margin: EdgeInsets.only(bottom: 12),
color: Color.fromRGBO(10, 40, 40, 0.3),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
isBackedUp
? Text("backup enabled")
: Text(
"backup disabled",
style: TextStyle(color: Colors.white.withOpacity(0.7)),
),
Switch(
value: isBackedUp,
onChanged: (value) async {
final current = Configuration.instance.getPathsToBackUp();
if (value) {
2021-03-25 16:58:30 +00:00
current.add(widget.path);
} else {
2021-03-25 16:58:30 +00:00
current.remove(widget.path);
}
2021-05-12 21:55:11 +00:00
await Configuration.instance.setPathsToBackUp(current);
setState(() {});
Bus.instance.fire(BackupFoldersUpdatedEvent());
},
),
],
),
);
}
2020-04-18 18:46:38 +00:00
}