Skip to content

Commit

Permalink
Fixes crash occurrinng sometimes whenn refreshing header of image sec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
EddyLB committed Jul 11, 2024
1 parent 7df2d5a commit ec9b1a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
24 changes: 10 additions & 14 deletions piwigo/Album/Extensions/AlbumViewController+DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ extension AlbumViewController: UICollectionViewDataSource
header.backgroundColor = UIColor.piwigoColorBackground().withAlphaComponent(0.75)
return header
case UICollectionView.elementKindSectionFooter:
if categoryId == Int32.zero {
guard let footer = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "ImageFooterReusableView", for: indexPath) as? ImageFooterReusableView
else { preconditionFailure("Could not load ImageFooterReusableView")}
footer.nberImagesLabel?.textColor = UIColor.piwigoColorHeader()
footer.nberImagesLabel?.text = getImageCount()
return footer
}
guard let footer = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "ImageFooterReusableView", for: indexPath) as? ImageFooterReusableView
else { preconditionFailure("Could not load ImageFooterReusableView")}
footer.nberImagesLabel?.textColor = UIColor.piwigoColorHeader()
footer.nberImagesLabel?.text = getImageCount()
return footer
default:
break
}
Expand Down Expand Up @@ -177,13 +175,11 @@ extension AlbumViewController: UICollectionViewDataSource
}
}
case UICollectionView.elementKindSectionFooter:
if indexPath.section == images.sections?.count ?? 0 {
guard let footer = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "ImageFooterReusableView", for: indexPath) as? ImageFooterReusableView
else { preconditionFailure("Could not load ImageFooterReusableView")}
footer.nberImagesLabel?.textColor = UIColor.piwigoColorHeader()
footer.nberImagesLabel?.text = getImageCount()
return footer
}
guard let footer = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "ImageFooterReusableView", for: indexPath) as? ImageFooterReusableView
else { preconditionFailure("Could not load ImageFooterReusableView")}
footer.nberImagesLabel?.textColor = UIColor.piwigoColorHeader()
footer.nberImagesLabel?.text = getImageCount()
return footer
default:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ extension AlbumViewController: NSFetchedResultsControllerDelegate
print("••> Delete image section at ", collectionSectionIndex)
self?.collectionView?.deleteSections(IndexSet(integer: collectionSectionIndex))
})
case .move, .update:
fallthrough
case .move:
let collectionSectionIndex = sectionIndex + 1
print("••> Move image section at ", collectionSectionIndex)
case .update:
let collectionSectionIndex = sectionIndex + 1
print("••> Update image section at ", collectionSectionIndex)
@unknown default:
fatalError("Unknown NSFetchedResultsChangeType of section in AlbumViewController")
}
Expand Down
7 changes: 2 additions & 5 deletions piwigo/Album/Extensions/AlbumViewController+FlowLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,8 @@ extension AlbumViewController: UICollectionViewDelegateFlowLayout

default /* Images */:
// Number of images shown at the bottom of the collection
guard AlbumVars.shared.isFetchingAlbumData.contains(categoryId) == false,
section == images.sections?.count ?? 0
else {
return CGSize.zero
}
guard section == images.sections?.count ?? 0
else { return CGSize.zero }
}

// Get number of images and status
Expand Down

0 comments on commit ec9b1a7

Please sign in to comment.