Rename album to folder
This commit is contained in:
parent
b6c9ae31b5
commit
5e5fdba4e2
7 changed files with 55 additions and 54 deletions
|
@ -1,12 +1,12 @@
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
|
||||
class AlbumSharingService {
|
||||
class FolderSharingService {
|
||||
final _dio = Dio();
|
||||
|
||||
AlbumSharingService._privateConstructor();
|
||||
static final AlbumSharingService instance =
|
||||
AlbumSharingService._privateConstructor();
|
||||
FolderSharingService._privateConstructor();
|
||||
static final FolderSharingService instance =
|
||||
FolderSharingService._privateConstructor();
|
||||
|
||||
Future<Map<String, bool>> getSharingStatus(String path) async {
|
||||
// TODO fetch folderID from path
|
||||
|
@ -40,7 +40,7 @@ class AlbumSharingService {
|
|||
});
|
||||
}
|
||||
|
||||
void shareAlbum(
|
||||
void shareFolder(
|
||||
String path,
|
||||
) {}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
import 'package:photos/models/filters/gallery_items_filter.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
|
||||
class Album {
|
||||
class DeviceFolder {
|
||||
final String name;
|
||||
final Photo thumbnailPhoto;
|
||||
final GalleryItemsFilter filter;
|
||||
|
||||
Album(this.name, this.thumbnailPhoto, this.filter);
|
||||
DeviceFolder(this.name, this.thumbnailPhoto, this.filter);
|
||||
}
|
|
@ -3,24 +3,24 @@ import 'dart:async';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/events/local_photos_updated_event.dart';
|
||||
import 'package:photos/models/album.dart';
|
||||
import 'package:photos/models/device_folder.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
import 'package:photos/photo_repository.dart';
|
||||
import 'package:photos/ui/gallery.dart';
|
||||
import 'package:photos/ui/gallery_app_bar_widget.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
class AlbumPage extends StatefulWidget {
|
||||
final Album album;
|
||||
class DeviceFolderPage extends StatefulWidget {
|
||||
final DeviceFolder folder;
|
||||
|
||||
const AlbumPage(this.album, {Key key}) : super(key: key);
|
||||
const DeviceFolderPage(this.folder, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_AlbumPageState createState() => _AlbumPageState();
|
||||
_DeviceFolderPageState createState() => _DeviceFolderPageState();
|
||||
}
|
||||
|
||||
class _AlbumPageState extends State<AlbumPage> {
|
||||
final logger = Logger("AlbumPageState");
|
||||
class _DeviceFolderPageState extends State<DeviceFolderPage> {
|
||||
final logger = Logger("DeviceFolderPageState");
|
||||
Set<Photo> _selectedPhotos = Set<Photo>();
|
||||
StreamSubscription<LocalPhotosUpdatedEvent> _subscription;
|
||||
|
||||
|
@ -37,8 +37,8 @@ class _AlbumPageState extends State<AlbumPage> {
|
|||
return Scaffold(
|
||||
appBar: GalleryAppBarWidget(
|
||||
GalleryAppBarType.folder,
|
||||
widget.album.name,
|
||||
widget.album.thumbnailPhoto.deviceFolder,
|
||||
widget.folder.name,
|
||||
widget.folder.thumbnailPhoto.deviceFolder,
|
||||
_selectedPhotos,
|
||||
onSelectionClear: () {
|
||||
setState(() {
|
||||
|
@ -61,7 +61,7 @@ class _AlbumPageState extends State<AlbumPage> {
|
|||
List<Photo> _getFilteredPhotos(List<Photo> unfilteredPhotos) {
|
||||
final List<Photo> filteredPhotos = List<Photo>();
|
||||
for (Photo photo in unfilteredPhotos) {
|
||||
if (widget.album.filter.shouldInclude(photo)) {
|
||||
if (widget.folder.filter.shouldInclude(photo)) {
|
||||
filteredPhotos.add(photo);
|
||||
}
|
||||
}
|
|
@ -1,35 +1,34 @@
|
|||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:photos/db/db_helper.dart';
|
||||
import 'package:photos/favorite_photos_repository.dart';
|
||||
import 'package:photos/models/album.dart';
|
||||
import 'package:photos/models/device_folder.dart';
|
||||
import 'package:photos/models/filters/favorite_items_filter.dart';
|
||||
import 'package:photos/models/filters/folder_name_filter.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
import 'package:photos/ui/album_page.dart';
|
||||
import 'package:photos/ui/device_folder_page.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:photos/ui/thumbnail_widget.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
class AlbumListWidget extends StatefulWidget {
|
||||
class DeviceFolderGalleryWidget extends StatefulWidget {
|
||||
final List<Photo> photos;
|
||||
|
||||
const AlbumListWidget(this.photos, {Key key}) : super(key: key);
|
||||
const DeviceFolderGalleryWidget(this.photos, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_AlbumListWidgetState createState() => _AlbumListWidgetState();
|
||||
_DeviceFolderGalleryWidgetState createState() =>
|
||||
_DeviceFolderGalleryWidgetState();
|
||||
}
|
||||
|
||||
class _AlbumListWidgetState extends State<AlbumListWidget> {
|
||||
class _DeviceFolderGalleryWidgetState extends State<DeviceFolderGalleryWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: _getAlbums(),
|
||||
future: _getDeviceFolders(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return _getAlbumListWidget(snapshot.data);
|
||||
return _getDeviceFolderGalleryWidget(snapshot.data);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
} else {
|
||||
|
@ -39,7 +38,7 @@ class _AlbumListWidgetState extends State<AlbumListWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _getAlbumListWidget(List<Album> albums) {
|
||||
Widget _getDeviceFolderGalleryWidget(List<DeviceFolder> folders) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 24),
|
||||
child: GridView.builder(
|
||||
|
@ -47,9 +46,9 @@ class _AlbumListWidgetState extends State<AlbumListWidget> {
|
|||
padding: EdgeInsets.only(bottom: 12),
|
||||
physics: ScrollPhysics(), // to disable GridView's scrolling
|
||||
itemBuilder: (context, index) {
|
||||
return _buildAlbum(context, albums[index]);
|
||||
return _buildFolder(context, folders[index]);
|
||||
},
|
||||
itemCount: albums.length,
|
||||
itemCount: folders.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
),
|
||||
|
@ -57,40 +56,42 @@ class _AlbumListWidgetState extends State<AlbumListWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
Future<List<Album>> _getAlbums() async {
|
||||
Future<List<DeviceFolder>> _getDeviceFolders() async {
|
||||
final paths = await DatabaseHelper.instance.getDistinctPaths();
|
||||
final albums = List<Album>();
|
||||
final folders = List<DeviceFolder>();
|
||||
for (final path in paths) {
|
||||
final photo = await DatabaseHelper.instance.getLatestPhotoInPath(path);
|
||||
final albumName = p.basename(path);
|
||||
albums.add(Album(albumName, photo, FolderNameFilter(albumName)));
|
||||
final folderName = p.basename(path);
|
||||
folders
|
||||
.add(DeviceFolder(folderName, photo, FolderNameFilter(folderName)));
|
||||
}
|
||||
albums.sort((firstAlbum, secondAlbum) {
|
||||
return secondAlbum.thumbnailPhoto.createTimestamp
|
||||
.compareTo(firstAlbum.thumbnailPhoto.createTimestamp);
|
||||
folders.sort((first, second) {
|
||||
return second.thumbnailPhoto.createTimestamp
|
||||
.compareTo(first.thumbnailPhoto.createTimestamp);
|
||||
});
|
||||
if (FavoritePhotosRepository.instance.hasFavorites()) {
|
||||
final photo = await DatabaseHelper.instance
|
||||
.getLatestPhotoAmongGeneratedIds(
|
||||
FavoritePhotosRepository.instance.getLiked().toList());
|
||||
albums.insert(0, Album("Favorites", photo, FavoriteItemsFilter()));
|
||||
folders.insert(
|
||||
0, DeviceFolder("Favorites", photo, FavoriteItemsFilter()));
|
||||
}
|
||||
return albums;
|
||||
return folders;
|
||||
}
|
||||
|
||||
Widget _buildAlbum(BuildContext context, Album album) {
|
||||
Widget _buildFolder(BuildContext context, DeviceFolder folder) {
|
||||
return GestureDetector(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: ThumbnailWidget(album.thumbnailPhoto),
|
||||
child: ThumbnailWidget(folder.thumbnailPhoto),
|
||||
height: 150,
|
||||
width: 150,
|
||||
),
|
||||
Padding(padding: EdgeInsets.all(2)),
|
||||
Expanded(
|
||||
child: Text(
|
||||
album.name,
|
||||
folder.name,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
|
@ -99,7 +100,7 @@ class _AlbumListWidgetState extends State<AlbumListWidget> {
|
|||
],
|
||||
),
|
||||
onTap: () {
|
||||
final page = AlbumPage(album);
|
||||
final page = DeviceFolderPage(folder);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
|
@ -8,7 +8,7 @@ import 'package:photos/models/photo.dart';
|
|||
import 'package:photos/photo_repository.dart';
|
||||
import 'package:photos/ui/setup_page.dart';
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
import 'package:photos/ui/share_album_widget.dart';
|
||||
import 'package:photos/ui/share_folder_widget.dart';
|
||||
import 'package:photos/utils/share_util.dart';
|
||||
|
||||
enum GalleryAppBarType { homepage, folder }
|
||||
|
@ -90,7 +90,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ShareAlbumWidget(widget.title, widget.path);
|
||||
return ShareFolderWidget(widget.title, widget.path);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import 'package:photos/events/local_photos_updated_event.dart';
|
|||
import 'package:photos/models/filters/important_items_filter.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
import 'package:photos/photo_repository.dart';
|
||||
import 'package:photos/ui/album_list_widget.dart';
|
||||
import 'package:photos/ui/device_folders_gallery_widget.dart';
|
||||
import 'package:photos/ui/gallery.dart';
|
||||
import 'package:photos/ui/gallery_app_bar_widget.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
|
@ -74,7 +74,7 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
});
|
||||
},
|
||||
),
|
||||
AlbumListWidget(PhotoRepository.instance.photos)
|
||||
DeviceFolderGalleryWidget(PhotoRepository.instance.photos)
|
||||
],
|
||||
index: _selectedNavBarItem,
|
||||
);
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:photos/album_sharing_service.dart';
|
||||
import 'package:photos/folder_service.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
|
||||
class ShareAlbumWidget extends StatefulWidget {
|
||||
class ShareFolderWidget extends StatefulWidget {
|
||||
final String title;
|
||||
final String path;
|
||||
|
||||
const ShareAlbumWidget(
|
||||
const ShareFolderWidget(
|
||||
this.title,
|
||||
this.path, {
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ShareAlbumWidgetState createState() => _ShareAlbumWidgetState();
|
||||
_ShareFolderWidgetState createState() => _ShareFolderWidgetState();
|
||||
}
|
||||
|
||||
class _ShareAlbumWidgetState extends State<ShareAlbumWidget> {
|
||||
class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<Map<String, bool>>(
|
||||
future: AlbumSharingService.instance.getSharingStatus(widget.path),
|
||||
future: FolderSharingService.instance.getSharingStatus(widget.path),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return _getSharingDialog(snapshot.data);
|
||||
|
@ -48,7 +48,7 @@ class _ShareAlbumWidgetState extends State<ShareAlbumWidget> {
|
|||
FlatButton(
|
||||
child: Text("Share"),
|
||||
onPressed: () {
|
||||
// TODO: AlbumSharingService.instance.shareAlbum();
|
||||
// TODO: FolderSharingService.instance.shareFolder();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
Loading…
Add table
Reference in a new issue