#326 date added sourced from Media Store
This commit is contained in:
parent
7b95f37171
commit
a86cbfa6eb
9 changed files with 19 additions and 25 deletions
|
@ -41,6 +41,7 @@ class SourceEntry {
|
||||||
var height: Int? = null
|
var height: Int? = null
|
||||||
private var sourceRotationDegrees: Int? = null
|
private var sourceRotationDegrees: Int? = null
|
||||||
private var sizeBytes: Long? = null
|
private var sizeBytes: Long? = null
|
||||||
|
private var dateAddedSecs: Long? = null
|
||||||
private var dateModifiedSecs: Long? = null
|
private var dateModifiedSecs: Long? = null
|
||||||
private var sourceDateTakenMillis: Long? = null
|
private var sourceDateTakenMillis: Long? = null
|
||||||
private var durationMillis: Long? = null
|
private var durationMillis: Long? = null
|
||||||
|
@ -61,6 +62,7 @@ class SourceEntry {
|
||||||
sourceRotationDegrees = map["sourceRotationDegrees"] as Int?
|
sourceRotationDegrees = map["sourceRotationDegrees"] as Int?
|
||||||
sizeBytes = toLong(map["sizeBytes"])
|
sizeBytes = toLong(map["sizeBytes"])
|
||||||
title = map["title"] as String?
|
title = map["title"] as String?
|
||||||
|
dateAddedSecs = toLong(map["dateAddedSecs"])
|
||||||
dateModifiedSecs = toLong(map["dateModifiedSecs"])
|
dateModifiedSecs = toLong(map["dateModifiedSecs"])
|
||||||
sourceDateTakenMillis = toLong(map["sourceDateTakenMillis"])
|
sourceDateTakenMillis = toLong(map["sourceDateTakenMillis"])
|
||||||
durationMillis = toLong(map["durationMillis"])
|
durationMillis = toLong(map["durationMillis"])
|
||||||
|
@ -83,6 +85,7 @@ class SourceEntry {
|
||||||
"sourceRotationDegrees" to (sourceRotationDegrees ?: 0),
|
"sourceRotationDegrees" to (sourceRotationDegrees ?: 0),
|
||||||
"sizeBytes" to sizeBytes,
|
"sizeBytes" to sizeBytes,
|
||||||
"title" to title,
|
"title" to title,
|
||||||
|
"dateAddedSecs" to dateAddedSecs,
|
||||||
"dateModifiedSecs" to dateModifiedSecs,
|
"dateModifiedSecs" to dateModifiedSecs,
|
||||||
"sourceDateTakenMillis" to sourceDateTakenMillis,
|
"sourceDateTakenMillis" to sourceDateTakenMillis,
|
||||||
"durationMillis" to durationMillis,
|
"durationMillis" to durationMillis,
|
||||||
|
|
|
@ -22,7 +22,12 @@ internal class FileImageProvider : ImageProvider() {
|
||||||
try {
|
try {
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
entry.initFromFile(path, file.name, file.length(), file.lastModified() / 1000)
|
entry.initFromFile(
|
||||||
|
path = path,
|
||||||
|
title = file.name,
|
||||||
|
sizeBytes = file.length(),
|
||||||
|
dateModifiedSecs = file.lastModified() / 1000,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} catch (e: SecurityException) {
|
} catch (e: SecurityException) {
|
||||||
callback.onFailure(e)
|
callback.onFailure(e)
|
||||||
|
|
|
@ -86,7 +86,7 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
val alwaysValid: NewEntryChecker = fun(_: Int, _: Int): Boolean = true
|
val alwaysValid: NewEntryChecker = fun(_: Int, _: Int): Boolean = true
|
||||||
val onSuccess: NewEntryHandler = fun(entry: FieldMap) { fetched.add(entry) }
|
val onSuccess: NewEntryHandler = fun(entry: FieldMap) { fetched.add(entry) }
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
if (!found && (sourceMimeType == null || isImage(sourceMimeType))) {
|
if (sourceMimeType == null || isImage(sourceMimeType)) {
|
||||||
val contentUri = ContentUris.withAppendedId(IMAGE_CONTENT_URI, id)
|
val contentUri = ContentUris.withAppendedId(IMAGE_CONTENT_URI, id)
|
||||||
found = fetchFrom(context, alwaysValid, onSuccess, contentUri, IMAGE_PROJECTION)
|
found = fetchFrom(context, alwaysValid, onSuccess, contentUri, IMAGE_PROJECTION)
|
||||||
}
|
}
|
||||||
|
@ -189,6 +189,7 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
val sizeColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE)
|
val sizeColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE)
|
||||||
val widthColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.WIDTH)
|
val widthColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.WIDTH)
|
||||||
val heightColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.HEIGHT)
|
val heightColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.HEIGHT)
|
||||||
|
val dateAddedColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_ADDED)
|
||||||
val dateModifiedColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED)
|
val dateModifiedColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED)
|
||||||
val dateTakenColumn = cursor.getColumnIndex(MediaColumns.DATE_TAKEN)
|
val dateTakenColumn = cursor.getColumnIndex(MediaColumns.DATE_TAKEN)
|
||||||
|
|
||||||
|
@ -224,6 +225,7 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
"height" to height,
|
"height" to height,
|
||||||
"sourceRotationDegrees" to if (orientationColumn != -1) cursor.getInt(orientationColumn) else 0,
|
"sourceRotationDegrees" to if (orientationColumn != -1) cursor.getInt(orientationColumn) else 0,
|
||||||
"sizeBytes" to cursor.getLong(sizeColumn),
|
"sizeBytes" to cursor.getLong(sizeColumn),
|
||||||
|
"dateAddedSecs" to cursor.getInt(dateAddedColumn),
|
||||||
"dateModifiedSecs" to dateModifiedSecs,
|
"dateModifiedSecs" to dateModifiedSecs,
|
||||||
"sourceDateTakenMillis" to if (dateTakenColumn != -1) cursor.getLong(dateTakenColumn) else null,
|
"sourceDateTakenMillis" to if (dateTakenColumn != -1) cursor.getLong(dateTakenColumn) else null,
|
||||||
"durationMillis" to durationMillis,
|
"durationMillis" to durationMillis,
|
||||||
|
@ -789,6 +791,7 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
|
|
||||||
// we retrieve updated fields as the renamed/moved file became a new entry in the Media Store
|
// we retrieve updated fields as the renamed/moved file became a new entry in the Media Store
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
|
MediaStore.MediaColumns.DATE_ADDED,
|
||||||
MediaStore.MediaColumns.DATE_MODIFIED,
|
MediaStore.MediaColumns.DATE_MODIFIED,
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
|
@ -798,6 +801,7 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
newFields["uri"] = uri.toString()
|
newFields["uri"] = uri.toString()
|
||||||
newFields["contentId"] = uri.tryParseId()
|
newFields["contentId"] = uri.tryParseId()
|
||||||
newFields["path"] = path
|
newFields["path"] = path
|
||||||
|
cursor.getColumnIndex(MediaStore.MediaColumns.DATE_ADDED).let { if (it != -1) newFields["dateAddedSecs"] = cursor.getInt(it) }
|
||||||
cursor.getColumnIndex(MediaStore.MediaColumns.DATE_MODIFIED).let { if (it != -1) newFields["dateModifiedSecs"] = cursor.getInt(it) }
|
cursor.getColumnIndex(MediaStore.MediaColumns.DATE_MODIFIED).let { if (it != -1) newFields["dateModifiedSecs"] = cursor.getInt(it) }
|
||||||
cursor.close()
|
cursor.close()
|
||||||
return newFields
|
return newFields
|
||||||
|
@ -871,6 +875,7 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
MediaStore.MediaColumns.SIZE,
|
MediaStore.MediaColumns.SIZE,
|
||||||
MediaStore.MediaColumns.WIDTH,
|
MediaStore.MediaColumns.WIDTH,
|
||||||
MediaStore.MediaColumns.HEIGHT,
|
MediaStore.MediaColumns.HEIGHT,
|
||||||
|
MediaStore.MediaColumns.DATE_ADDED,
|
||||||
MediaStore.MediaColumns.DATE_MODIFIED,
|
MediaStore.MediaColumns.DATE_MODIFIED,
|
||||||
MediaColumns.DATE_TAKEN,
|
MediaColumns.DATE_TAKEN,
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,8 +10,6 @@ import 'package:aves/model/video_playback.dart';
|
||||||
abstract class MetadataDb {
|
abstract class MetadataDb {
|
||||||
int get nextId;
|
int get nextId;
|
||||||
|
|
||||||
int get timestampSecs;
|
|
||||||
|
|
||||||
Future<void> init();
|
Future<void> init();
|
||||||
|
|
||||||
Future<int> dbFileSize();
|
Future<int> dbFileSize();
|
||||||
|
|
|
@ -34,9 +34,6 @@ class SqfliteMetadataDb implements MetadataDb {
|
||||||
@override
|
@override
|
||||||
int get nextId => ++_lastId;
|
int get nextId => ++_lastId;
|
||||||
|
|
||||||
@override
|
|
||||||
int get timestampSecs => DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
_db = await openDatabase(
|
_db = await openDatabase(
|
||||||
|
|
|
@ -150,6 +150,7 @@ class AvesEntry {
|
||||||
'sourceRotationDegrees': sourceRotationDegrees,
|
'sourceRotationDegrees': sourceRotationDegrees,
|
||||||
'sizeBytes': sizeBytes,
|
'sizeBytes': sizeBytes,
|
||||||
'title': sourceTitle,
|
'title': sourceTitle,
|
||||||
|
'dateAddedSecs': dateAddedSecs,
|
||||||
'dateModifiedSecs': dateModifiedSecs,
|
'dateModifiedSecs': dateModifiedSecs,
|
||||||
'sourceDateTakenMillis': sourceDateTakenMillis,
|
'sourceDateTakenMillis': sourceDateTakenMillis,
|
||||||
'durationMillis': durationMillis,
|
'durationMillis': durationMillis,
|
||||||
|
|
|
@ -310,7 +310,7 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM
|
||||||
contentId: newFields['contentId'] as int?,
|
contentId: newFields['contentId'] as int?,
|
||||||
// title can change when moved files are automatically renamed to avoid conflict
|
// title can change when moved files are automatically renamed to avoid conflict
|
||||||
title: newFields['title'] as String?,
|
title: newFields['title'] as String?,
|
||||||
dateAddedSecs: metadataDb.timestampSecs,
|
dateAddedSecs: newFields['dateAddedSecs'] as int?,
|
||||||
dateModifiedSecs: newFields['dateModifiedSecs'] as int?,
|
dateModifiedSecs: newFields['dateModifiedSecs'] as int?,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -159,13 +159,7 @@ class MediaStoreSource extends CollectionSource {
|
||||||
// reuse known entry ID to overwrite it while preserving favourites, etc.
|
// reuse known entry ID to overwrite it while preserving favourites, etc.
|
||||||
final contentId = entry.contentId;
|
final contentId = entry.contentId;
|
||||||
final existingEntry = knownContentIds.contains(contentId) ? knownLiveEntries.firstWhereOrNull((entry) => entry.contentId == contentId) : null;
|
final existingEntry = knownContentIds.contains(contentId) ? knownLiveEntries.firstWhereOrNull((entry) => entry.contentId == contentId) : null;
|
||||||
if (existingEntry != null) {
|
entry.id = existingEntry?.id ?? metadataDb.nextId;
|
||||||
entry.id = existingEntry.id;
|
|
||||||
entry.dateAddedSecs = existingEntry.dateAddedSecs;
|
|
||||||
} else {
|
|
||||||
entry.id = metadataDb.nextId;
|
|
||||||
entry.dateAddedSecs = metadataDb.timestampSecs;
|
|
||||||
}
|
|
||||||
|
|
||||||
pendingNewEntries.add(entry);
|
pendingNewEntries.add(entry);
|
||||||
if (pendingNewEntries.length >= refreshCount) {
|
if (pendingNewEntries.length >= refreshCount) {
|
||||||
|
@ -250,13 +244,7 @@ class MediaStoreSource extends CollectionSource {
|
||||||
final newPath = sourceEntry.path;
|
final newPath = sourceEntry.path;
|
||||||
final volume = newPath != null ? androidFileUtils.getStorageVolume(newPath) : null;
|
final volume = newPath != null ? androidFileUtils.getStorageVolume(newPath) : null;
|
||||||
if (volume != null) {
|
if (volume != null) {
|
||||||
if (existingEntry != null) {
|
sourceEntry.id = existingEntry?.id ?? metadataDb.nextId;
|
||||||
sourceEntry.id = existingEntry.id;
|
|
||||||
sourceEntry.dateAddedSecs = existingEntry.dateAddedSecs;
|
|
||||||
} else {
|
|
||||||
sourceEntry.id = metadataDb.nextId;
|
|
||||||
sourceEntry.dateAddedSecs = metadataDb.timestampSecs;
|
|
||||||
}
|
|
||||||
newEntries.add(sourceEntry);
|
newEntries.add(sourceEntry);
|
||||||
final existingDirectory = existingEntry?.directory;
|
final existingDirectory = existingEntry?.directory;
|
||||||
if (existingDirectory != null) {
|
if (existingDirectory != null) {
|
||||||
|
|
|
@ -15,9 +15,6 @@ class FakeMetadataDb extends Fake implements MetadataDb {
|
||||||
@override
|
@override
|
||||||
int get nextId => ++_lastId;
|
int get nextId => ++_lastId;
|
||||||
|
|
||||||
@override
|
|
||||||
int get timestampSecs => DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> init() => SynchronousFuture(null);
|
Future<void> init() => SynchronousFuture(null);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue