From 7b2a1bc2985fda0edb54adc668eb1d50ea47c955 Mon Sep 17 00:00:00 2001 From: Diogo Simao Marques <dogo@videolabs.io> Date: Tue, 10 Dec 2024 10:14:16 +0100 Subject: [PATCH] CustomEqualizerProfiles: Move its implementation to a proper file Everything related to the custom equalizer profiles is now located in a proper dedicated file. --- .../Subviews/CustomEqualizerProfiles.swift | 120 ++++++++++++++++++ .../Subviews/EqualizerView.swift | 103 --------------- VLC.xcodeproj/project.pbxproj | 4 + 3 files changed, 124 insertions(+), 103 deletions(-) create mode 100644 Sources/Playback/Player/VideoPlayer-iOS/Subviews/CustomEqualizerProfiles.swift diff --git a/Sources/Playback/Player/VideoPlayer-iOS/Subviews/CustomEqualizerProfiles.swift b/Sources/Playback/Player/VideoPlayer-iOS/Subviews/CustomEqualizerProfiles.swift new file mode 100644 index 000000000..1ee4d69a2 --- /dev/null +++ b/Sources/Playback/Player/VideoPlayer-iOS/Subviews/CustomEqualizerProfiles.swift @@ -0,0 +1,120 @@ +/***************************************************************************** +* EqualizerView.swift +* +* Copyright © 2020 VLC authors and VideoLAN +* +* Authors: Diogo Simao Marques <dogo@videolabs.io> +* +* Refer to the COPYING file of the official project for license. +*****************************************************************************/ + +import UIKit + +// MARK: - MoveEventIdentifier + +enum MoveEventIdentifier: Int { + case up = 1 + case down +} + +// MARK: - EqualizerEditActionsIdentifier + +@objc enum EqualizerEditActionsIdentifier: Int { + case rename = 1 + case delete +} + +// MARK: - CustomEqualizerProfile + +class CustomEqualizerProfile: NSObject, NSCoding { + var name: String + var preAmpLevel: Float + var frequencies: [Float] + + init(name: String, preAmpLevel: Float, frequencies: [Float]) { + self.name = name + self.preAmpLevel = preAmpLevel + self.frequencies = frequencies + } + + required init?(coder: NSCoder) { + guard let name = coder.decodeObject(forKey: "name") as? String, + let frequencies = coder.decodeObject(forKey: "frequencies") as? [Float] else { + self.name = "" + self.preAmpLevel = 6.0 + self.frequencies = [] + return + } + + self.name = name + self.preAmpLevel = coder.decodeFloat(forKey: "preAmpLevel") + self.frequencies = frequencies + } + + func encode(with coder: NSCoder) { + coder.encode(name, forKey: "name") + coder.encode(preAmpLevel, forKey: "preAmpLevel") + coder.encode(frequencies, forKey: "frequencies") + } +} + +// MARK: - CustomEqualizerProfiles + +class CustomEqualizerProfiles: NSObject, NSCoding { + var profiles: [CustomEqualizerProfile] + + required init?(coder: NSCoder) { + guard let customProfiles = coder.decodeObject(forKey: "profiles") as? [CustomEqualizerProfile] else { + self.profiles = [] + return + } + + self.profiles = customProfiles + } + + init(profiles: [CustomEqualizerProfile]) { + self.profiles = profiles + } + + func encode(with coder: NSCoder) { + coder.encode(self.profiles, forKey: "profiles") + } + + func moveUp(index: Int) { + guard index - 1 >= 0 else { + return + } + + profiles.swapAt(index, index - 1) + + let userDefaults = UserDefaults.standard + if userDefaults.bool(forKey: kVLCCustomProfileEnabled) { + let currentProfileIndex = userDefaults.integer(forKey: kVLCSettingEqualizerProfile) + + if currentProfileIndex == index { + userDefaults.setValue(index - 1, forKeyPath: kVLCSettingEqualizerProfile) + } else if currentProfileIndex == index - 1 { + userDefaults.setValue(index, forKey: kVLCSettingEqualizerProfile) + } + } + } + + func moveDown(index: Int) { + guard index + 1 < profiles.count else { + return + } + + profiles.swapAt(index, index + 1) + + let userDefaults = UserDefaults.standard + if userDefaults.bool(forKey: kVLCCustomProfileEnabled) { + let currentProfileIndex = userDefaults.integer(forKey: kVLCSettingEqualizerProfile) + + if currentProfileIndex == index { + userDefaults.setValue(index + 1, forKeyPath: kVLCSettingEqualizerProfile) + } else if currentProfileIndex == index + 1 { + userDefaults.setValue(index, forKey: kVLCSettingEqualizerProfile) + } + } + } +} diff --git a/Sources/Playback/Player/VideoPlayer-iOS/Subviews/EqualizerView.swift b/Sources/Playback/Player/VideoPlayer-iOS/Subviews/EqualizerView.swift index 0223c9c79..58b67cace 100644 --- a/Sources/Playback/Player/VideoPlayer-iOS/Subviews/EqualizerView.swift +++ b/Sources/Playback/Player/VideoPlayer-iOS/Subviews/EqualizerView.swift @@ -11,109 +11,6 @@ import UIKit -// MARK: - Custom Equalizer Profiles -class CustomEqualizerProfile: NSObject, NSCoding { - var name: String - var preAmpLevel: Float - var frequencies: [Float] - - init(name: String, preAmpLevel: Float, frequencies: [Float]) { - self.name = name - self.preAmpLevel = preAmpLevel - self.frequencies = frequencies - } - - required init?(coder: NSCoder) { - guard let name = coder.decodeObject(forKey: "name") as? String, - let frequencies = coder.decodeObject(forKey: "frequencies") as? [Float] else { - self.name = "" - self.preAmpLevel = 6.0 - self.frequencies = [] - return - } - - self.name = name - self.preAmpLevel = coder.decodeFloat(forKey: "preAmpLevel") - self.frequencies = frequencies - } - - func encode(with coder: NSCoder) { - coder.encode(name, forKey: "name") - coder.encode(preAmpLevel, forKey: "preAmpLevel") - coder.encode(frequencies, forKey: "frequencies") - } -} - -class CustomEqualizerProfiles: NSObject, NSCoding { - var profiles: [CustomEqualizerProfile] - - required init?(coder: NSCoder) { - guard let customProfiles = coder.decodeObject(forKey: "profiles") as? [CustomEqualizerProfile] else { - self.profiles = [] - return - } - - self.profiles = customProfiles - } - - init(profiles: [CustomEqualizerProfile]) { - self.profiles = profiles - } - - func encode(with coder: NSCoder) { - coder.encode(self.profiles, forKey: "profiles") - } - - func moveUp(index: Int) { - guard index - 1 >= 0 else { - return - } - - profiles.swapAt(index, index - 1) - - let userDefaults = UserDefaults.standard - if userDefaults.bool(forKey: kVLCCustomProfileEnabled) { - let currentProfileIndex = userDefaults.integer(forKey: kVLCSettingEqualizerProfile) - - if currentProfileIndex == index { - userDefaults.setValue(index - 1, forKeyPath: kVLCSettingEqualizerProfile) - } else if currentProfileIndex == index - 1 { - userDefaults.setValue(index, forKey: kVLCSettingEqualizerProfile) - } - } - } - - func moveDown(index: Int) { - guard index + 1 < profiles.count else { - return - } - - profiles.swapAt(index, index + 1) - - let userDefaults = UserDefaults.standard - if userDefaults.bool(forKey: kVLCCustomProfileEnabled) { - let currentProfileIndex = userDefaults.integer(forKey: kVLCSettingEqualizerProfile) - - if currentProfileIndex == index { - userDefaults.setValue(index + 1, forKeyPath: kVLCSettingEqualizerProfile) - } else if currentProfileIndex == index + 1 { - userDefaults.setValue(index, forKey: kVLCSettingEqualizerProfile) - } - } - } -} - -enum MoveEventIdentifier: Int { - case up = 1 - case down -} - -// MARK: - EqualizerEditActionsIdentifier -@objc enum EqualizerEditActionsIdentifier: Int { - case rename = 1 - case delete -} - @objc class EqualizerView: UIView { // MARK: - EqualizerFrequency structure diff --git a/VLC.xcodeproj/project.pbxproj b/VLC.xcodeproj/project.pbxproj index 0d48f6bcc..6aaf03cd1 100644 --- a/VLC.xcodeproj/project.pbxproj +++ b/VLC.xcodeproj/project.pbxproj @@ -428,6 +428,7 @@ D9B36AF62AF4020000A10C99 /* AspectRatio.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9B36AF42AF3E01200A10C99 /* AspectRatio.swift */; }; D9B4027D298BEF4F007E923F /* AlbumHeaderFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9B4027C298BEF4F007E923F /* AlbumHeaderFlowLayout.swift */; }; D9B421732B14AB1C000F7318 /* ABRepeatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9B421722B14AB1C000F7318 /* ABRepeatView.swift */; }; + D9D6907D2D083B62008C6C40 /* CustomEqualizerProfiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9D6907C2D083B5D008C6C40 /* CustomEqualizerProfiles.swift */; }; D9D6E989291BDF2200ADBC74 /* AudioPlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9D6E988291BDF2200ADBC74 /* AudioPlayerViewController.swift */; }; D9F0D67A2937624900A97964 /* PlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9F0D6792937624900A97964 /* PlayerViewController.swift */; }; DD1B31F41BF637D500A369B6 /* VLCPlaybackInfoTracksTVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD1B31F21BF637D500A369B6 /* VLCPlaybackInfoTracksTVViewController.m */; }; @@ -1180,6 +1181,7 @@ D9B36AF42AF3E01200A10C99 /* AspectRatio.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AspectRatio.swift; sourceTree = "<group>"; }; D9B4027C298BEF4F007E923F /* AlbumHeaderFlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbumHeaderFlowLayout.swift; sourceTree = "<group>"; }; D9B421722B14AB1C000F7318 /* ABRepeatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ABRepeatView.swift; sourceTree = "<group>"; }; + D9D6907C2D083B5D008C6C40 /* CustomEqualizerProfiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomEqualizerProfiles.swift; sourceTree = "<group>"; }; D9D6E988291BDF2200ADBC74 /* AudioPlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayerViewController.swift; sourceTree = "<group>"; }; D9F0D6792937624900A97964 /* PlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerViewController.swift; sourceTree = "<group>"; }; DD13A3791BEE2FAA00A35554 /* VLCMaskView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCMaskView.h; sourceTree = "<group>"; }; @@ -1865,6 +1867,7 @@ D9AFDCA427D6383F002326CC /* BookmarksView.swift */, 6D86F50425F8168600044C79 /* SpoilerButton.swift */, 6D758AA82577DDAF0016F675 /* EqualizerView.swift */, + D9D6907C2D083B5D008C6C40 /* CustomEqualizerProfiles.swift */, 6D8EC09125F8010E00FDDE17 /* EqualizerPresetSelector.swift */, D9B421722B14AB1C000F7318 /* ABRepeatView.swift */, 0F47AB942C1C42FF004B630F /* LongPressPlaybackSpeedView.swift */, @@ -3864,6 +3867,7 @@ 7D3784C3183A9938009EE944 /* VLCStatusLabel.m in Sources */, 6CC3F6B32D230AEF00C15E33 /* PictureInPictureMediaController.swift in Sources */, 4144156C20ECE6330078EC37 /* FileServerView.swift in Sources */, + D9D6907D2D083B62008C6C40 /* CustomEqualizerProfiles.swift in Sources */, 40C95A07256E929D002DD208 /* PlaybackSpeedView.swift in Sources */, 416DACB720B6DB9A001BC75D /* PlayingExternallyView.swift in Sources */, 41EC28E52136DD41004BCF0F /* MovieCollectionViewCell.swift in Sources */, -- GitLab