Preload the next memory
This commit is contained in:
parent
9f91c83f77
commit
590c72f2e5
3 changed files with 29 additions and 22 deletions
|
@ -106,30 +106,10 @@ class _DetailPageState extends State<DetailPage> {
|
|||
|
||||
void _preloadFiles(int index) {
|
||||
if (index > 0) {
|
||||
_preloadFile(_files[index - 1]);
|
||||
preloadFile(_files[index - 1]);
|
||||
}
|
||||
if (index < _files.length - 1) {
|
||||
_preloadFile(_files[index + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
void _preloadFile(File file) {
|
||||
if (file.fileType == FileType.video) {
|
||||
return;
|
||||
}
|
||||
if (file.localId == null) {
|
||||
file.getBytes().then((data) {
|
||||
BytesLruCache.put(file, data);
|
||||
});
|
||||
} else {
|
||||
final cachedFile = FileLruCache.get(file);
|
||||
if (cachedFile == null) {
|
||||
file.getAsset().then((asset) {
|
||||
asset.file.then((assetFile) {
|
||||
FileLruCache.put(file, assetFile);
|
||||
});
|
||||
});
|
||||
}
|
||||
preloadFile(_files[index + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:photos/ui/thumbnail_widget.dart';
|
|||
import 'package:photos/ui/video_widget.dart';
|
||||
import 'package:photos/ui/zoomable_image.dart';
|
||||
import 'package:photos/utils/date_time_util.dart';
|
||||
import 'package:photos/utils/file_util.dart';
|
||||
import 'package:photos/utils/share_util.dart';
|
||||
|
||||
class MemoriesWidget extends StatefulWidget {
|
||||
|
@ -283,6 +284,9 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
|
|||
setState(() {
|
||||
_index = index;
|
||||
});
|
||||
if (index < widget.memories.length - 1) {
|
||||
preloadFile(widget.memories[index + 1].file);
|
||||
}
|
||||
return index;
|
||||
},
|
||||
);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import 'package:photo_manager/photo_manager.dart';
|
||||
import 'package:photos/core/cache/image_cache.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/file_type.dart';
|
||||
|
||||
Future<void> deleteFiles(List<File> files,
|
||||
{bool deleteEveryWhere = false}) async {
|
||||
|
@ -12,3 +14,24 @@ Future<void> deleteFiles(List<File> files,
|
|||
: await FilesDB.instance.delete(file);
|
||||
}
|
||||
}
|
||||
|
||||
void preloadFile(File file) {
|
||||
if (file.fileType == FileType.video) {
|
||||
return;
|
||||
}
|
||||
if (file.localId == null) {
|
||||
if (BytesLruCache.get(file) == null) {
|
||||
file.getBytes().then((data) {
|
||||
BytesLruCache.put(file, data);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (FileLruCache.get(file) == null) {
|
||||
file.getAsset().then((asset) {
|
||||
asset.file.then((assetFile) {
|
||||
FileLruCache.put(file, assetFile);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue