Minor refactoring
This commit is contained in:
parent
acffc4f269
commit
82fa67ef9e
3 changed files with 21 additions and 19 deletions
8
lib/core/cache/image_cache.dart
vendored
8
lib/core/cache/image_cache.dart
vendored
|
@ -6,11 +6,11 @@ import 'package:photos/models/file.dart';
|
|||
class FileLruCache {
|
||||
static final LRUMap<String, io.File> _map = LRUMap(25);
|
||||
|
||||
static io.File get(File file) {
|
||||
return _map.get(file.tag());
|
||||
static io.File get(String key) {
|
||||
return _map.get(key);
|
||||
}
|
||||
|
||||
static void put(File file, io.File imageData) {
|
||||
_map.put(file.tag(), imageData);
|
||||
static void put(String key, io.File imageData) {
|
||||
_map.put(key, imageData);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ class _ZoomableLiveImageState extends State<ZoomableLiveImage>
|
|||
} else {
|
||||
_loadLocalImage(context);
|
||||
}
|
||||
_loadLiveVide();
|
||||
_loadLiveVideo();
|
||||
if (_imageProvider != null) {
|
||||
Widget content;
|
||||
if (_loadLivePhotoVideo && _videoPlayerController != null
|
||||
|
@ -146,15 +146,15 @@ class _ZoomableLiveImageState extends State<ZoomableLiveImage>
|
|||
return Chewie(controller: _chewieController);
|
||||
}
|
||||
|
||||
void _loadLiveVide() {
|
||||
void _loadLiveVideo() {
|
||||
if (_videoPlayerController != null) {
|
||||
return ;
|
||||
}
|
||||
getLiveVideo(widget.photo).then((file) {
|
||||
getFile(widget.photo, liveVideo: true).then((file) {
|
||||
if (file != null && file.existsSync()) {
|
||||
_logger.fine("loading live from local");
|
||||
_setVideoPlayerController(file: file);
|
||||
} else {
|
||||
} else if (widget.photo.uploadedFileID != null) {
|
||||
_logger.fine("loading live from remote");
|
||||
getFileFromServer(widget.photo, liveVideo: true).then((file) {
|
||||
if (file != null && file.existsSync()) {
|
||||
|
|
|
@ -27,31 +27,33 @@ void preloadFile(ente.File file) {
|
|||
getFile(file);
|
||||
}
|
||||
|
||||
Future<io.File> getFile(ente.File file) async {
|
||||
Future<io.File> getFile(ente.File file,
|
||||
{bool liveVideo = false} // only relevant for live photos
|
||||
) async {
|
||||
if (file.isRemoteFile()) {
|
||||
return getFileFromServer(file);
|
||||
return getFileFromServer(file, liveVideo: liveVideo);
|
||||
} else {
|
||||
final cachedFile = FileLruCache.get(file);
|
||||
String key = file.tag() + liveVideo.toString();
|
||||
final cachedFile = FileLruCache.get(key);
|
||||
if (cachedFile == null) {
|
||||
final diskFile = await _getLocalDiskFile(file);
|
||||
FileLruCache.put(file, diskFile);
|
||||
final diskFile = await _getLocalDiskFile(file, liveVideo: liveVideo);
|
||||
FileLruCache.put(key, diskFile);
|
||||
return diskFile;
|
||||
}
|
||||
return cachedFile;
|
||||
}
|
||||
}
|
||||
|
||||
Future<io.File> getLiveVideo(ente.File file) async {
|
||||
return Motionphoto.getLivePhotoFile(file.localID);
|
||||
}
|
||||
|
||||
Future<io.File> _getLocalDiskFile(ente.File file) async {
|
||||
Future<io.File> _getLocalDiskFile(ente.File file, {bool liveVideo = false}) async {
|
||||
if (file.isSharedMediaToAppSandbox()) {
|
||||
var localFile = io.File(getSharedMediaFilePath(file));
|
||||
return localFile.exists().then((exist) {
|
||||
return exist ? localFile : null;
|
||||
});
|
||||
} else {
|
||||
} else if (file.fileType == FileType.livePhoto && liveVideo) {
|
||||
return Motionphoto.getLivePhotoFile(file.localID);
|
||||
}
|
||||
else {
|
||||
return file.getAsset().then((asset) async {
|
||||
if (asset == null || !(await asset.exists)) {
|
||||
return null;
|
||||
|
|
Loading…
Add table
Reference in a new issue