diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7f57034e..b1fe92ae5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,16 @@ jobs: steps: - uses: actions/checkout@v4 + # We only use Xcode 15.4 + - name: Remove unused applications + run: | + df -hI /dev/disk3s1s1 + sudo rm -rf /Applications/Xcode_14.3.1.app + sudo rm -rf /Applications/Xcode_15.0.1.app + sudo rm -rf /Applications/Xcode_15.1.app + sudo rm -rf /Applications/Xcode_15.2.app + sudo rm -rf /Applications/Xcode_15.3.app + df -hI /dev/disk3s1s1 - name: Create Debug.xcconfig run: cp ./BuildConfiguration/Debug.template.xcconfig ./BuildConfiguration/Debug.xcconfig - name: Set Xcode version diff --git a/BookPlayer.xcodeproj/project.pbxproj b/BookPlayer.xcodeproj/project.pbxproj index 717d0e3a6..ce519fec0 100644 --- a/BookPlayer.xcodeproj/project.pbxproj +++ b/BookPlayer.xcodeproj/project.pbxproj @@ -143,7 +143,6 @@ 4197240021874D5F00AB1190 /* UserActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419723FF21874D5F00AB1190 /* UserActivityManager.swift */; }; 4197FAFC267E480100811CC8 /* ImportViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4197FAFB267E480100811CC8 /* ImportViewController.swift */; }; 419B373923B8D0C600128A8F /* Player.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 419B373B23B8D0C600128A8F /* Player.storyboard */; }; - 419B373C23B8D12200128A8F /* AddCellView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 419B373E23B8D12200128A8F /* AddCellView.xib */; }; 419B373F23B8D14100128A8F /* LoadingView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 419B374123B8D14100128A8F /* LoadingView.xib */; }; 419B374223B8D18000128A8F /* PlusBannerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 419B374423B8D18000128A8F /* PlusBannerView.xib */; }; 419B375623B8D5A500128A8F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 419B375423B8D5A500128A8F /* Localizable.strings */; }; @@ -210,7 +209,6 @@ 41B2A5E121CCC21000917584 /* ThemeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41B2A5E021CCC21000917584 /* ThemeManager.swift */; }; 41B2A5ED21CCC6D100917584 /* AppNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41B2A5EC21CCC6D100917584 /* AppNavigationController.swift */; }; 41B2A5EF21CD5AAE00917584 /* StaticCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41B2A5EE21CD5AAE00917584 /* StaticCellView.swift */; }; - 41B2A5F121CD857800917584 /* AddCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41B2A5F021CD857800917584 /* AddCellView.swift */; }; 41B2AC8E1D43CCE8005382A9 /* ChaptersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41B2AC8D1D43CCE8005382A9 /* ChaptersViewController.swift */; }; 41B30A33230232D200025D69 /* CarPlayManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41B30A32230232D200025D69 /* CarPlayManager.swift */; }; 41C233FD272E1957006BC7B8 /* SimpleLibraryItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41188D3026ED715D0017124E /* SimpleLibraryItem.swift */; }; @@ -234,7 +232,6 @@ 41D20DB225D5F5A100AAEE30 /* MappingModel_v1_to_v2.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 41D20DAE25D5F5A100AAEE30 /* MappingModel_v1_to_v2.xcmappingmodel */; }; 41D20DB325D5F5A100AAEE30 /* MappingModel_v1_to_v2.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 41D20DAE25D5F5A100AAEE30 /* MappingModel_v1_to_v2.xcmappingmodel */; }; 41D20DB425D5F5A100AAEE30 /* MappingModel_v1_to_v2.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 41D20DAE25D5F5A100AAEE30 /* MappingModel_v1_to_v2.xcmappingmodel */; }; - 41D4F2EF21053944009F1B1E /* IndexPath+BookPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41D4F2EE21053944009F1B1E /* IndexPath+BookPlayer.swift */; }; 41DA44BD26FAEC4F00F3A05D /* BookActivityItemProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41D39D40215F177D00B65290 /* BookActivityItemProvider.swift */; }; 41E562CE22394F5200C06BC9 /* ayu-light@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 41E562CC22394F5200C06BC9 /* ayu-light@2x.png */; }; 41E562CF22394F5200C06BC9 /* ayu-light@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 41E562CD22394F5200C06BC9 /* ayu-light@3x.png */; }; @@ -949,7 +946,6 @@ 419723FF21874D5F00AB1190 /* UserActivityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserActivityManager.swift; sourceTree = ""; }; 4197FAFB267E480100811CC8 /* ImportViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportViewController.swift; sourceTree = ""; }; 419B373A23B8D0C600128A8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Player.storyboard; sourceTree = ""; }; - 419B373D23B8D12200128A8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/AddCellView.xib; sourceTree = ""; }; 419B374023B8D14100128A8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LoadingView.xib; sourceTree = ""; }; 419B374323B8D18000128A8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PlusBannerView.xib; sourceTree = ""; }; 419B375523B8D5A500128A8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = ""; }; @@ -1006,7 +1002,6 @@ 41B2A5E021CCC21000917584 /* ThemeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeManager.swift; sourceTree = ""; }; 41B2A5EC21CCC6D100917584 /* AppNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppNavigationController.swift; sourceTree = ""; }; 41B2A5EE21CD5AAE00917584 /* StaticCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaticCellView.swift; sourceTree = ""; }; - 41B2A5F021CD857800917584 /* AddCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddCellView.swift; sourceTree = ""; }; 41B2A6AB21D3274500917584 /* Themeable.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Themeable.framework; path = Carthage/Build/iOS/Themeable.framework; sourceTree = ""; }; 41B2AC8D1D43CCE8005382A9 /* ChaptersViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChaptersViewController.swift; sourceTree = ""; }; 41B30A32230232D200025D69 /* CarPlayManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarPlayManager.swift; sourceTree = ""; }; @@ -1020,7 +1015,6 @@ 41D20DAE25D5F5A100AAEE30 /* MappingModel_v1_to_v2.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = MappingModel_v1_to_v2.xcmappingmodel; sourceTree = ""; }; 41D39D40215F177D00B65290 /* BookActivityItemProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookActivityItemProvider.swift; sourceTree = ""; }; 41D4F2EA2101A278009F1B1E /* DirectoryWatcher.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DirectoryWatcher.framework; path = Carthage/Build/iOS/DirectoryWatcher.framework; sourceTree = ""; }; - 41D4F2EE21053944009F1B1E /* IndexPath+BookPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "IndexPath+BookPlayer.swift"; sourceTree = ""; }; 41D7944E22260EC000228580 /* SwiftyStoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftyStoreKit.framework; path = Carthage/Build/iOS/SwiftyStoreKit.framework; sourceTree = ""; }; 41E34E4F2138EA8200A3997C /* ImportOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportOperation.swift; sourceTree = ""; }; 41E562CC22394F5200C06BC9 /* ayu-light@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ayu-light@2x.png"; sourceTree = ""; }; @@ -2695,8 +2689,6 @@ C33E843B20C6E179004A0489 /* ItemProgress.swift */, C398559B20C492FF00BE9EC0 /* AddButton.swift */, C3FE94782080086800BCEA37 /* BookCellView.swift */, - 419B373E23B8D12200128A8F /* AddCellView.xib */, - 41B2A5F021CD857800917584 /* AddCellView.swift */, 4165EE0A20A7A33500616EDF /* BookCellView.xib */, 4142964321F21D95004356DA /* BulkControlsView.swift */, 4142964521F21DAE004356DA /* BulkControlsView.xib */, @@ -2728,7 +2720,6 @@ isa = PBXGroup; children = ( 416B640C1E72F362000E955A /* Notification+BookPlayer.swift */, - 41D4F2EE21053944009F1B1E /* IndexPath+BookPlayer.swift */, C3A479142094CA3800D92122 /* UIImage+BookPlayer.swift */, C39401E820DEE83100F3DC71 /* UIView+BookPlayer.swift */, C3A479182094CAF300D92122 /* UIViewController+BookPlayer.swift */, @@ -3154,7 +3145,6 @@ 418B6D031D2707F800F974FB /* Main.storyboard in Resources */, 9F665ED42A4894C4004BFE27 /* heart-of-glass-ipad@2x.png in Resources */, 634BA54A2C0BD06B0015314D /* pride-ipad@2x.png in Resources */, - 419B373C23B8D12200128A8F /* AddCellView.xib in Resources */, 41E562EB2239531E00C06BC9 /* retro-modern-ipad@3x.png in Resources */, 9F665EE12A4898F6004BFE27 /* heart-of-glass-forest@3x.png in Resources */, 41E56302223956B800C06BC9 /* retro-icon-ipad@3x.png in Resources */, @@ -3459,7 +3449,6 @@ 9F2681AD2888B26100359BD3 /* LoginBenefitView.swift in Sources */, 634BA5A72C1777BB0015314D /* PricingBoxView.swift in Sources */, 9F588DBF2902C798000DA799 /* ComposedButton.swift in Sources */, - 41B2A5F121CD857800917584 /* AddCellView.swift in Sources */, 4151A6B326E491A800E49DBE /* NibLoadableView.swift in Sources */, 4197FAFC267E480100811CC8 /* ImportViewController.swift in Sources */, 631C75C92AB92C540013E7E5 /* BPPushPresentationFlow.swift in Sources */, @@ -3560,7 +3549,6 @@ 9F3D0CE528C2BF5C00E9E8A3 /* ButtonFreeViewController.swift in Sources */, 4197240021874D5F00AB1190 /* UserActivityManager.swift in Sources */, 634BA5972C161FBE0015314D /* StoryView.swift in Sources */, - 41D4F2EF21053944009F1B1E /* IndexPath+BookPlayer.swift in Sources */, 6356F9C52AC86D9200B7A027 /* BPAppShortcuts.swift in Sources */, 69343D332133844D000C425E /* VoiceOverService.swift in Sources */, C359C30720A9F35B00A626E3 /* SkipDurationViewController.swift in Sources */, @@ -3960,14 +3948,6 @@ name = Player.storyboard; sourceTree = ""; }; - 419B373E23B8D12200128A8F /* AddCellView.xib */ = { - isa = PBXVariantGroup; - children = ( - 419B373D23B8D12200128A8F /* Base */, - ); - name = AddCellView.xib; - sourceTree = ""; - }; 419B374123B8D14100128A8F /* LoadingView.xib */ = { isa = PBXVariantGroup; children = ( @@ -5427,7 +5407,7 @@ repositoryURL = "https://github.com/getsentry/sentry-cocoa.git"; requirement = { kind = exactVersion; - version = 8.32.0; + version = 8.36.0; }; }; 41F1A214254B0AA40043FCF3 /* XCRemoteSwiftPackageReference "Kingfisher" */ = { diff --git a/BookPlayer.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/BookPlayer.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e86e0446a..ef48ac4da 100644 --- a/BookPlayer.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/BookPlayer.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -78,8 +78,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/getsentry/sentry-cocoa.git", "state" : { - "revision" : "5421f94cc859eb65f5ae3866165a053aa634431e", - "version" : "8.32.0" + "revision" : "5575af93efb776414f243e93d6af9f6258dc539a", + "version" : "8.36.0" } }, { diff --git a/BookPlayer/AppDelegate.swift b/BookPlayer/AppDelegate.swift index 2f8d8f445..76dc9339d 100644 --- a/BookPlayer/AppDelegate.swift +++ b/BookPlayer/AppDelegate.swift @@ -275,60 +275,62 @@ class AppDelegate: UIResponder, UIApplicationDelegate, BPLogger { } func setupMPPlaybackRemoteCommands() { - // Play / Pause - MPRemoteCommandCenter.shared().togglePlayPauseCommand.isEnabled = true - MPRemoteCommandCenter.shared().togglePlayPauseCommand.addTarget { [weak self] (_) -> MPRemoteCommandHandlerStatus in - guard let playerManager = self?.playerManager else { return .commandFailed } - - let wasPlaying = playerManager.isPlaying - playerManager.playPause() - - if wasPlaying, - UIApplication.shared.applicationState == .background { - self?.scheduleAppRefresh() + Task { + // Play / Pause + MPRemoteCommandCenter.shared().togglePlayPauseCommand.isEnabled = true + MPRemoteCommandCenter.shared().togglePlayPauseCommand.addTarget { [weak self] (_) -> MPRemoteCommandHandlerStatus in + guard let playerManager = self?.playerManager else { return .commandFailed } + + let wasPlaying = playerManager.isPlaying + playerManager.playPause() + + if wasPlaying, + UIApplication.shared.applicationState == .background { + self?.scheduleAppRefresh() + } + return .success } - return .success - } - - MPRemoteCommandCenter.shared().playCommand.isEnabled = true - MPRemoteCommandCenter.shared().playCommand.addTarget { [weak self] (_) -> MPRemoteCommandHandlerStatus in - guard let playerManager = self?.playerManager else { return .commandFailed } - - playerManager.play() - return .success - } - - MPRemoteCommandCenter.shared().pauseCommand.isEnabled = true - MPRemoteCommandCenter.shared().pauseCommand.addTarget { [weak self] (_) -> MPRemoteCommandHandlerStatus in - guard let playerManager = self?.playerManager else { return .commandFailed } - - playerManager.pause() - - if UIApplication.shared.applicationState == .background { - self?.scheduleAppRefresh() + + MPRemoteCommandCenter.shared().playCommand.isEnabled = true + MPRemoteCommandCenter.shared().playCommand.addTarget { [weak self] (_) -> MPRemoteCommandHandlerStatus in + guard let playerManager = self?.playerManager else { return .commandFailed } + + playerManager.play() + return .success } - - return .success - } - - MPRemoteCommandCenter.shared().changePlaybackPositionCommand.isEnabled = true - MPRemoteCommandCenter.shared().changePlaybackPositionCommand.addTarget { [weak self] remoteEvent in - guard - let playerManager = self?.playerManager, - let currentItem = playerManager.currentItem, - let event = remoteEvent as? MPChangePlaybackPositionCommandEvent - else { return .commandFailed } - - var newTime = event.positionTime - - if UserDefaults.sharedDefaults.bool(forKey: Constants.UserDefaults.chapterContextEnabled), - let currentChapter = currentItem.currentChapter { - newTime += currentChapter.start + + MPRemoteCommandCenter.shared().pauseCommand.isEnabled = true + MPRemoteCommandCenter.shared().pauseCommand.addTarget { [weak self] (_) -> MPRemoteCommandHandlerStatus in + guard let playerManager = self?.playerManager else { return .commandFailed } + + playerManager.pause() + + if UIApplication.shared.applicationState == .background { + self?.scheduleAppRefresh() + } + + return .success + } + + MPRemoteCommandCenter.shared().changePlaybackPositionCommand.isEnabled = true + MPRemoteCommandCenter.shared().changePlaybackPositionCommand.addTarget { [weak self] remoteEvent in + guard + let playerManager = self?.playerManager, + let currentItem = playerManager.currentItem, + let event = remoteEvent as? MPChangePlaybackPositionCommandEvent + else { return .commandFailed } + + var newTime = event.positionTime + + if UserDefaults.sharedDefaults.bool(forKey: Constants.UserDefaults.chapterContextEnabled), + let currentChapter = currentItem.currentChapter { + newTime += currentChapter.start + } + + playerManager.jumpTo(newTime, recordBookmark: true) + + return .success } - - playerManager.jumpTo(newTime, recordBookmark: true) - - return .success } } diff --git a/BookPlayer/Library/ItemList Screen/ItemListViewController.swift b/BookPlayer/Library/ItemList Screen/ItemListViewController.swift index a1622e47e..d3cc35658 100644 --- a/BookPlayer/Library/ItemList Screen/ItemListViewController.swift +++ b/BookPlayer/Library/ItemList Screen/ItemListViewController.swift @@ -36,6 +36,15 @@ class ItemListViewController: UIViewController, MVVMControllerProtocol, Storyboa }) }() + private lazy var addButton: UIBarButtonItem = { + return UIBarButtonItem( + image: UIImage(systemName: "plus"), + style: .plain, + target: self, + action: #selector(handleAddAction) + ) + }() + private lazy var sortButton: UIButton = { let button = ComposedButton( title: "sort_button_title".localized, @@ -146,7 +155,7 @@ class ItemListViewController: UIViewController, MVVMControllerProtocol, Storyboa self.adjustBottomOffsetForMiniPlayer() - self.navigationItem.rightBarButtonItem = searchButton + self.navigationItem.rightBarButtonItems = [addButton, searchButton] self.emptyStateImageView.image = UIImage(named: self.viewModel.getEmptyStateImageName()) @@ -170,7 +179,6 @@ class ItemListViewController: UIViewController, MVVMControllerProtocol, Storyboa func configureDataSource() { self.tableView.register(UINib(nibName: "BookCellView", bundle: nil), forCellReuseIdentifier: "BookCellView") - self.tableView.register(UINib(nibName: "AddCellView", bundle: nil), forCellReuseIdentifier: "AddCellView") self.tableView.rowHeight = UITableView.automaticDimension self.tableView.estimatedRowHeight = UITableView.automaticDimension @@ -360,16 +368,16 @@ class ItemListViewController: UIViewController, MVVMControllerProtocol, Storyboa if editing { self.selectButton.setTitle("done_title".localized, for: .normal) - self.navigationItem.rightBarButtonItem?.isEnabled = false + self.navigationItem.rightBarButtonItems?.forEach { $0.isEnabled = false } self.selectAllButton.isHidden = false sortButton.isHidden = true - self.selectAllButton.isEnabled = self.tableView.numberOfRows(inSection: BPSection.data.rawValue) > 0 + self.selectAllButton.isEnabled = self.tableView.numberOfRows(inSection: 0) > 0 self.updateSelectionStatus() } else { self.selectButton.setTitle("select_title".localized, for: .normal) self.selectAllButton.isHidden = true sortButton.isHidden = false - self.navigationItem.rightBarButtonItem?.isEnabled = true + self.navigationItem.rightBarButtonItems?.forEach { $0.isEnabled = true } } } @@ -389,7 +397,7 @@ class ItemListViewController: UIViewController, MVVMControllerProtocol, Storyboa func updateSelectionStatus() { guard self.tableView.isEditing else { return } - let title = self.tableView.numberOfRows(inSection: BPSection.data.rawValue) > (self.tableView.indexPathsForSelectedRows?.count ?? 0) + let title = self.tableView.numberOfRows(inSection: 0) > (self.tableView.indexPathsForSelectedRows?.count ?? 0) ? "select_all_title".localized : "deselect_all_title".localized self.selectAllButton.setTitle(title, for: .normal) @@ -411,6 +419,10 @@ class ItemListViewController: UIViewController, MVVMControllerProtocol, Storyboa self.viewModel.showAddActions() } + @objc func handleAddAction() { + self.viewModel.showAddActions() + } + @objc func handleSelectButtonPressed() { self.setEditing(!isEditing, animated: true) } @@ -418,13 +430,13 @@ class ItemListViewController: UIViewController, MVVMControllerProtocol, Storyboa @objc func selectAllButtonPressed(_ sender: Any) { self.viewModel.loadAllItemsIfNeeded() - if self.tableView.numberOfRows(inSection: BPSection.data.rawValue) == (self.tableView.indexPathsForSelectedRows?.count ?? 0) { - for row in 0.. Int { - return BPSection.allCases.count + return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - guard section == BPSection.data.rawValue else { return 1 } - return self.viewModel.items.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - guard indexPath.sectionValue != .add, - let cell = tableView.dequeueReusableCell(withIdentifier: "BookCellView", for: indexPath) as? BookCellView else { - return tableView.dequeueReusableCell(withIdentifier: "AddCellView", for: indexPath) - } - + // swiftlint:disable force_cast + let cell = tableView.dequeueReusableCell(withIdentifier: "BookCellView", for: indexPath) as! BookCellView + // swiftlint:enable force_cast let item = self.viewModel.items[indexPath.row] cell.onArtworkTap = { [weak self] in @@ -499,13 +507,11 @@ extension ItemListViewController: UITableViewDelegate { // MARK: reordering support func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { - return indexPath.sectionValue == .data + return true } func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { - guard sourceIndexPath.sectionValue == .data, - destinationIndexPath.sectionValue == .data, - sourceIndexPath.row != destinationIndexPath.row else { + guard sourceIndexPath.row != destinationIndexPath.row else { return } @@ -516,18 +522,15 @@ extension ItemListViewController: UITableViewDelegate { // MARK: editing support func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { - return indexPath.sectionValue == .data + return true } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - guard indexPath.sectionValue == .data else { return 66 } - return UITableView.automaticDimension } func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { - guard indexPath.sectionValue == .data, - indexPath.row == (self.viewModel.items.count - 1) else { return } + guard indexPath.row == (self.viewModel.items.count - 1) else { return } DispatchQueue.main.async { [weak self] in guard let self = self else { return } @@ -536,10 +539,6 @@ extension ItemListViewController: UITableViewDelegate { } func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { - guard tableView.isEditing else { return indexPath } - - guard indexPath.sectionValue == .data else { return nil } - return indexPath } @@ -556,14 +555,6 @@ extension ItemListViewController: UITableViewDelegate { tableView.deselectRow(at: indexPath, animated: true) - guard indexPath.sectionValue == .data else { - if indexPath.sectionValue == .add { - self.viewModel.showAddActions() - } - - return - } - let item = self.viewModel.items[indexPath.row] navigationItem.backButtonDisplayMode = .default @@ -571,8 +562,6 @@ extension ItemListViewController: UITableViewDelegate { } func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { - guard indexPath.sectionValue == .data else { return nil } - let item = self.viewModel.items[indexPath.row] let optionsAction = UIContextualAction(style: .normal, title: "\("options_button".localized)…") { _, _, completion in @@ -598,10 +587,6 @@ extension ItemListViewController: UITableViewDropDelegate { } func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal { - // Cancel drop if destination is not in the data section - if destinationIndexPath?.sectionValue == .add { - return UITableViewDropProposal(operation: .cancel, intent: .unspecified) - } if session.localDragSession != nil { // Drag originated from the same app. return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath) @@ -737,7 +722,7 @@ extension ItemListViewController { guard let foundIndex = newIndex else { return nil } - let newIndexPath = IndexPath(row: foundIndex, section: .data) + let newIndexPath = IndexPath(row: foundIndex, section: 0) self.tableView.scrollToRow(at: newIndexPath, at: .none, animated: false) let newCell = self.tableView.cellForRow(at: newIndexPath)! diff --git a/BookPlayer/Library/ItemList Screen/ItemListViewModel.swift b/BookPlayer/Library/ItemList Screen/ItemListViewModel.swift index ea8942406..ad4166048 100644 --- a/BookPlayer/Library/ItemList Screen/ItemListViewModel.swift +++ b/BookPlayer/Library/ItemList Screen/ItemListViewModel.swift @@ -163,7 +163,7 @@ class ItemListViewModel: ViewModelProtocol { self?.items[index].percentCompleted = progress - let indexModified = IndexPath(row: index, section: BPSection.data.rawValue) + let indexModified = IndexPath(row: index, section: 0) self?.sendEvent(.reloadIndex(indexModified)) }.store(in: &disposeBag) } @@ -181,7 +181,7 @@ class ItemListViewModel: ViewModelProtocol { else { return } self?.sendEvent( - .reloadIndex(IndexPath(row: index, section: BPSection.data.rawValue)) + .reloadIndex(IndexPath(row: index, section: 0)) ) }.store(in: &disposeBag) @@ -196,7 +196,7 @@ class ItemListViewModel: ViewModelProtocol { }) else { return } - let indexModified = IndexPath(row: index, section: BPSection.data.rawValue) + let indexModified = IndexPath(row: index, section: 0) self?.sendEvent( .downloadState(.downloading(progress: progress), indexPath: indexModified) ) @@ -257,7 +257,7 @@ class ItemListViewModel: ViewModelProtocol { self.items[index].percentCompleted = percentCompleted - let indexModified = IndexPath(row: index, section: BPSection.data.rawValue) + let indexModified = IndexPath(row: index, section: 0) self.sendEvent(.reloadIndex(indexModified)) }) } @@ -1251,7 +1251,7 @@ extension ItemListViewModel { } if let index = self?.items.firstIndex(of: item) { - self?.sendEvent(.reloadIndex(IndexPath(row: index, section: .data))) + self?.sendEvent(.reloadIndex(IndexPath(row: index, section: 0))) } } ), diff --git a/BookPlayer/Library/ItemList Screen/Views/AddCellView.swift b/BookPlayer/Library/ItemList Screen/Views/AddCellView.swift deleted file mode 100644 index 8e8f5b1b9..000000000 --- a/BookPlayer/Library/ItemList Screen/Views/AddCellView.swift +++ /dev/null @@ -1,33 +0,0 @@ -// -// AddCellView.swift -// BookPlayer -// -// Created by Gianni Carlo on 12/21/18. -// Copyright © 2018 Tortuga Power. All rights reserved. -// - -import BookPlayerKit -import Themeable -import UIKit - -class AddCellView: UITableViewCell { - @IBOutlet weak var addImageView: UIImageView! - @IBOutlet weak var titleLabel: UILabel! - - override func awakeFromNib() { - super.awakeFromNib() - self.titleLabel.accessibilityLabel = "playlist_add_title".localized - let titleDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body) - self.titleLabel.font = UIFont(descriptor: titleDescriptor, size: 0.0) - self.titleLabel.adjustsFontForContentSizeCategory = true - setUpTheming() - } -} - -extension AddCellView: Themeable { - func applyTheme(_ theme: SimpleTheme) { - self.titleLabel.textColor = theme.linkColor - self.backgroundColor = theme.systemBackgroundColor - self.addImageView.tintColor = theme.linkColor - } -} diff --git a/BookPlayer/Library/ItemList Screen/Views/Base.lproj/AddCellView.xib b/BookPlayer/Library/ItemList Screen/Views/Base.lproj/AddCellView.xib deleted file mode 100644 index 9072e0a26..000000000 --- a/BookPlayer/Library/ItemList Screen/Views/Base.lproj/AddCellView.xib +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/BookPlayer/Settings/Themes Screen/ThemesViewController.swift b/BookPlayer/Settings/Themes Screen/ThemesViewController.swift index ee6d216e1..f64d5d039 100644 --- a/BookPlayer/Settings/Themes Screen/ThemesViewController.swift +++ b/BookPlayer/Settings/Themes Screen/ThemesViewController.swift @@ -279,16 +279,10 @@ class ThemesViewController: UIViewController, Storyboarded { extension ThemesViewController: UITableViewDataSource { func numberOfSections(in tableView: UITableView) -> Int { - return tableView == self.localThemesTableView - ? 1 - : BPSection.allCases.count + return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - guard section == BPSection.data.rawValue else { - return 1 - } - return tableView == self.localThemesTableView ? self.localThemes.count : self.extractedThemes.count @@ -303,16 +297,6 @@ extension ThemesViewController: UITableViewDataSource { cell.accessoryType = .none cell.titleLabel.textColor = ThemeManager.shared.currentTheme.primaryColor - guard indexPath.sectionValue != .add else { - cell.titleLabel.text = "library_add_button".localized - cell.titleLabel.textColor = ThemeManager.shared.currentTheme.linkColor - cell.plusImageView.isHidden = false - cell.plusImageView.tintColor = ThemeManager.shared.currentTheme.linkColor - cell.showCaseView.isHidden = true - cell.isLocked = !self.viewModel.hasMadeDonation() - return cell - } - let item = tableView == self.localThemesTableView ? self.localThemes[indexPath.row] : self.extractedThemes[indexPath.row] @@ -338,11 +322,6 @@ extension ThemesViewController: UITableViewDelegate { return } - guard indexPath.sectionValue != .add else { - self.extractTheme() - return - } - let item = tableView == self.localThemesTableView ? self.localThemes[indexPath.row] : self.extractedThemes[indexPath.row] diff --git a/BookPlayer/Utils/Extensions/IndexPath+BookPlayer.swift b/BookPlayer/Utils/Extensions/IndexPath+BookPlayer.swift deleted file mode 100644 index dd7b5d0df..000000000 --- a/BookPlayer/Utils/Extensions/IndexPath+BookPlayer.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// IndexPath+BookPlayer.swift -// BookPlayer -// -// Created by Gianni Carlo on 7/22/18. -// Copyright © 2018 Tortuga Power. All rights reserved. -// - -import UIKit - -extension IndexPath { - init(row: Int, section: BPSection) { - self.init(row: row, section: section.rawValue) - } - - var sectionValue: BPSection { - return BPSection(rawValue: self.section) ?? .data - } -} - -enum BPSection: Int, CaseIterable { - case data, - add -} diff --git a/BookPlayerTests/Services/LibraryServiceTests.swift b/BookPlayerTests/Services/LibraryServiceTests.swift index 21df4a4b5..9dd836edc 100644 --- a/BookPlayerTests/Services/LibraryServiceTests.swift +++ b/BookPlayerTests/Services/LibraryServiceTests.swift @@ -1085,8 +1085,8 @@ class ModifyLibraryTests: LibraryServiceTests { self.sut.reorderItem( with: book3.relativePath, inside: nil, - sourceIndexPath: IndexPath(row: 0, section: .data), - destinationIndexPath: IndexPath(row: 2, section: .data) + sourceIndexPath: IndexPath(row: 0, section: 0), + destinationIndexPath: IndexPath(row: 2, section: 0) ) let sortedContents = sut.fetchContents(at: nil, limit: nil, offset: nil) @@ -1106,8 +1106,8 @@ class ModifyLibraryTests: LibraryServiceTests { self.sut.reorderItem( with: book3.relativePath, inside: folder.relativePath, - sourceIndexPath: IndexPath(row: 2, section: .data), - destinationIndexPath: IndexPath(row: 0, section: .data) + sourceIndexPath: IndexPath(row: 2, section: 0), + destinationIndexPath: IndexPath(row: 0, section: 0) ) let sortedFolderContents = sut.fetchContents(at: folder.relativePath, limit: nil, offset: nil)