Remove dead code related to folders
This commit is contained in:
parent
f6b9e50f8a
commit
d64f34f6d7
5 changed files with 0 additions and 356 deletions
|
@ -1,106 +0,0 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart';
|
||||
import 'package:photos/models/folder.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class FoldersDB {
|
||||
static final _databaseName = "ente.folder.db";
|
||||
static final _databaseVersion = 1;
|
||||
|
||||
static final table = 'folders';
|
||||
|
||||
static final columnId = 'id';
|
||||
static final columnName = 'name';
|
||||
static final columnOwnerID = 'owner_id';
|
||||
static final columnDeviceFolder = 'device_folder';
|
||||
static final columnSharedWith = 'shared_with';
|
||||
static final columnUpdationTime = 'updation_time';
|
||||
|
||||
FoldersDB._privateConstructor();
|
||||
static final FoldersDB instance = FoldersDB._privateConstructor();
|
||||
|
||||
static Database _database;
|
||||
Future<Database> get database async {
|
||||
if (_database != null) return _database;
|
||||
_database = await _initDatabase();
|
||||
return _database;
|
||||
}
|
||||
|
||||
_initDatabase() async {
|
||||
Directory documentsDirectory = await getApplicationDocumentsDirectory();
|
||||
String path = join(documentsDirectory.path, _databaseName);
|
||||
return await openDatabase(path,
|
||||
version: _databaseVersion, onCreate: _onCreate);
|
||||
}
|
||||
|
||||
Future _onCreate(Database db, int version) async {
|
||||
await db.execute('''
|
||||
CREATE TABLE $table (
|
||||
$columnId INTEGER PRIMARY KEY NOT NULL,
|
||||
$columnName TEXT NOT NULL,
|
||||
$columnOwnerID INTEGER NOT NULL,
|
||||
$columnDeviceFolder TEXT NOT NULL,
|
||||
$columnSharedWith TEXT NOT NULL,
|
||||
$columnUpdationTime INTEGER NOT NULL,
|
||||
UNIQUE($columnOwnerID, $columnDeviceFolder)
|
||||
)
|
||||
''');
|
||||
}
|
||||
|
||||
Future<int> putFolder(Folder folder) async {
|
||||
final db = await instance.database;
|
||||
return await db.insert(table, _getRowForFolder(folder),
|
||||
conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
}
|
||||
|
||||
Future<List<Folder>> getFolders() async {
|
||||
final db = await instance.database;
|
||||
final results = await db.query(
|
||||
table,
|
||||
orderBy: '$columnUpdationTime DESC',
|
||||
);
|
||||
return _convertToFolders(results);
|
||||
}
|
||||
|
||||
Future<int> deleteFolder(Folder folder) async {
|
||||
final db = await instance.database;
|
||||
return db.delete(
|
||||
table,
|
||||
where: '$columnId =?',
|
||||
whereArgs: [folder.id],
|
||||
);
|
||||
}
|
||||
|
||||
List<Folder> _convertToFolders(List<Map<String, dynamic>> results) {
|
||||
final folders = List<Folder>();
|
||||
for (final result in results) {
|
||||
folders.add(_getFolderFromRow(result));
|
||||
}
|
||||
return folders;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _getRowForFolder(Folder folder) {
|
||||
final row = new Map<String, dynamic>();
|
||||
row[columnId] = folder.id;
|
||||
row[columnName] = folder.name;
|
||||
row[columnOwnerID] = folder.ownerID;
|
||||
row[columnDeviceFolder] = folder.deviceFolder;
|
||||
row[columnSharedWith] = jsonEncode(folder.sharedWith.toList());
|
||||
row[columnUpdationTime] = folder.updationTime;
|
||||
return row;
|
||||
}
|
||||
|
||||
Folder _getFolderFromRow(Map<String, dynamic> row) {
|
||||
return Folder(
|
||||
row[columnId],
|
||||
row[columnName],
|
||||
row[columnOwnerID],
|
||||
row[columnDeviceFolder],
|
||||
(jsonDecode(row[columnSharedWith]) as List<dynamic>).cast<int>().toSet(),
|
||||
row[columnUpdationTime],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:photos/models/file.dart';
|
||||
|
||||
class Folder {
|
||||
final int id;
|
||||
final String name;
|
||||
final int ownerID;
|
||||
final String deviceFolder;
|
||||
final Set<int> sharedWith;
|
||||
final int updationTime;
|
||||
File thumbnailPhoto;
|
||||
|
||||
Folder(
|
||||
this.id,
|
||||
this.name,
|
||||
this.ownerID,
|
||||
this.deviceFolder,
|
||||
this.sharedWith,
|
||||
this.updationTime,
|
||||
);
|
||||
|
||||
static Folder fromMap(Map<String, dynamic> map) {
|
||||
if (map == null) return null;
|
||||
|
||||
return Folder(
|
||||
map['id'],
|
||||
map['name'],
|
||||
map['ownerID'],
|
||||
map['deviceFolder'],
|
||||
Set<int>.from(map['sharedWith']),
|
||||
map['updationTime'],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Folder(id: $id, name: $name, ownerID: $ownerID, deviceFolder: $deviceFolder, sharedWith: $sharedWith, updationTime: $updationTime)';
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'ownerID': ownerID,
|
||||
'deviceFolder': deviceFolder,
|
||||
'sharedWith': sharedWith.toList(),
|
||||
'updationTime': updationTime,
|
||||
};
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
static Folder fromJson(String source) => fromMap(json.decode(source));
|
||||
|
||||
@override
|
||||
bool operator ==(Object o) {
|
||||
if (identical(this, o)) return true;
|
||||
|
||||
return o is Folder && o.id == id;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return id.hashCode;
|
||||
}
|
||||
}
|
|
@ -18,7 +18,6 @@ import 'package:photos/ui/gallery_app_bar_widget.dart';
|
|||
import 'package:photos/ui/loading_photos_widget.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:photos/ui/memories_widget.dart';
|
||||
import 'package:photos/ui/remote_folder_gallery_widget.dart';
|
||||
import 'package:photos/ui/search_page.dart';
|
||||
import 'package:photos/services/user_service.dart';
|
||||
import 'package:photos/ui/shared_collections_gallery.dart';
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/db/folders_db.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/events/remote_sync_event.dart';
|
||||
import 'package:photos/models/folder.dart';
|
||||
import 'package:photos/ui/common_elements.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:photos/ui/remote_folder_page.dart';
|
||||
import 'package:photos/ui/thumbnail_widget.dart';
|
||||
|
||||
class RemoteFolderGalleryWidget extends StatefulWidget {
|
||||
const RemoteFolderGalleryWidget({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_RemoteFolderGalleryWidgetState createState() =>
|
||||
_RemoteFolderGalleryWidgetState();
|
||||
}
|
||||
|
||||
class _RemoteFolderGalleryWidgetState extends State<RemoteFolderGalleryWidget> {
|
||||
Logger _logger = Logger("RemoteFolderGalleryWidget");
|
||||
StreamSubscription<RemoteSyncEvent> _subscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_subscription = Bus.instance.on<RemoteSyncEvent>().listen((event) {
|
||||
if (event.success) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<List<Folder>>(
|
||||
future: _getRemoteFolders(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
if (snapshot.data.isEmpty) {
|
||||
return nothingToSeeHere;
|
||||
} else {
|
||||
return _getRemoteFolderGalleryWidget(snapshot.data);
|
||||
}
|
||||
} else if (snapshot.hasError) {
|
||||
_logger.shout(snapshot.error);
|
||||
return Center(child: Text(snapshot.error.toString()));
|
||||
} else {
|
||||
return loadWidget;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getRemoteFolderGalleryWidget(List<Folder> folders) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 24),
|
||||
child: GridView.builder(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.only(bottom: 12),
|
||||
physics: ScrollPhysics(), // to disable GridView's scrolling
|
||||
itemBuilder: (context, index) {
|
||||
return _buildFolder(context, folders[index]);
|
||||
},
|
||||
itemCount: folders.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<Folder>> _getRemoteFolders() async {
|
||||
final folders = await FoldersDB.instance.getFolders();
|
||||
final filteredFolders = List<Folder>();
|
||||
for (final folder in folders) {
|
||||
if (folder.ownerID == Configuration.instance.getUserID()) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
folder.thumbnailPhoto =
|
||||
await FilesDB.instance.getLatestFileInRemoteFolder(folder.id);
|
||||
} catch (e) {
|
||||
_logger.warning(e.toString());
|
||||
}
|
||||
filteredFolders.add(folder);
|
||||
}
|
||||
return filteredFolders;
|
||||
}
|
||||
|
||||
Widget _buildFolder(BuildContext context, Folder folder) {
|
||||
return GestureDetector(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: folder.thumbnailPhoto ==
|
||||
null // When the user has shared a folder without photos
|
||||
? Icon(Icons.error)
|
||||
: Hero(
|
||||
tag: "remote_folder" + folder.thumbnailPhoto.tag(),
|
||||
child: ThumbnailWidget(folder.thumbnailPhoto)),
|
||||
height: 150,
|
||||
width: 150,
|
||||
),
|
||||
Padding(padding: EdgeInsets.all(2)),
|
||||
Expanded(
|
||||
child: Text(
|
||||
folder.name,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
final page = RemoteFolderPage(folder);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return page;
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_subscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/models/folder.dart';
|
||||
import 'package:photos/models/selected_files.dart';
|
||||
import 'package:photos/ui/gallery.dart';
|
||||
import 'package:photos/ui/gallery_app_bar_widget.dart';
|
||||
|
||||
class RemoteFolderPage extends StatefulWidget {
|
||||
final Folder folder;
|
||||
|
||||
const RemoteFolderPage(this.folder, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_RemoteFolderPageState createState() => _RemoteFolderPageState();
|
||||
}
|
||||
|
||||
class _RemoteFolderPageState extends State<RemoteFolderPage> {
|
||||
final _selectedFiles = SelectedFiles();
|
||||
|
||||
@override
|
||||
Widget build(Object context) {
|
||||
var gallery = Gallery(
|
||||
asyncLoader: (lastFile, limit) => FilesDB.instance.getAllInFolder(
|
||||
widget.folder.id,
|
||||
lastFile == null
|
||||
? DateTime.now().microsecondsSinceEpoch
|
||||
: lastFile.creationTime,
|
||||
limit),
|
||||
// onRefresh: () => FolderSharingService.instance.syncDiff(widget.folder),
|
||||
tagPrefix: "remote_folder",
|
||||
selectedFiles: _selectedFiles,
|
||||
);
|
||||
return Scaffold(
|
||||
appBar: GalleryAppBarWidget(
|
||||
GalleryAppBarType.shared_collection,
|
||||
widget.folder.name,
|
||||
_selectedFiles,
|
||||
widget.folder.deviceFolder,
|
||||
),
|
||||
body: gallery,
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue