feat: reintroduce scrolling
This commit is contained in:
@@ -59,8 +59,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
var scrollPos: CGPoint!
|
var scrollPos: CGPoint!
|
||||||
var hasSetContentOffset = false
|
var hasSetContentOffset = false
|
||||||
var pageCount = 0
|
var pageCount = 0
|
||||||
var pagesAvailable = 0
|
|
||||||
var chapterAndPages: [(Int, Int)] = []
|
|
||||||
|
|
||||||
var imageView = UIImageView()
|
var imageView = UIImageView()
|
||||||
var mode = PageTurnMode.leftToRight
|
var mode = PageTurnMode.leftToRight
|
||||||
@@ -136,9 +134,9 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
readerView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
readerView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||||
readerView.widthAnchor.constraint(equalTo: view.widthAnchor),
|
readerView.widthAnchor.constraint(equalTo: view.widthAnchor),
|
||||||
])
|
])
|
||||||
|
setupScrollingCollectionView()
|
||||||
loadComics()
|
loadComics()
|
||||||
setupImageView()
|
setupImageView()
|
||||||
setupScrollingCollectionView()
|
|
||||||
setupGestures()
|
setupGestures()
|
||||||
setupBar()
|
setupBar()
|
||||||
setupHomeView()
|
setupHomeView()
|
||||||
@@ -594,7 +592,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
}
|
}
|
||||||
if let indexPath = scrollingCollectionView.indexPathForItem(at: scrollOffset) {
|
if let indexPath = scrollingCollectionView.indexPathForItem(at: scrollOffset) {
|
||||||
var theProgress = ProgressIndices(v: 0, c: 0, i: 0)
|
var theProgress = ProgressIndices(v: 0, c: 0, i: 0)
|
||||||
for _ in 0 ... indexPath.item {
|
for _ in 0 ..< indexPath.item {
|
||||||
theProgress = getProgressIndicesFromTurn(
|
theProgress = getProgressIndicesFromTurn(
|
||||||
turn: .next, progress: theProgress
|
turn: .next, progress: theProgress
|
||||||
)
|
)
|
||||||
@@ -632,9 +630,11 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if let indexPath = scrollingCollectionView.indexPathForItem(at: centerPoint) {
|
if let indexPath = scrollingCollectionView.indexPathForItem(at: centerPoint) {
|
||||||
let (chapter, page) = chapterAndPages[indexPath.item]
|
var newProgress = ProgressIndices(v: 0, c: 0, i: 0)
|
||||||
progress.c = chapter
|
for _ in 0 ..< indexPath.item {
|
||||||
progress.i = page
|
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
||||||
|
}
|
||||||
|
progress = newProgress
|
||||||
}
|
}
|
||||||
if scrollingCollectionView.isHidden == false {
|
if scrollingCollectionView.isHidden == false {
|
||||||
saveLocalState()
|
saveLocalState()
|
||||||
@@ -694,7 +694,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
leftView.isHidden = true
|
leftView.isHidden = true
|
||||||
rightView.isHidden = true
|
rightView.isHidden = true
|
||||||
scrollingCollectionView.isHidden = false
|
scrollingCollectionView.isHidden = false
|
||||||
// TODO: Fix scrolling again
|
scrollingCollectionView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
func countFiles() -> Int {
|
func countFiles() -> Int {
|
||||||
@@ -1028,6 +1028,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
scrollingCollectionView.isHidden = mode != .scroll
|
scrollingCollectionView.isHidden = mode != .scroll
|
||||||
leftView.isHidden = mode == .scroll
|
leftView.isHidden = mode == .scroll
|
||||||
rightView.isHidden = mode == .scroll
|
rightView.isHidden = mode == .scroll
|
||||||
|
imageView.isHidden = mode == .scroll
|
||||||
togglePageTurnDropdown()
|
togglePageTurnDropdown()
|
||||||
saveLocalState()
|
saveLocalState()
|
||||||
}
|
}
|
||||||
@@ -1161,7 +1162,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
self?.updateInfo()
|
self?.updateInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _ in 0 ... preloadCount {
|
for _ in 0 ..< preloadCount {
|
||||||
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
||||||
let path = getImagePath(progress: newProgress)
|
let path = getImagePath(progress: newProgress)
|
||||||
imageLoader.preloadImage(at: path, scaling: scaling, screenSize: UIScreen.main.bounds.size)
|
imageLoader.preloadImage(at: path, scaling: scaling, screenSize: UIScreen.main.bounds.size)
|
||||||
@@ -1302,7 +1303,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var newProgress = progress
|
var newProgress = progress
|
||||||
for _ in 0 ... preloadCount {
|
for _ in 0 ..< preloadCount {
|
||||||
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
||||||
imageLoader.preloadImage(at: getImagePath(progress: newProgress), scaling: scaling, screenSize: UIScreen.main.bounds.size)
|
imageLoader.preloadImage(at: getImagePath(progress: newProgress), scaling: scaling, screenSize: UIScreen.main.bounds.size)
|
||||||
}
|
}
|
||||||
@@ -1375,7 +1376,13 @@ extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFl
|
|||||||
if collectionView == comicCollectionView {
|
if collectionView == comicCollectionView {
|
||||||
return comics.count
|
return comics.count
|
||||||
} else {
|
} else {
|
||||||
return pagesAvailable
|
var sum = 0
|
||||||
|
for volume in metadata.volumes {
|
||||||
|
for chapter in volume.chapters {
|
||||||
|
sum += chapter.images.count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1391,16 +1398,25 @@ extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFl
|
|||||||
cell.imageView.image = comics[indexPath.item].cover
|
cell.imageView.image = comics[indexPath.item].cover
|
||||||
return cell
|
return cell
|
||||||
} else if collectionView == scrollingCollectionView {
|
} else if collectionView == scrollingCollectionView {
|
||||||
// let scaling = UIView.ContentMode.scaleAspectFill
|
let scaling = UIView.ContentMode.scaleAspectFill
|
||||||
let cell =
|
let cell =
|
||||||
collectionView.dequeueReusableCell(
|
collectionView.dequeueReusableCell(
|
||||||
withReuseIdentifier: "ScrollingImageCell", for: indexPath
|
withReuseIdentifier: "ScrollingImageCell", for: indexPath
|
||||||
)
|
)
|
||||||
as! ScrollingImageCell
|
as! ScrollingImageCell
|
||||||
if metadata == nil {
|
if metadata == nil {
|
||||||
|
print("metadata is nil, should probably not be the case")
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
// TODO: Fix scrolling again
|
var newProgress = ProgressIndices(v: 0, c: 0, i: 0)
|
||||||
|
if indexPath.item != 0 {
|
||||||
|
for _ in 0 ..< indexPath.item {
|
||||||
|
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imageLoader.loadImage(at: getImagePath(progress: newProgress), scaling: scaling, screenSize: UIScreen.main.bounds.size) { image in
|
||||||
|
cell.imageView.image = image
|
||||||
|
}
|
||||||
return cell
|
return cell
|
||||||
} else {
|
} else {
|
||||||
assertionFailure()
|
assertionFailure()
|
||||||
@@ -1417,7 +1433,7 @@ extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFl
|
|||||||
func collectionView(
|
func collectionView(
|
||||||
_ collectionView: UICollectionView,
|
_ collectionView: UICollectionView,
|
||||||
layout _: UICollectionViewLayout,
|
layout _: UICollectionViewLayout,
|
||||||
sizeForItemAt _: IndexPath
|
sizeForItemAt indexPath: IndexPath
|
||||||
) -> CGSize {
|
) -> CGSize {
|
||||||
if collectionView == comicCollectionView {
|
if collectionView == comicCollectionView {
|
||||||
let spacing: CGFloat = 8
|
let spacing: CGFloat = 8
|
||||||
@@ -1429,8 +1445,15 @@ extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFl
|
|||||||
if metadata == nil {
|
if metadata == nil {
|
||||||
return CGSize()
|
return CGSize()
|
||||||
}
|
}
|
||||||
// TODO: Fix scrolling again
|
var newProgress = ProgressIndices(v: 0, c: 0, i: 0)
|
||||||
return CGSize()
|
for _ in 0 ..< indexPath.item {
|
||||||
|
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
||||||
|
}
|
||||||
|
let imageMetadata = metadata.volumes[newProgress.v].chapters[newProgress.c].images[newProgress.i]
|
||||||
|
return CGSize(
|
||||||
|
width: readerView.bounds.width,
|
||||||
|
height: CGFloat(imageMetadata.size!.height) * readerView.bounds.width / CGFloat(imageMetadata.size!.width)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
assertionFailure()
|
assertionFailure()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user