diff --git a/4champ/Data/Structs.swift b/4champ/Data/Structs.swift index 8b75243..c668657 100644 --- a/4champ/Data/Structs.swift +++ b/4champ/Data/Structs.swift @@ -112,7 +112,7 @@ struct MMD: Identifiable { } extension MMD: Equatable {} -func ==(lhs: MMD, rhs: MMD) -> Bool { +func == (lhs: MMD, rhs: MMD) -> Bool { let eq = lhs.id == rhs.id && lhs.id != nil return eq } diff --git a/4champ/Networking/ModuleFetcher.swift b/4champ/Networking/ModuleFetcher.swift index c1748bf..9005937 100644 --- a/4champ/Networking/ModuleFetcher.swift +++ b/4champ/Networking/ModuleFetcher.swift @@ -29,7 +29,7 @@ enum FetcherError: Error { ModuleFetcher state delegate. Implemented in classes that use a fetcher to download modules, e.g. RadioInteractor and SearchInteractor */ -protocol ModuleFetcherDelegate { +protocol ModuleFetcherDelegate: class { /** Fetcher calls delegate on state changes. - parameters: @@ -166,8 +166,7 @@ class ModuleFetcher { - returns: module data, unzipped */ private func gzipInflate(data: Data) -> Data? { - if data.isGzipped { - let inflated = try! data.gunzipped() + if data.isGzipped, let inflated = try? data.gunzipped() { return inflated } log.error("FAILED TO UNZIP") diff --git a/4champ/Replay/ModulePlayer.swift b/4champ/Replay/ModulePlayer.swift index fe414ba..b16726c 100644 --- a/4champ/Replay/ModulePlayer.swift +++ b/4champ/Replay/ModulePlayer.swift @@ -275,15 +275,13 @@ class ModulePlayer: NSObject { /// called when app resigns to clear non-stored modules func cleanup() { - for mod in playQueue { - if mod.hasBeenSaved() == false { - if let url = mod.localPath { - log.info("Deleting module \(url.lastPathComponent)") - do { - try FileManager.default.removeItem(at: url) - } catch { - log.error("Deleting file at \(url) failed, \(error)") - } + for mod in playQueue where !mod.hasBeenSaved() { + if let url = mod.localPath { + log.info("Deleting module \(url.lastPathComponent)") + do { + try FileManager.default.removeItem(at: url) + } catch { + log.error("Deleting file at \(url) failed, \(error)") } } } @@ -333,10 +331,8 @@ extension ModulePlayer: ModuleStorageObserver { currentModule?.favorite = mmd.favorite } if playQueue.count == 0 { return } - for i in 0...playQueue.count-1 { - if playQueue[i] == mmd { - playQueue[i].favorite = mmd.favorite - } + for qIndex in 0...playQueue.count-1 where playQueue[qIndex] == mmd { + playQueue[qIndex].favorite = mmd.favorite } _ = observers.map { $0.queueChanged(changeType: .other) diff --git a/4champ/Scenes/About/AboutViewController.swift b/4champ/Scenes/About/AboutViewController.swift index dae50d9..5bab17c 100644 --- a/4champ/Scenes/About/AboutViewController.swift +++ b/4champ/Scenes/About/AboutViewController.swift @@ -80,7 +80,6 @@ class AboutViewController: UIViewController, AboutDisplayLogic { // MARK: Display Logic func displayNowPlaying(_ viewModel: About.Status.ViewModel) { - // TODO } @objc func reviewNow() { diff --git a/4champ/Scenes/Local/LocalInteractor.swift b/4champ/Scenes/Local/LocalInteractor.swift index 8b636c7..46c8575 100644 --- a/4champ/Scenes/Local/LocalInteractor.swift +++ b/4champ/Scenes/Local/LocalInteractor.swift @@ -61,7 +61,11 @@ class LocalInteractor: NSObject, LocalBusinessLogic, LocalDataStore { fetchRequest.predicate = NSPredicate.init(format: filterString) frc = moduleStorage.createFRC(fetchRequest: fetchRequest, entityName: "ModuleInfo") frc?.delegate = self - try! frc?.performFetch() + do { + try frc?.performFetch() + } catch { + log.error("Fetch failed \(error)") + } presenter?.presentModules(response: Local.SortFilter.Response()) } diff --git a/4champ/Scenes/Local/ModuleStorage.swift b/4champ/Scenes/Local/ModuleStorage.swift index a37d7c0..ce3298a 100644 --- a/4champ/Scenes/Local/ModuleStorage.swift +++ b/4champ/Scenes/Local/ModuleStorage.swift @@ -118,7 +118,7 @@ class ModuleStorage: NSObject { let filterString = "plId == 'default'" fetchRequest.predicate = NSPredicate.init(format: filterString) let frc = createFRC(fetchRequest: fetchRequest, entityName: "Playlist") - try! frc.performFetch() + try? frc.performFetch() guard let defaultPl = frc.fetchedObjects?.first else { // No Default playlist yet, must create it return createPlaylist(name: "default", id: "default") diff --git a/4champ/Scenes/MainViewController.swift b/4champ/Scenes/MainViewController.swift index 53849dc..e025a53 100644 --- a/4champ/Scenes/MainViewController.swift +++ b/4champ/Scenes/MainViewController.swift @@ -65,9 +65,9 @@ class MainViewController: UITabBarController { npView?.addGestureRecognizer(lpr) let titles = ["TabBar_Local", "TabBar_Playlist", "TabBar_Search", "TabBar_Radio", "TabBar_About"] - for t in tabBar.items! { - if let index = tabBar.items!.index(of: t) { - t.title = titles[index].l13n() + for tab in tabBar.items! { + if let index = tabBar.items!.index(of: tab) { + tab.title = titles[index].l13n() } } } @@ -96,13 +96,10 @@ class MainViewController: UITabBarController { switch event.subtype { case .remoteControlPlay: modulePlayer.resume() - break case .remoteControlPause: modulePlayer.pause() - break case .remoteControlStop: modulePlayer.stop() - break case .remoteControlNextTrack: modulePlayer.playNext() case .remoteControlPreviousTrack: diff --git a/4champ/Scenes/PlaylistSelector/PlaylistSelectorInteractor.swift b/4champ/Scenes/PlaylistSelector/PlaylistSelectorInteractor.swift index 65f890b..17fc40c 100644 --- a/4champ/Scenes/PlaylistSelector/PlaylistSelectorInteractor.swift +++ b/4champ/Scenes/PlaylistSelector/PlaylistSelectorInteractor.swift @@ -37,7 +37,7 @@ class PlaylistSelectorInteractor: PlaylistSelectorBusinessLogic, PlaylistSelecto let filterString = "plId != 'radioList'" fetchRequest.predicate = NSPredicate.init(format: filterString) frc = moduleStorage.createFRC(fetchRequest: fetchRequest, entityName: "Playlist") - try! frc?.performFetch() + try? frc?.performFetch() if let plObjects = frc?.fetchedObjects { var plMetaData = plObjects.map { @@ -46,7 +46,7 @@ class PlaylistSelectorInteractor: PlaylistSelectorBusinessLogic, PlaylistSelecto for pl in plObjects { for mi in pl.modules ?? [] { - let modId = (mi as! ModuleInfo).modId?.intValue ?? 0 + let modId = (mi as? ModuleInfo)?.modId?.intValue ?? 0 if let index = plMetaData.firstIndex(where: { $0.id == pl.plId }) { plMetaData[index].modules.append(modId) } @@ -86,7 +86,7 @@ class PlaylistSelectorInteractor: PlaylistSelectorBusinessLogic, PlaylistSelecto moduleStorage.saveContext() presenter?.presentAppend(response: completed) } else { - if let _ = module?.localPath { + if module?.localPath != nil { // 2. Module is downloaded (radio/search) but not yet in database moduleStorage.addModule(module: module!) if let modInfo = moduleStorage.fetchModuleInfo(modId) { @@ -112,7 +112,7 @@ class PlaylistSelectorInteractor: PlaylistSelectorBusinessLogic, PlaylistSelecto let filterString = "plId == '\(id)'" fetchRequest.predicate = NSPredicate.init(format: filterString) let tmp = moduleStorage.createFRC(fetchRequest: fetchRequest, entityName: "Playlist") - try! tmp.performFetch() + try? tmp.performFetch() return tmp.fetchedObjects?.first } } diff --git a/4champ/Scenes/PlaylistSelector/PlaylistSelectorPresenter.swift b/4champ/Scenes/PlaylistSelector/PlaylistSelectorPresenter.swift index 4966f95..b6f266e 100644 --- a/4champ/Scenes/PlaylistSelector/PlaylistSelectorPresenter.swift +++ b/4champ/Scenes/PlaylistSelector/PlaylistSelectorPresenter.swift @@ -44,8 +44,8 @@ class PlaylistSelectorPresenter: PlaylistSelectorPresentationLogic { } var moduleName = response.module.name ?? "" - if let mod_name = response.module.name, let composer_name = response.module.composer, composer_name.count > 0 { - moduleName = String.init(format: "LockScreen_Playing".l13n(), mod_name, composer_name) + if let mName = response.module.name, let cName = response.module.composer, cName.count > 0 { + moduleName = String.init(format: "LockScreen_Playing".l13n(), mName, cName) } let status: DownloadStatus = response.module.hasBeenSaved() ? .complete : .unknown diff --git a/4champ/Scenes/PlaylistSelector/PlaylistSelectorStore.swift b/4champ/Scenes/PlaylistSelector/PlaylistSelectorStore.swift index 4e2537a..eadc4cb 100644 --- a/4champ/Scenes/PlaylistSelector/PlaylistSelectorStore.swift +++ b/4champ/Scenes/PlaylistSelector/PlaylistSelectorStore.swift @@ -23,7 +23,7 @@ class PlaylistSelectorStore: ObservableObject, PlaylistSelectorDisplayLogic { weak var hostingController: UIHostingController? @Published var viewModel: PlaylistSelector.PrepareSelection.ViewModel - + init() { self.viewModel = PlaylistSelector.PrepareSelection.ViewModel(module: "", currentPlaylistIndex: 0, playlistOptions: [], status: .unknown) } @@ -32,16 +32,16 @@ class PlaylistSelectorStore: ObservableObject, PlaylistSelectorDisplayLogic { let pls = PlaylistSelectorStore() var contentView = PlaylistPickerView(dismissAction: { pls.hostingController?.dismiss(animated: true, completion: nil)}, shareAction: { - pls.shareModule(module) + pls.shareModule(module) }, deleteAction: { - pls.deleteModule(module) + pls.deleteModule(module) }, store: pls) pls.setup() pls.doPrepare(mod: module) - contentView.addToPlaylistAction = { b in - pls.addToPlaylist(playlistIndex: b) + contentView.addToPlaylistAction = { pIndex in + pls.addToPlaylist(playlistIndex: pIndex) } let hvc = UIHostingController(rootView: contentView) pls.hostingController = hvc @@ -93,7 +93,7 @@ class PlaylistSelectorStore: ObservableObject, PlaylistSelectorDisplayLogic { guard viewModel.status == .complete else { return } - + interactor?.deleteModule(request: PlaylistSelector.Delete.Request(module: module)) hostingController?.dismiss(animated: true, completion: nil) } diff --git a/4champ/Scenes/Playlists/PlaylistInteractor.swift b/4champ/Scenes/Playlists/PlaylistInteractor.swift index 5fa17b1..e2f479b 100644 --- a/4champ/Scenes/Playlists/PlaylistInteractor.swift +++ b/4champ/Scenes/Playlists/PlaylistInteractor.swift @@ -33,19 +33,23 @@ class PlaylistInteractor: NSObject, PlaylistBusinessLogic, PlaylistDataStore { var selectedPlaylistId: String? var frc: NSFetchedResultsController? // var name: String = "" - + private var downloadController = DownloadController.init() override init() { super.init() let filterString = "plId != 'radioList'" - + let fetchRequest = NSFetchRequest.init(entityName: "Playlist") fetchRequest.sortDescriptors = [] fetchRequest.predicate = NSPredicate.init(format: filterString) frc = moduleStorage.createFRC(fetchRequest: fetchRequest, entityName: "Playlist") frc?.delegate = self - try! frc?.performFetch() + do { + try frc?.performFetch() + } catch { + log.error("Failed to perform fetch: \(error)") + } if selectedPlaylistId == nil { selectedPlaylistId = "default" @@ -125,11 +129,12 @@ class PlaylistInteractor: NSObject, PlaylistBusinessLogic, PlaylistDataStore { private func rebuildQueue() { if let pl = frc?.fetchedObjects?.first(where: { ($0 as Playlist).plId == selectedPlaylistId }) { var playlistQueue: [MMD] = [] - if let moduleinfos = pl.modules { - for mod in moduleinfos { - playlistQueue.append(MMD(cdi: (mod as! ModuleInfo))) + pl.modules?.forEach { + if let modInfo = $0 as? ModuleInfo { + playlistQueue.append(MMD(cdi: modInfo)) } } + if pl.playmode?.boolValue ?? false { playlistQueue.shuffle() } @@ -152,14 +157,14 @@ extension PlaylistInteractor: NSFetchedResultsControllerDelegate { } func controller(_ controller: NSFetchedResultsController, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) { - + guard modulePlayer.radioOn == false else { return } if let pl = anObject as? Playlist, pl.plId == selectedPlaylistId { rebuildQueue() - } + } } func controllerDidChangeContent(_ controller: NSFetchedResultsController) { diff --git a/4champ/Scenes/Playlists/PlaylistPresenter.swift b/4champ/Scenes/Playlists/PlaylistPresenter.swift index 09c8939..1ecad96 100644 --- a/4champ/Scenes/Playlists/PlaylistPresenter.swift +++ b/4champ/Scenes/Playlists/PlaylistPresenter.swift @@ -25,9 +25,9 @@ class PlaylistPresenter: PlaylistPresentationLogic { let shuffle = (pl.playmode?.intValue ?? 0) == 1 var mods: [MMD] = [] - if let moduleinfos = pl.modules { - for mod in moduleinfos { - mods.append(MMD(cdi: (mod as! ModuleInfo))) + pl.modules?.forEach { + if let modInfo = $0 as? ModuleInfo { + mods.append(MMD(cdi: modInfo)) } } diff --git a/4champ/Scenes/Playlists/PlaylistView.swift b/4champ/Scenes/Playlists/PlaylistView.swift index 9c2874d..e886e9a 100644 --- a/4champ/Scenes/Playlists/PlaylistView.swift +++ b/4champ/Scenes/Playlists/PlaylistView.swift @@ -51,7 +51,7 @@ struct SUIModule: View { struct PlaylistView: View { @Environment(\.managedObjectContext) var managedObjectContext - @State private var show_modal: Bool = false + @State private var showModal: Bool = false @State var showNowPlaying: Bool = false @State var isEditing: Bool = false @State var navigationButtonID = UUID() @@ -93,13 +93,13 @@ struct PlaylistView: View { var body: some View { VStack { Button(action: { - self.show_modal = true + self.showModal = true }) { Text(store.viewModel.playlistName).underline() .foregroundColor(Color(.white)) .padding(EdgeInsets.init(top: 5, leading: 0, bottom: -5, trailing: 0)) - }.sheet(isPresented: self.$show_modal) { - PlaylistSelectorSUI(show_modal: self.$show_modal).environment(\.managedObjectContext, self.managedObjectContext).onDisappear { + }.sheet(isPresented: self.$showModal) { + PlaylistSelectorSUI(showModal: self.$showModal).environment(\.managedObjectContext, self.managedObjectContext).onDisappear { self.navigationButtonID = UUID() }.background(Color(Appearance.darkBlueColor)) } @@ -171,7 +171,7 @@ func randomMMD() -> MMD { var st = PlaylistStore(viewModel: Playlists.Select.ViewModel(playlistName: "foo", shuffle: false, modules: [randomMMD(), randomMMD(), randomMMD()]) ) -struct Playlist_Preview: PreviewProvider { +struct PlaylistPreview: PreviewProvider { static var previews: some View { Group { NavigationView { diff --git a/4champ/Scenes/Playlists/SelectPlaylistView.swift b/4champ/Scenes/Playlists/SelectPlaylistView.swift index 461ee6a..0c00d1b 100644 --- a/4champ/Scenes/Playlists/SelectPlaylistView.swift +++ b/4champ/Scenes/Playlists/SelectPlaylistView.swift @@ -41,7 +41,7 @@ struct PlaylistCell: View { } struct PlaylistSelectorSUI: View { - @Binding var show_modal: Bool + @Binding var showModal: Bool @State private var listId = UUID() @Environment(\.managedObjectContext) var managedObjectContext @FetchRequest(entity: Playlist.entity(), @@ -126,7 +126,7 @@ struct PlaylistSelectorSUI: View { if pl.plName != "radioList" { PlaylistCell(pl: pl).contentShape(Rectangle()).onTapGesture { moduleStorage.currentPlaylist = pl - self.show_modal.toggle() + self.showModal.toggle() } .onLongPressGesture { self.edit(pl: pl) @@ -136,7 +136,7 @@ struct PlaylistSelectorSUI: View { }.contentShape(Rectangle()).id(listId) }.navigationBarTitle("PlaylistView_Playlists", displayMode: .inline) .navigationBarItems(leading: Button(action: { - self.show_modal.toggle() + self.showModal.toggle() }) { Image(systemName: "xmark").imageScale(.large) }, diff --git a/4champ/Scenes/Radio/RadioInteractor.swift b/4champ/Scenes/Radio/RadioInteractor.swift index ba3dd0e..7b9b540 100644 --- a/4champ/Scenes/Radio/RadioInteractor.swift +++ b/4champ/Scenes/Radio/RadioInteractor.swift @@ -325,7 +325,7 @@ class RadioInteractor: NSObject, RadioBusinessLogic, RadioDataStore, RadioRemote while(id == 0 || !radioSessionHistory.filter({ mmd in mmd.id == id }).isEmpty) { - id = Int(arc4random_uniform(UInt32(settings.collectionSize))) + id = Int.random(in: 1...settings.collectionSize) } return id case .new: @@ -333,7 +333,7 @@ class RadioInteractor: NSObject, RadioBusinessLogic, RadioDataStore, RadioRemote lastPlayed = settings.collectionSize settings.newestPlayed = lastPlayed } else { - lastPlayed = lastPlayed - 1 + lastPlayed -= 1 } return lastPlayed case .local: @@ -375,26 +375,30 @@ extension RadioInteractor: ModuleFetcherDelegate { status = .fetching(progress: progress) case .done(let mmd): - switch postFetchAction { - case .appendToQueue: - modulePlayer.playQueue.append(mmd) - case .insertToQueue: - modulePlayer.playQueue.insert(mmd, at: 0) - case .startPlay: - modulePlayer.play(mmd: mmd) - } - postFetchAction = .appendToQueue // reset to default - - self.triggerBufferPresentation() - if let first = modulePlayer.playQueue.first, first == mmd { - modulePlayer.play(at: 0) - } - self.fillBuffer() - self.status = .on + handleDownloadComplete(mmd) default: () } } + + func handleDownloadComplete(_ mmd: MMD) { + switch postFetchAction { + case .appendToQueue: + modulePlayer.playQueue.append(mmd) + case .insertToQueue: + modulePlayer.playQueue.insert(mmd, at: 0) + case .startPlay: + modulePlayer.play(mmd: mmd) + } + postFetchAction = .appendToQueue // reset to default + + self.triggerBufferPresentation() + if let first = modulePlayer.playQueue.first, first == mmd { + modulePlayer.play(at: 0) + } + self.fillBuffer() + self.status = .on + } } extension RadioInteractor: ModulePlayerObserver { diff --git a/4champ/Scenes/Search/SearchViewController.swift b/4champ/Scenes/Search/SearchViewController.swift index d418e3e..b1a9626 100644 --- a/4champ/Scenes/Search/SearchViewController.swift +++ b/4champ/Scenes/Search/SearchViewController.swift @@ -174,7 +174,7 @@ class SearchViewController: UIViewController, SearchDisplayLogic { var onlineOnly = vm.modules.count for mod in vm.modules { if mod.hasBeenSaved() || mod.supported() == false { - onlineOnly = onlineOnly - 1 + onlineOnly -= 1 } } @@ -523,7 +523,9 @@ extension SearchViewController: ModuleCellDelegate { func shareTapped(cell: ModuleCell) { guard let ip = tableView?.indexPath(for: cell), - let module = viewModel?.modules[ip.row], let _ = module.id, module.supported() else { + let module = viewModel?.modules[ip.row], + module.id != nil, + module.supported() else { return } shareUtil.shareMod(mod: module) @@ -541,7 +543,6 @@ extension SearchViewController: ModuleCellDelegate { } func addAction(moduleId: Int, playlistId: String) { - log.error("addAction") - // TODO: Add the module to playlist + log.error("not expecting addAction") } } diff --git a/4champ/Scenes/Settings/SettingsInteractor.swift b/4champ/Scenes/Settings/SettingsInteractor.swift index 0aaff9d..646959d 100644 --- a/4champ/Scenes/Settings/SettingsInteractor.swift +++ b/4champ/Scenes/Settings/SettingsInteractor.swift @@ -17,7 +17,7 @@ protocol SettingsDataStore { } class SettingsInteractor: SettingsBusinessLogic, SettingsDataStore { - + private enum SettingKeys { static let domainName = "DomainName" static let stereoSeparation = "StereoSeparation" @@ -26,81 +26,81 @@ class SettingsInteractor: SettingsBusinessLogic, SettingsDataStore { static let prevCollectionSize = "prevCollectionSize" static let interpolation = "interpolation" } - + var presenter: SettingsPresentationLogic? var stereoSeparation: Int { - set { - UserDefaults.standard.set(newValue, forKey: SettingKeys.stereoSeparation) - } get { if let value = UserDefaults.standard.value(forKey: SettingKeys.stereoSeparation) as? Int { return value } return Constants.stereoSeparationDefault } + set { + UserDefaults.standard.set(newValue, forKey: SettingKeys.stereoSeparation) + } + } + + var interpolation: SampleInterpolation { + get { + if let value = UserDefaults.standard.value(forKey: SettingKeys.interpolation) as? Int { + return SampleInterpolation(rawValue: value) ?? .libraryDefault + } + return SampleInterpolation.libraryDefault + } + set { + UserDefaults.standard.set(newValue.rawValue, forKey: SettingKeys.interpolation) + } + } + + var collectionSize: Int { + get { + if let value = UserDefaults.standard.value(forKey: SettingKeys.collectionSize) as? Int { + return value + } + return Constants.latestDummy + } + set { + UserDefaults.standard.set(newValue, forKey: SettingKeys.collectionSize) + updateBadge() + NotificationCenter.default.post(Notification.init(name: Notifications.badgeUpdate)) + } } - - var interpolation: SampleInterpolation { - set { - UserDefaults.standard.set(newValue.rawValue, forKey: SettingKeys.interpolation) - } - get { - if let value = UserDefaults.standard.value(forKey: SettingKeys.interpolation) as? Int { - return SampleInterpolation(rawValue: value) ?? .libraryDefault - } - return SampleInterpolation.libraryDefault - } + + var newestPlayed: Int { + get { + if let value = UserDefaults.standard.value(forKey: SettingKeys.newestPlayed) as? Int { + return value + } + return 0 } - - var collectionSize: Int { - set { - UserDefaults.standard.set(newValue, forKey: SettingKeys.collectionSize) - updateBadge() - NotificationCenter.default.post(Notification.init(name: Notifications.badgeUpdate)) - } - get { - if let value = UserDefaults.standard.value(forKey: SettingKeys.collectionSize) as? Int { - return value - } - return Constants.latestDummy - } + set { + UserDefaults.standard.set(newValue, forKey: SettingKeys.newestPlayed) + updateBadge() + NotificationCenter.default.post(Notification.init(name: Notifications.badgeUpdate)) } - - var newestPlayed: Int { - set { - UserDefaults.standard.set(newValue, forKey: SettingKeys.newestPlayed) - updateBadge() - NotificationCenter.default.post(Notification.init(name: Notifications.badgeUpdate)) - } - get { - if let value = UserDefaults.standard.value(forKey: SettingKeys.newestPlayed) as? Int { - return value - } - return 0 - } + } + + var prevCollectionSize: Int { + get { + if let value = UserDefaults.standard.value(forKey: SettingKeys.prevCollectionSize) as? Int { + return value + } + return 0 } - - var prevCollectionSize: Int { - set { - UserDefaults.standard.set(newValue, forKey: SettingKeys.prevCollectionSize) - } - get { - if let value = UserDefaults.standard.value(forKey: SettingKeys.prevCollectionSize) as? Int { - return value - } - return 0 - } + set { + UserDefaults.standard.set(newValue, forKey: SettingKeys.prevCollectionSize) } - - var badgeCount: Int { - if newestPlayed < collectionSize { - var diff = collectionSize - newestPlayed - diff = diff > Constants.maxBadgeValue ? Constants.maxBadgeValue : diff - return diff - } - return 0 + } + + var badgeCount: Int { + if newestPlayed < collectionSize { + var diff = collectionSize - newestPlayed + diff = diff > Constants.maxBadgeValue ? Constants.maxBadgeValue : diff + return diff } + return 0 + } // MARK: Do something @@ -111,14 +111,14 @@ class SettingsInteractor: SettingsBusinessLogic, SettingsDataStore { stereoSeparation = request.stereoSeparation interpolation = request.interpolation } else { - response = Settings.Update.ValueBag(stereoSeparation: stereoSeparation, interpolation: interpolation) + response = Settings.Update.ValueBag(stereoSeparation: stereoSeparation, interpolation: interpolation) } modulePlayer.setStereoSeparation(stereoSeparation) modulePlayer.setInterpolation(interpolation) presenter?.presentSettings(response: response) } - - private func updateBadge() { - UIApplication.shared.applicationIconBadgeNumber = badgeCount - } + + private func updateBadge() { + UIApplication.shared.applicationIconBadgeNumber = badgeCount + } } diff --git a/4champ/Scenes/Settings/SettingsViewController.swift b/4champ/Scenes/Settings/SettingsViewController.swift index 39811d4..92234f5 100644 --- a/4champ/Scenes/Settings/SettingsViewController.swift +++ b/4champ/Scenes/Settings/SettingsViewController.swift @@ -114,8 +114,8 @@ class SettingsViewController: UITableViewController, SettingsDisplayLogic { if let interpolationCell = tableView.cellForRow(at: IndexPath.init(row: 0, section: 1)) as? SettingsInterpolationCell, let value = interpolationCell.interpolationSwitch?.isOn { - let i = value ? SampleInterpolation.libraryDefault : SampleInterpolation.off - valueBag.interpolation = i + let ipol = value ? SampleInterpolation.libraryDefault : SampleInterpolation.off + valueBag.interpolation = ipol } return valueBag diff --git a/4champ/Scenes/SharedUI/ModuleCell.swift b/4champ/Scenes/SharedUI/ModuleCell.swift index 51a2efe..a526a58 100644 --- a/4champ/Scenes/SharedUI/ModuleCell.swift +++ b/4champ/Scenes/SharedUI/ModuleCell.swift @@ -75,9 +75,7 @@ extension ModuleCell { lbl.textAlignment = .center self.contentView.addSubview(lbl) DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+3.0) { - UIView.animate(withDuration: 1.0, animations: {lbl.alpha=0}) { (_) in - lbl.removeFromSuperview() - } + UIView.animate(withDuration: 1.0, animations: {lbl.alpha=0}, completion: {_ in lbl.removeFromSuperview()}) } } } diff --git a/4champ/Scenes/Visualizer/AmpSlider.swift b/4champ/Scenes/Visualizer/AmpSlider.swift index 141ef12..6ff6245 100644 --- a/4champ/Scenes/Visualizer/AmpSlider.swift +++ b/4champ/Scenes/Visualizer/AmpSlider.swift @@ -68,11 +68,11 @@ class AmpSlider: UISlider { self.setThumbImage(image, for: .highlighted) } - @objc func sliderTapped(_ g: UITapGestureRecognizer) { + @objc func sliderTapped(_ gRec: UITapGestureRecognizer) { if self.isHighlighted { return } - let pt: CGPoint = g.location(in: self) + let pt: CGPoint = gRec.location(in: self) let percentage: Float = Float.init(pt.x) / Float.init(self.bounds.size.width) let delta: Float = percentage * (self.maximumValue - self.minimumValue) let value: Float = self.minimumValue + delta diff --git a/4champ/Scenes/Visualizer/AmpVizScene.swift b/4champ/Scenes/Visualizer/AmpVizScene.swift index 08e6e0b..d80c73a 100644 --- a/4champ/Scenes/Visualizer/AmpVizScene.swift +++ b/4champ/Scenes/Visualizer/AmpVizScene.swift @@ -73,15 +73,15 @@ class AmpVizScene: SKScene { func setupChannelBars() { let channelcount = modulePlayer.renderer.numberOfChannels() - for i in 0.. 0 { self.presentingViewController?.dismiss(animated: true, completion: nil) } - break - default: - var v = 0 - v = v+1 - // nop + default: () } } diff --git a/4champ/Utils/ModuleSharing.swift b/4champ/Utils/ModuleSharing.swift index bb793ad..48a6985 100644 --- a/4champ/Utils/ModuleSharing.swift +++ b/4champ/Utils/ModuleSharing.swift @@ -17,7 +17,7 @@ class ShareUtility: NSObject, UIActivityItemSource { } func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? { - guard let modName = sharedMod?.name, let composer = sharedMod?.composer, let _ = sharedMod?.id else { + guard let modName = sharedMod?.name, let composer = sharedMod?.composer, sharedMod?.id != nil else { return nil } let shareString = String.init(format: "Share_DefaultMessage".l13n(), modName, composer) @@ -25,7 +25,7 @@ class ShareUtility: NSObject, UIActivityItemSource { } func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivity.ActivityType?) -> String { - guard let modName = sharedMod?.name, let composer = sharedMod?.composer, let _ = sharedMod?.id else { + guard let modName = sharedMod?.name, let composer = sharedMod?.composer, sharedMod?.id != nil else { return "" } let shareString = String.init(format: "Share_DefaultMessage".l13n(), modName, composer) diff --git a/4champ/l13n/String+extension.swift b/4champ/l13n/String+extension.swift index c591f42..5d4b26a 100644 --- a/4champ/l13n/String+extension.swift +++ b/4champ/l13n/String+extension.swift @@ -20,8 +20,8 @@ extension String { private func fallbackL13N(debugPrefix: String) -> String { let fallbackLoc: String if let bundlePath = Bundle.main.path(forResource: "en", ofType: "lproj"), - let b = Bundle.init(path: bundlePath) { - fallbackLoc = b.localizedString(forKey: self, value: "", table: nil) + let bundle = Bundle.init(path: bundlePath) { + fallbackLoc = bundle.localizedString(forKey: self, value: "", table: nil) } else { fallbackLoc = self }