Skip to content

Commit

Permalink
Merge pull request #1141 from TortugaPower/multiple-fixes
Browse files Browse the repository at this point in the history
Multiple fixes
  • Loading branch information
GianniCarlo authored Jun 8, 2024
2 parents 5a63221 + 173c882 commit d9a1471
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 245 deletions.
6 changes: 3 additions & 3 deletions BookPlayer/Generated/AutoMockable.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1600,12 +1600,12 @@ class SyncServiceProtocolMock: SyncServiceProtocol {
}
var scheduleUploadItemsReceivedItems: [SimpleLibraryItem]?
var scheduleUploadItemsReceivedInvocations: [[SimpleLibraryItem]] = []
var scheduleUploadItemsClosure: (([SimpleLibraryItem]) -> Void)?
func scheduleUpload(items: [SimpleLibraryItem]) {
var scheduleUploadItemsClosure: (([SimpleLibraryItem]) async -> Void)?
func scheduleUpload(items: [SimpleLibraryItem]) async {
scheduleUploadItemsCallsCount += 1
scheduleUploadItemsReceivedItems = items
scheduleUploadItemsReceivedInvocations.append(items)
scheduleUploadItemsClosure?(items)
await scheduleUploadItemsClosure?(items)
}
//MARK: - scheduleDelete

Expand Down
100 changes: 52 additions & 48 deletions BookPlayer/Library/ItemList Screen/ItemListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,30 +404,32 @@ class ItemListViewModel: ViewModelProtocol {
}

func createFolder(with title: String, items: [String]? = nil, type: SimpleItemType) {
do {
let folder = try self.libraryService.createFolder(with: title, inside: self.folderRelativePath)
syncService.scheduleUpload(items: [folder])
if let fetchedItems = items {
try libraryService.moveItems(fetchedItems, inside: folder.relativePath)
syncService.scheduleMove(items: fetchedItems, to: folder.relativePath)
}
try self.libraryService.updateFolder(at: folder.relativePath, type: type)
libraryService.rebuildFolderDetails(folder.relativePath)

// stop playback if folder items contain that current item
if let items = items,
let currentRelativePath = self.playerManager.currentItem?.relativePath,
items.contains(currentRelativePath) {
self.playerManager.stop()
Task { @MainActor in
do {
let folder = try self.libraryService.createFolder(with: title, inside: self.folderRelativePath)
await syncService.scheduleUpload(items: [folder])
if let fetchedItems = items {
try libraryService.moveItems(fetchedItems, inside: folder.relativePath)
syncService.scheduleMove(items: fetchedItems, to: folder.relativePath)
}
try self.libraryService.updateFolder(at: folder.relativePath, type: type)
libraryService.rebuildFolderDetails(folder.relativePath)

// stop playback if folder items contain that current item
if let items = items,
let currentRelativePath = self.playerManager.currentItem?.relativePath,
items.contains(currentRelativePath) {
self.playerManager.stop()
}

} catch {
sendEvent(.showAlert(
content: BPAlertContent.errorAlert(message: error.localizedDescription)
))
}

} catch {
sendEvent(.showAlert(
content: BPAlertContent.errorAlert(message: error.localizedDescription)
))
self.coordinator.reloadItemsWithPadding(padding: 1)
}

self.coordinator.reloadItemsWithPadding(padding: 1)
}

func updateFolders(_ folders: [SimpleLibraryItem], type: SimpleItemType) {
Expand Down Expand Up @@ -1012,37 +1014,39 @@ extension ItemListViewModel {
func handleOperationCompletion(_ files: [URL], suggestedFolderName: String?) {
guard !files.isEmpty else { return }

let processedItems = libraryService.insertItems(from: files)
var itemIdentifiers = processedItems.map({ $0.relativePath })
do {
syncService.scheduleUpload(items: processedItems)
/// Move imported files to current selected folder so the user can see them
if let folderRelativePath {
try libraryService.moveItems(itemIdentifiers, inside: folderRelativePath)
syncService.scheduleMove(items: itemIdentifiers, to: folderRelativePath)
/// Update identifiers after moving for the follow up action alert
itemIdentifiers = itemIdentifiers.map({ "\(folderRelativePath)/\($0)" })
Task { @MainActor in
let processedItems = libraryService.insertItems(from: files)
var itemIdentifiers = processedItems.map({ $0.relativePath })
do {
await syncService.scheduleUpload(items: processedItems)
/// Move imported files to current selected folder so the user can see them
if let folderRelativePath {
try libraryService.moveItems(itemIdentifiers, inside: folderRelativePath)
syncService.scheduleMove(items: itemIdentifiers, to: folderRelativePath)
/// Update identifiers after moving for the follow up action alert
itemIdentifiers = itemIdentifiers.map({ "\(folderRelativePath)/\($0)" })
}
} catch {
sendEvent(.showAlert(
content: BPAlertContent.errorAlert(message: error.localizedDescription)
))
return
}
} catch {
sendEvent(.showAlert(
content: BPAlertContent.errorAlert(message: error.localizedDescription)
))
return
}

self.coordinator.reloadItemsWithPadding(padding: itemIdentifiers.count)
self.coordinator.reloadItemsWithPadding(padding: itemIdentifiers.count)

let availableFolders = self.libraryService.getItems(
notIn: itemIdentifiers,
parentFolder: folderRelativePath
)?.filter({ $0.type == .folder }) ?? []
let availableFolders = self.libraryService.getItems(
notIn: itemIdentifiers,
parentFolder: folderRelativePath
)?.filter({ $0.type == .folder }) ?? []

showOperationCompletedAlert(
itemIdentifiers: itemIdentifiers,
hasOnlyBooks: processedItems.allSatisfy({ $0.type == .book }),
availableFolders: availableFolders,
suggestedFolderName: suggestedFolderName
)
showOperationCompletedAlert(
itemIdentifiers: itemIdentifiers,
hasOnlyBooks: processedItems.allSatisfy({ $0.type == .book }),
availableFolders: availableFolders,
suggestedFolderName: suggestedFolderName
)
}
}

// swiftlint:disable:next function_body_length
Expand Down
1 change: 1 addition & 0 deletions BookPlayer/Player/PlayerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ extension PlayerManager {
}

load(nextBook, autoplay: shouldAutoplay)
libraryService.setLibraryLastBook(with: nextBook.relativePath)
}

/// Check `UTType` of the book before returning it
Expand Down
16 changes: 8 additions & 8 deletions BookPlayer/ar.lproj/AppShortcuts.strings
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"Play the current book in ${applicationName}" = "تشغيل الكتاب الحالي في ${applicationName}";
"Play the last book in ${applicationName}" = "تشغيل الكتاب الأخير في ${applicationName}";
"Continue the last played book in ${applicationName}" = "متابعة آخر كتاب تم تشغيله في ${applicationName}";
"Pause the current book in ${applicationName}" = "إيقاف الكتاب الحالي مؤقتًا في ${applicationName}";
"Pause playback in ${applicationName}" = "إيقاف التشغيل مؤقتًا في ${applicationName}";
"Play the last book in ${applicationName}" = "تشغيل آخر كتاب في ${applicationName}";
"Continue the last played book in ${applicationName}" = "متابعة الاستماع لآخر كتاب في ${applicationName}";
"Pause the current book in ${applicationName}" = "إيقاف الكتاب الحالي في ${applicationName}";
"Pause playback in ${applicationName}" = "إيقاف التشغيل في ${applicationName}";
"Stop ${applicationName}" = "إيقاف ${applicationName}";
"Stop playback in ${applicationName}" = "إيقاف التشغيل في ${applicationName}";
"Set the sleep timer to the End of Chapter in ${applicationName}" = "اضبط مؤقت السكون على نهاية الفصل في ${applicationName}";
"Stop playback in ${applicationName}" = "إيقاف تشغيل الصوت في ${applicationName}";
"Set the sleep timer to the End of Chapter in ${applicationName}" = "اضبط مؤقت النوم على نهاية الفصل في ${applicationName}";
"Set the sleep timer to the End of the current Chapter in ${applicationName}" = "اضبط مؤقت السكون على نهاية الفصل الحالي في ${applicationName}";
"Cancel the sleep timer in ${applicationName}" = "إلغاء مؤقت النوم في ${applicationName}";
"Turn off the sleep timer in ${applicationName}" = "قم بإيقاف تشغيل مؤقت النوم في ${applicationName}";
"Turn off the sleep timer in ${applicationName}" = "إيقاف تشغيل مؤقت النوم في ${applicationName}";
"Set the sleep timer in ${applicationName}" = "ضبط مؤقت النوم في ${applicationName}";
"Turn on the sleep timer in ${applicationName}" = "تشغيل مؤقت النوم في ${applicationName}";
"Enable the sleep timer in ${applicationName}" = "تمكين مؤقت النوم في ${applicationName}";
"Enable the sleep timer in ${applicationName}" = "تشغيل مؤقت النوم في ${applicationName}";
Loading

0 comments on commit d9a1471

Please sign in to comment.