Skip to content

Commit

Permalink
Fix T4410445: Tapping on Play button should start playing with full-i…
Browse files Browse the repository at this point in the history
…mage screen mode without any error
  • Loading branch information
Mahmud Ahsan committed Feb 10, 2023
1 parent 30bc805 commit 7fea5a8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions MEGAUnitTests/Mocks/MockSlideShowDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ final class MockSlideShowDataSource: SlideShowDataSourceProtocol {
}

func startInitialDownload(_ initialPhotoDownloaded: Bool) {
processData(basedOnCurrentSlideNumber: 0, andOldSlideNumber: 0)
processData(basedOnCurrentSlideIndex: 0, andOldSlideIndex: 0)
}

func loadSelectedPhotoPreview() -> Bool {
true
}

func processData(basedOnCurrentSlideNumber currentSlideNumber: Int, andOldSlideNumber oldSlideNumber: Int) {
func processData(basedOnCurrentSlideIndex currentSlideIndex: Int, andOldSlideIndex oldSlideIndex: Int) {
nodeEntities.forEach { node in
photos.append(SlideShowMediaEntity(image: nil, node: node, fileUrl: nil))
}
Expand Down
8 changes: 4 additions & 4 deletions MEGAUnitTests/Slideshow/SlideshowDataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SlideShowDataSourceTests: XCTestCase {
sut.startInitialDownload(false)
await sut.thumbnailLoadingTask?.value

sut.processData(basedOnCurrentSlideNumber: 11, andOldSlideNumber: 10)
sut.processData(basedOnCurrentSlideIndex: 11, andOldSlideIndex: 10)
await sut.thumbnailLoadingTask?.value
XCTAssertTrue(sut.photos.count == 40)
}
Expand All @@ -89,10 +89,10 @@ class SlideShowDataSourceTests: XCTestCase {
sut.startInitialDownload(false)
await sut.thumbnailLoadingTask?.value

sut.processData(basedOnCurrentSlideNumber: 20, andOldSlideNumber: 19)
sut.processData(basedOnCurrentSlideIndex: 20, andOldSlideIndex: 19)
XCTAssertNil(sut.photos[0].image)

sut.processData(basedOnCurrentSlideNumber: 19, andOldSlideNumber: 20)
sut.processData(basedOnCurrentSlideIndex: 19, andOldSlideIndex: 20)
await sut.thumbnailLoadingTask?.value
XCTAssertNotNil(sut.photos[0].image)
}
Expand All @@ -103,7 +103,7 @@ class SlideShowDataSourceTests: XCTestCase {
sut.startInitialDownload(false)
await sut.thumbnailLoadingTask?.value

sut.processData(basedOnCurrentSlideNumber: 20, andOldSlideNumber: 19)
sut.processData(basedOnCurrentSlideIndex: 20, andOldSlideIndex: 19)
XCTAssertNil(sut.photos[0].image)
}
}
6 changes: 3 additions & 3 deletions MEGAUnitTests/Slideshow/SlideshowViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class SlideshowViewModelTests: XCTestCase {
XCTAssertTrue(slideShowViewModel.playbackStatus == .playing)
slideShowViewModel.dispatch(.pause)
XCTAssertTrue(slideShowViewModel.playbackStatus == .pause)
XCTAssertTrue(slideShowViewModel.currentSlideNumber == 0)
XCTAssertTrue(slideShowViewModel.currentSlideIndex == 0)
XCTAssertTrue(slideShowViewModel.timeIntervalForSlideInSeconds == 4)
XCTAssertTrue(slideShowViewModel.configuration.isRepeat == false)

Expand Down Expand Up @@ -121,9 +121,9 @@ class SlideshowViewModelTests: XCTestCase {
XCTAssertTrue(command == .showLoader)
}

sut.currentSlideNumber = 1
sut.currentSlideIndex = 1
sut.restartSlideShow()
XCTAssertTrue(sut.currentSlideNumber == 0)
XCTAssertTrue(sut.currentSlideIndex == 0)

wait(for: [expectation], timeout: 1.0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protocol SlideShowDataSourceProtocol {
func resetData()
func loadSelectedPhotoPreview() -> Bool
func startInitialDownload(_ initialPhotoDownloaded: Bool)
func processData(basedOnCurrentSlideNumber currentSlideNumber: Int, andOldSlideNumber oldSlideNumber: Int)
func processData(basedOnCurrentSlideIndex currentSlideIndex: Int, andOldSlideIndex oldSlideIndex: Int)
func sortNodes(byOrder order: SlideShowPlayingOrderEntity)
}

Expand Down Expand Up @@ -101,16 +101,16 @@ final class SlideShowDataSource: SlideShowDataSourceProtocol {
}
}

func processData(basedOnCurrentSlideNumber currentSlideNumber: Int, andOldSlideNumber oldSlideNumber: Int) {
if shouldLoadMorePhotos(currentSlideNumber) {
func processData(basedOnCurrentSlideIndex currentSlideIndex: Int, andOldSlideIndex oldSlideIndex: Int) {
if shouldLoadMorePhotos(currentSlideIndex) {
loadNextSetOfPhotosPreview(advanceNumberOfPhotosToLoad, withInitialPhoto: false)
}

if oldSlideNumber > currentSlideNumber {
reloadUnusedPhotos(currentSlideNumber)
if oldSlideIndex > currentSlideIndex {
reloadUnusedPhotos(currentSlideIndex)
}
else if currentSlideNumber > oldSlideNumber {
removeUnusedPhotos(currentSlideNumber)
else if currentSlideIndex > oldSlideIndex {
removeUnusedPhotos(currentSlideIndex)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ final class SlideShowViewModel: ViewModelType {
configuration.timeIntervalForSlideInSeconds.value
}

var currentSlideNumber = 0 {
var currentSlideIndex = 0 {
didSet {
dataSource.processData(basedOnCurrentSlideNumber: currentSlideNumber, andOldSlideNumber: oldValue)
dataSource.processData(basedOnCurrentSlideIndex: currentSlideIndex, andOldSlideIndex: oldValue)
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ final class SlideShowViewModel: ViewModelType {
func restartSlideShow() {
invokeCommand?(.showLoader)
dataSource.initialPhotoDownloadCallback = { [weak self] in
self?.currentSlideNumber = 0
self?.currentSlideIndex = 0
self?.invokeCommand?(.restart)
}
dataSource.resetData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ final class SlideShowViewController: UIViewController, ViewType {
self.collectionView.backgroundColor = UIColor.black
self.view.backgroundColor = .black
cell?.resetZoomScale()
if viewModel.currentSlideNumber >= viewModel.photos.count {
viewModel.currentSlideNumber = -1
if viewModel.currentSlideIndex >= viewModel.photos.count - 1 {
viewModel.currentSlideIndex = -1
self.changeImage()
}
}
Expand Down Expand Up @@ -191,21 +191,21 @@ final class SlideShowViewController: UIViewController, ViewType {
guard let viewModel = viewModel else { return }
hideLoader()
reload()
collectionView.scrollToItem(at: IndexPath(item: viewModel.currentSlideNumber, section: 0), at: .left, animated: false)
collectionView.scrollToItem(at: IndexPath(item: viewModel.currentSlideIndex, section: 0), at: .left, animated: false)
play()
}

@objc private func changeImage() {
guard let viewModel = viewModel else { return }

let slideNumber = viewModel.currentSlideNumber + 1
let slideNumber = viewModel.currentSlideIndex + 1

if slideNumber < viewModel.photos.count {
viewModel.currentSlideNumber = slideNumber
viewModel.currentSlideIndex = slideNumber
hideLoader()
updateSlideInView()
} else if viewModel.configuration.isRepeat {
viewModel.currentSlideNumber = 0
viewModel.currentSlideIndex = 0
hideLoader()
updateSlideInView()
} else if slideNumber >= viewModel.numberOfSlideShowContents {
Expand All @@ -219,7 +219,7 @@ final class SlideShowViewController: UIViewController, ViewType {
private func updateSlideInView() {
guard let viewModel = viewModel else { return }

let index = IndexPath(item: viewModel.currentSlideNumber, section: 0)
let index = IndexPath(item: viewModel.currentSlideIndex, section: 0)
if collectionView.isValid(indexPath: index) {
collectionView.scrollToItem(at: index, at: .centeredHorizontally, animated: false)
}
Expand Down Expand Up @@ -286,8 +286,8 @@ extension SlideShowViewController: UIScrollViewDelegate {
let visibleIndexPath = collectionView.indexPathForItem(at: visiblePoint)

if let viewModel = viewModel, let visibleIndexPath = visibleIndexPath,
viewModel.currentSlideNumber != visibleIndexPath.row {
viewModel.currentSlideNumber = visibleIndexPath.row
viewModel.currentSlideIndex != visibleIndexPath.row {
viewModel.currentSlideIndex = visibleIndexPath.row
}

if viewModel?.playbackStatus == .playing {
Expand Down

0 comments on commit 7fea5a8

Please sign in to comment.