convenience for getImagePath and simplified logic in loadImage
This commit is contained in:
@@ -1011,7 +1011,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
let archiveURL = getArchiveURL(progress.v)
|
||||
imageLoader.loadImage(
|
||||
archiveURL: archiveURL,
|
||||
filename: getImagePath(progress: progress),
|
||||
filename: getImagePath(progress),
|
||||
scaling: .scaleAspectFit,
|
||||
screenSize: UIScreen.main.bounds.size
|
||||
) { [weak self] image in
|
||||
@@ -1155,18 +1155,18 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
}
|
||||
progress = newProgress
|
||||
updateInfo()
|
||||
let path = getImagePath(progress: progress)
|
||||
let path = getImagePath(progress)
|
||||
|
||||
imageLoader.setActiveWindow([path])
|
||||
|
||||
let archiveURL = getArchiveURL(progress.v)
|
||||
imageLoader.loadImage(archiveURL: archiveURL, filename: getImagePath(progress: progress), scaling: scaling, screenSize: UIScreen.main.bounds.size) { [weak self] image in
|
||||
imageLoader.loadImage(archiveURL: archiveURL, filename: getImagePath(progress), scaling: scaling, screenSize: UIScreen.main.bounds.size) { [weak self] image in
|
||||
self?.imageView.image = image
|
||||
}
|
||||
|
||||
for _ in 0 ..< preloadCount {
|
||||
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
||||
let filename = getImagePath(progress: newProgress)
|
||||
let filename = getImagePath(newProgress)
|
||||
let archiveURL = getArchiveURL(newProgress.v)
|
||||
imageLoader.preloadImage(archiveURL: archiveURL, filename: filename, scaling: scaling, screenSize: UIScreen.main.bounds.size)
|
||||
}
|
||||
@@ -1241,7 +1241,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
return currentPath.appendingPathComponent("volumes").appendingPathComponent(metadata.volumes[volumeProgress].archive)
|
||||
}
|
||||
|
||||
func getImagePath(progress: ProgressIndices) -> String {
|
||||
func getImagePath(_ progress: ProgressIndices) -> String {
|
||||
let (v, c, i) = (progress.v, progress.c, progress.i)
|
||||
let modernPath = metadata.volumes[v].chapters[c].images[i].filename!
|
||||
// if fileManager.fileExists(atPath: modernPath.path) {
|
||||
@@ -1295,7 +1295,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
let scaling: UIView.ContentMode = mode == .scroll ? .scaleAspectFill : .scaleAspectFit
|
||||
imageLoader.loadImage(
|
||||
archiveURL: getArchiveURL(progress.v),
|
||||
filename: getImagePath(progress: progress),
|
||||
filename: getImagePath(progress),
|
||||
scaling: scaling,
|
||||
screenSize: UIScreen.main.bounds.size
|
||||
) { [weak self] image in
|
||||
@@ -1306,7 +1306,12 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
var newProgress = progress
|
||||
for _ in 0 ..< preloadCount {
|
||||
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
||||
imageLoader.preloadImage(archiveURL: getArchiveURL(progress.v), filename: getImagePath(progress: newProgress), scaling: scaling, screenSize: UIScreen.main.bounds.size)
|
||||
imageLoader.preloadImage(
|
||||
archiveURL: getArchiveURL(progress.v),
|
||||
filename: getImagePath(newProgress),
|
||||
scaling: scaling,
|
||||
screenSize: UIScreen.main.bounds.size,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1326,7 +1331,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
if mode != .scroll {
|
||||
imageLoader.loadImage(
|
||||
archiveURL: getArchiveURL(progress.v),
|
||||
filename: getImagePath(progress: progress),
|
||||
filename: getImagePath(progress),
|
||||
scaling: .scaleAspectFit,
|
||||
screenSize: size
|
||||
) { image in
|
||||
@@ -1421,7 +1426,7 @@ extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFl
|
||||
}
|
||||
imageLoader.loadImage(
|
||||
archiveURL: getArchiveURL(progress.v),
|
||||
filename: getImagePath(progress: newProgress),
|
||||
filename: getImagePath(newProgress),
|
||||
scaling: scaling, screenSize: UIScreen.main.bounds.size) { image in
|
||||
cell.imageView.image = image
|
||||
}
|
||||
@@ -1585,16 +1590,12 @@ class ImageLoader {
|
||||
return
|
||||
}
|
||||
|
||||
if let existing = activeTokens[key], !existing.isCancelled {
|
||||
if let completion = completion {
|
||||
loadingTasks[key] = completion
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if let completion = completion {
|
||||
loadingTasks[key] = completion
|
||||
}
|
||||
if let existing = activeTokens[key], !existing.isCancelled {
|
||||
return
|
||||
}
|
||||
|
||||
let token = CancellationToken()
|
||||
activeTokens[key] = token
|
||||
|
||||
Reference in New Issue
Block a user