mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-25 13:12:16 +03:00
On disk we are only caching the full-size images.
So when modify the key to query for the full size image, because scaling down a larger size image on the device is quicker than requesting the down-sized image from the network.
This commit is contained in:
parent
78cb4d09cf
commit
3c554caf2e
@ -57,6 +57,8 @@ public class FileUtil
|
||||
private static final List<String> VIDEO_FILE_EXTENSIONS = Arrays.asList("flv", "mp4", "m4v", "wmv", "avi", "mov", "mpg", "mkv");
|
||||
private static final List<String> PLAYLIST_FILE_EXTENSIONS = Collections.singletonList("m3u");
|
||||
private static final Pattern TITLE_WITH_TRACK = Pattern.compile("^\\d\\d-.*");
|
||||
public static final String SUFFIX_LARGE = ".jpeg";
|
||||
public static final String SUFFIX_SMALL = ".jpeg-small";
|
||||
|
||||
private static final Lazy<PermissionUtil> permissionUtil = inject(PermissionUtil.class);
|
||||
|
||||
@ -141,7 +143,9 @@ public class FileUtil
|
||||
return null;
|
||||
}
|
||||
|
||||
return String.format(Locale.ROOT, "%s%b.jpeg", Util.md5Hex(albumDir.getPath()), large);
|
||||
String suffix = (large) ? SUFFIX_LARGE : SUFFIX_SMALL;
|
||||
|
||||
return String.format(Locale.ROOT, "%s%s", Util.md5Hex(albumDir.getPath()), suffix);
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,6 +7,8 @@ import com.squareup.picasso.RequestHandler
|
||||
import java.io.IOException
|
||||
import okio.Okio
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
|
||||
import org.moire.ultrasonic.util.FileUtil.SUFFIX_LARGE
|
||||
import org.moire.ultrasonic.util.FileUtil.SUFFIX_SMALL
|
||||
|
||||
/**
|
||||
* Loads cover arts from subsonic api.
|
||||
@ -25,16 +27,23 @@ class CoverArtRequestHandler(private val apiClient: SubsonicAPIClient) : Request
|
||||
val size = request.uri.getQueryParameter(SIZE)?.toLong()
|
||||
|
||||
// Check if we have a hit in the disk cache
|
||||
val cache = BitmapUtils.getAlbumArtBitmapFromDisk(request.stableKey!!, size?.toInt())
|
||||
// Note: Currently we are only caching full size images on disk
|
||||
// So we modify the key to query for the full size image,
|
||||
// because scaling down a larger size image on the device is quicker than
|
||||
// requesting the down-sized image from the network.
|
||||
val key = request.stableKey!!.replace(SUFFIX_SMALL, SUFFIX_LARGE)
|
||||
val cache = BitmapUtils.getAlbumArtBitmapFromDisk(key, size?.toInt())
|
||||
if (cache != null) {
|
||||
return Result(cache, DISK)
|
||||
}
|
||||
|
||||
// Try to fetch the image from the API
|
||||
val response = apiClient.getCoverArt(id, size)
|
||||
if (response.hasError() || response.stream == null) {
|
||||
throw IOException("${response.apiError}")
|
||||
} else {
|
||||
if (!response.hasError() && response.stream != null) {
|
||||
return Result(Okio.source(response.stream!!), NETWORK)
|
||||
}
|
||||
|
||||
// Throw an error if still not successful
|
||||
throw IOException("${response.apiError}")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user