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