Skip to content

Commit

Permalink
Fix removing items from queue other than the current track (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Duvholt <[email protected]>
  • Loading branch information
duvholt and Christian Duvholt authored Mar 27, 2023
1 parent 3cac61f commit a270b3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
28 changes: 13 additions & 15 deletions Example/Tests/QueueManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,22 +344,20 @@ class QueueManagerTests: QuickSpec {
// MARK: - Removal

context("then removing a item with index less than currentIndex") {
var removed: Int?
var initialCurrentIndex: Int!
beforeEach {
var removed: Int?
var initialCurrentIndex: Int!
beforeEach {
let _ = try? queue.jump(to: 3)
initialCurrentIndex = queue.currentIndex
removed = try? queue.removeItem(at: initialCurrentIndex - 1)
}

it("should remove an item") {
expect(removed).toNot(beNil())
}

it("should decrement the currentIndex") {
expect(queue.currentIndex).to(equal(initialCurrentIndex - 1))
}
let _ = try? queue.jump(to: 1)
initialCurrentIndex = queue.currentIndex
removed = try? queue.removeItem(at: initialCurrentIndex - 1)
}

it("should remove an item") {
expect(removed).toNot(beNil())
}

it("should decrement the currentIndex") {
expect(queue.currentIndex).to(equal(initialCurrentIndex - 1))
}
}

Expand Down
8 changes: 5 additions & 3 deletions SwiftAudioEx/Classes/QueueManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ class QueueManager<T> {
try throwIfIndexInvalid(index: index)
let result = items.remove(at: index)

mutateCurrentIndex(index: index == currentIndex && items.count > 0
? currentIndex % items.count : -1
)
if index == currentIndex {
mutateCurrentIndex(index: items.count > 0 ? currentIndex % items.count : -1)
} else if index < currentIndex {
mutateCurrentIndex(index: currentIndex - 1)
}

return result;
}
Expand Down

0 comments on commit a270b3b

Please sign in to comment.