Rename DBHelper
This commit is contained in:
parent
1c361f7045
commit
496e1d2f81
6 changed files with 17 additions and 18 deletions
|
@ -5,7 +5,7 @@ import 'package:path/path.dart';
|
|||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class DatabaseHelper {
|
||||
class PhotoDB {
|
||||
static final _databaseName = "ente.db";
|
||||
static final _databaseVersion = 1;
|
||||
|
||||
|
@ -22,8 +22,8 @@ class DatabaseHelper {
|
|||
static final columnSyncTimestamp = 'sync_timestamp';
|
||||
|
||||
// make this a singleton class
|
||||
DatabaseHelper._privateConstructor();
|
||||
static final DatabaseHelper instance = DatabaseHelper._privateConstructor();
|
||||
PhotoDB._privateConstructor();
|
||||
static final PhotoDB instance = PhotoDB._privateConstructor();
|
||||
|
||||
// only have a single app-wide reference to the database
|
||||
static Database _database;
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/db/db_helper.dart';
|
||||
import 'package:photos/db/photo_db.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import 'package:photos/models/face.dart';
|
||||
|
@ -37,7 +37,7 @@ class FaceSearchManager {
|
|||
headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||
)
|
||||
.then((response) => (response.data["results"] as List)
|
||||
.map((result) => (DatabaseHelper.instance.getPhotoByPath(result))));
|
||||
.map((result) => (PhotoDB.instance.getPhotoByPath(result))));
|
||||
return Future.wait(await futures);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/db/db_helper.dart';
|
||||
import 'package:photos/db/photo_db.dart';
|
||||
import 'package:photos/events/local_photos_updated_event.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
|
||||
|
@ -16,7 +16,7 @@ class PhotoRepository {
|
|||
}
|
||||
|
||||
Future<bool> loadPhotos() async {
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
PhotoDB db = PhotoDB.instance;
|
||||
var photos = await db.getAllPhotos();
|
||||
|
||||
_photos.clear();
|
||||
|
|
|
@ -4,7 +4,7 @@ import 'dart:math';
|
|||
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/db/db_helper.dart';
|
||||
import 'package:photos/db/photo_db.dart';
|
||||
import 'package:photos/events/user_authenticated_event.dart';
|
||||
import 'package:photos/photo_repository.dart';
|
||||
import 'package:photos/photo_provider.dart';
|
||||
|
@ -20,7 +20,7 @@ import 'package:photos/events/remote_sync_event.dart';
|
|||
class PhotoSyncManager {
|
||||
final _logger = Logger("PhotoSyncManager");
|
||||
final _dio = Dio();
|
||||
final _db = DatabaseHelper.instance;
|
||||
final _db = PhotoDB.instance;
|
||||
bool _isSyncInProgress = false;
|
||||
|
||||
static final _lastSyncTimestampKey = "last_sync_timestamp_0";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:photos/db/db_helper.dart';
|
||||
import 'package:photos/db/photo_db.dart';
|
||||
import 'package:photos/favorite_photos_repository.dart';
|
||||
import 'package:photos/models/device_folder.dart';
|
||||
import 'package:photos/models/filters/favorite_items_filter.dart';
|
||||
|
@ -57,10 +57,10 @@ class _DeviceFolderGalleryWidgetState extends State<DeviceFolderGalleryWidget> {
|
|||
}
|
||||
|
||||
Future<List<DeviceFolder>> _getDeviceFolders() async {
|
||||
final paths = await DatabaseHelper.instance.getDistinctPaths();
|
||||
final paths = await PhotoDB.instance.getDistinctPaths();
|
||||
final folders = List<DeviceFolder>();
|
||||
for (final path in paths) {
|
||||
final photo = await DatabaseHelper.instance.getLatestPhotoInPath(path);
|
||||
final photo = await PhotoDB.instance.getLatestPhotoInPath(path);
|
||||
final folderName = p.basename(path);
|
||||
folders
|
||||
.add(DeviceFolder(folderName, photo, FolderNameFilter(folderName)));
|
||||
|
@ -70,9 +70,8 @@ class _DeviceFolderGalleryWidgetState extends State<DeviceFolderGalleryWidget> {
|
|||
.compareTo(first.thumbnailPhoto.createTimestamp);
|
||||
});
|
||||
if (FavoritePhotosRepository.instance.hasFavorites()) {
|
||||
final photo = await DatabaseHelper.instance
|
||||
.getLatestPhotoAmongGeneratedIds(
|
||||
FavoritePhotosRepository.instance.getLiked().toList());
|
||||
final photo = await PhotoDB.instance.getLatestPhotoAmongGeneratedIds(
|
||||
FavoritePhotosRepository.instance.getLiked().toList());
|
||||
folders.insert(
|
||||
0, DeviceFolder("Favorites", photo, FavoriteItemsFilter()));
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/db/db_helper.dart';
|
||||
import 'package:photos/db/photo_db.dart';
|
||||
import 'package:photos/events/remote_sync_event.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
import 'package:photos/photo_repository.dart';
|
||||
|
@ -153,8 +153,8 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
|
||||
for (Photo photo in widget.selectedPhotos) {
|
||||
deleteEverywhere
|
||||
? await DatabaseHelper.instance.markPhotoForDeletion(photo)
|
||||
: await DatabaseHelper.instance.deletePhoto(photo);
|
||||
? await PhotoDB.instance.markPhotoForDeletion(photo)
|
||||
: await PhotoDB.instance.deletePhoto(photo);
|
||||
}
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
PhotoRepository.instance.reloadPhotos();
|
||||
|
|
Loading…
Add table
Reference in a new issue