ente/lib/ui/device_folder_page.dart

99 lines
3.1 KiB
Dart
Raw Normal View History

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/collection_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
2020-05-17 14:35:31 +00:00
class DeviceFolderPage extends StatefulWidget {
final DeviceFolder folder;
2020-04-18 18:46:38 +00:00
2020-05-17 14:35:31 +00:00
const DeviceFolderPage(this.folder, {Key key}) : super(key: key);
2020-04-18 18:46:38 +00:00
@override
2020-05-17 14:35:31 +00:00
_DeviceFolderPageState createState() => _DeviceFolderPageState();
2020-04-18 18:46:38 +00:00
}
2020-05-17 14:35:31 +00:00
class _DeviceFolderPageState extends State<DeviceFolderPage> {
final _selectedFiles = SelectedFiles();
2020-04-18 18:46:38 +00:00
@override
Widget build(Object context) {
final gallery = Gallery(
asyncLoader: (_, __) => FilesDB.instance.getAllInPath(widget.folder.path),
shouldLoadAll: true,
reloadEvent: Bus.instance.on<LocalPhotosUpdatedEvent>(),
tagPrefix: "device_folder:" + widget.folder.path,
selectedFiles: _selectedFiles,
headerWidget: Configuration.instance.hasConfiguredAccount()
? _getHeaderWidget()
: Container(),
);
2020-04-18 18:46:38 +00:00
return Scaffold(
appBar: GalleryAppBarWidget(
GalleryAppBarType.local_folder,
2020-05-17 14:35:31 +00:00
widget.folder.name,
_selectedFiles,
2020-10-29 12:56:30 +00:00
path: widget.folder.thumbnail.deviceFolder,
2020-04-18 18:46:38 +00:00
),
body: gallery,
2020-04-18 18:46:38 +00:00
);
}
Widget _getHeaderWidget() {
2021-03-25 16:58:30 +00:00
return BackupConfigurationHeaderWidget(widget.folder.path);
}
}
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 =
2021-03-25 16:58:30 +00:00
Configuration.instance.getPathsToBackUp().contains(widget.path);
return Container(
padding: EdgeInsets.only(left: 12, right: 12),
color: Colors.grey.withOpacity(0.15),
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);
}
Configuration.instance.setPathsToBackUp(current);
setState(() {});
Bus.instance.fire(CollectionUpdatedEvent());
},
),
],
),
);
}
2020-04-18 18:46:38 +00:00
}