diff --git a/Music Tools.xcodeproj/project.pbxproj b/Music Tools.xcodeproj/project.pbxproj index 3b2327b..41c000a 100644 --- a/Music Tools.xcodeproj/project.pbxproj +++ b/Music Tools.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ @@ -11,7 +11,9 @@ E98254C223F9FFF90056D9D3 /* PlaylistView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E98254C123F9FFF90056D9D3 /* PlaylistView.swift */; }; E98254C823FA25D20056D9D3 /* PlaylistList.swift in Sources */ = {isa = PBXBuildFile; fileRef = E98254C723FA25D20056D9D3 /* PlaylistList.swift */; }; E98254CA23FA26600056D9D3 /* PlaylistRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = E98254C923FA26600056D9D3 /* PlaylistRow.swift */; }; - E98254CC23FA2D0A0056D9D3 /* NetTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E98254CB23FA2D0A0056D9D3 /* NetTypes.swift */; }; + E98254D023FB00B60056D9D3 /* LoginScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E98254CF23FB00B60056D9D3 /* LoginScreen.swift */; }; + E98254D923FB53780056D9D3 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = E98254D823FB53780056D9D3 /* Alamofire */; }; + E98254DB23FB64740056D9D3 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = E98254DA23FB64740056D9D3 /* Network.swift */; }; E9EA690B23F9A5430012C3E8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9EA690A23F9A5430012C3E8 /* AppDelegate.swift */; }; E9EA690D23F9A5430012C3E8 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9EA690C23F9A5430012C3E8 /* SceneDelegate.swift */; }; E9EA690F23F9A5430012C3E8 /* RootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9EA690E23F9A5430012C3E8 /* RootView.swift */; }; @@ -44,7 +46,8 @@ E98254C123F9FFF90056D9D3 /* PlaylistView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaylistView.swift; sourceTree = ""; }; E98254C723FA25D20056D9D3 /* PlaylistList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaylistList.swift; sourceTree = ""; }; E98254C923FA26600056D9D3 /* PlaylistRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaylistRow.swift; sourceTree = ""; }; - E98254CB23FA2D0A0056D9D3 /* NetTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetTypes.swift; sourceTree = ""; }; + E98254CF23FB00B60056D9D3 /* LoginScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginScreen.swift; sourceTree = ""; }; + E98254DA23FB64740056D9D3 /* Network.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = ""; }; E9EA690723F9A5430012C3E8 /* Music Tools.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Music Tools.app"; sourceTree = BUILT_PRODUCTS_DIR; }; E9EA690A23F9A5430012C3E8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; E9EA690C23F9A5430012C3E8 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -66,6 +69,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + E98254D923FB53780056D9D3 /* Alamofire in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -97,7 +101,7 @@ E98254BF23F9BE040056D9D3 /* Network */ = { isa = PBXGroup; children = ( - E98254CB23FA2D0A0056D9D3 /* NetTypes.swift */, + E98254DA23FB64740056D9D3 /* Network.swift */, ); path = Network; sourceTree = ""; @@ -109,6 +113,7 @@ E98254C123F9FFF90056D9D3 /* PlaylistView.swift */, E98254C723FA25D20056D9D3 /* PlaylistList.swift */, E98254C923FA26600056D9D3 /* PlaylistRow.swift */, + E98254CF23FB00B60056D9D3 /* LoginScreen.swift */, ); path = Views; sourceTree = ""; @@ -199,6 +204,9 @@ dependencies = ( ); name = "Music Tools"; + packageProductDependencies = ( + E98254D823FB53780056D9D3 /* Alamofire */, + ); productName = "Music Tools"; productReference = E9EA690723F9A5430012C3E8 /* Music Tools.app */; productType = "com.apple.product-type.application"; @@ -271,6 +279,9 @@ Base, ); mainGroup = E9EA68FE23F9A5430012C3E8; + packageReferences = ( + E98254D723FB53770056D9D3 /* XCRemoteSwiftPackageReference "alamofire" */, + ); productRefGroup = E9EA690823F9A5430012C3E8 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -314,14 +325,15 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - E98254CC23FA2D0A0056D9D3 /* NetTypes.swift in Sources */, E98254CA23FA26600056D9D3 /* PlaylistRow.swift in Sources */, E9EA690B23F9A5430012C3E8 /* AppDelegate.swift in Sources */, E9EA690D23F9A5430012C3E8 /* SceneDelegate.swift in Sources */, + E98254DB23FB64740056D9D3 /* Network.swift in Sources */, E98254C823FA25D20056D9D3 /* PlaylistList.swift in Sources */, E9EA690F23F9A5430012C3E8 /* RootView.swift in Sources */, E98254BD23F9B7A90056D9D3 /* Playlist.swift in Sources */, E98254C223F9FFF90056D9D3 /* PlaylistView.swift in Sources */, + E98254D023FB00B60056D9D3 /* LoginScreen.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -646,6 +658,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + E98254D723FB53770056D9D3 /* XCRemoteSwiftPackageReference "alamofire" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/alamofire/alamofire.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 5.0.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + E98254D823FB53780056D9D3 /* Alamofire */ = { + isa = XCSwiftPackageProductDependency; + package = E98254D723FB53770056D9D3 /* XCRemoteSwiftPackageReference "alamofire" */; + productName = Alamofire; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = E9EA68FF23F9A5430012C3E8 /* Project object */; } diff --git a/Music Tools.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Music Tools.xcodeproj/project.xcworkspace/contents.xcworkspacedata index b064cd0..919434a 100644 --- a/Music Tools.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/Music Tools.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/Music Tools.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Music Tools.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..2b10548 --- /dev/null +++ b/Music Tools.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "Alamofire", + "repositoryURL": "https://github.com/alamofire/alamofire.git", + "state": { + "branch": null, + "revision": "0c8cb78d05b6d067ee331c05058ff4dedcb45ffa", + "version": "5.0.0" + } + } + ] + }, + "version": 1 +} diff --git a/Music Tools/Application/Base.lproj/LaunchScreen.storyboard b/Music Tools/Application/Base.lproj/LaunchScreen.storyboard index 125fd91..cb7f638 100644 --- a/Music Tools/Application/Base.lproj/LaunchScreen.storyboard +++ b/Music Tools/Application/Base.lproj/LaunchScreen.storyboard @@ -14,6 +14,12 @@ + + + + + + @@ -23,4 +29,7 @@ + + + diff --git a/Music Tools/Assets.xcassets/Logo.imageset/Contents.json b/Music Tools/Assets.xcassets/Logo.imageset/Contents.json new file mode 100644 index 0000000..3c5822e --- /dev/null +++ b/Music Tools/Assets.xcassets/Logo.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "MusicToolsIcon1024.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Music Tools/Assets.xcassets/Logo.imageset/MusicToolsIcon1024.png b/Music Tools/Assets.xcassets/Logo.imageset/MusicToolsIcon1024.png new file mode 100644 index 0000000..326d083 Binary files /dev/null and b/Music Tools/Assets.xcassets/Logo.imageset/MusicToolsIcon1024.png differ diff --git a/Music Tools/Assets.xcassets/first.imageset/Contents.json b/Music Tools/Assets.xcassets/first.imageset/Contents.json deleted file mode 100644 index 33a7451..0000000 --- a/Music Tools/Assets.xcassets/first.imageset/Contents.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "filename" : "first.pdf" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/Music Tools/Assets.xcassets/first.imageset/first.pdf b/Music Tools/Assets.xcassets/first.imageset/first.pdf deleted file mode 100644 index 47d911d..0000000 Binary files a/Music Tools/Assets.xcassets/first.imageset/first.pdf and /dev/null differ diff --git a/Music Tools/Assets.xcassets/second.imageset/Contents.json b/Music Tools/Assets.xcassets/second.imageset/Contents.json deleted file mode 100644 index 03bd9c9..0000000 --- a/Music Tools/Assets.xcassets/second.imageset/Contents.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "filename" : "second.pdf" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/Music Tools/Assets.xcassets/second.imageset/second.pdf b/Music Tools/Assets.xcassets/second.imageset/second.pdf deleted file mode 100644 index 401614e..0000000 Binary files a/Music Tools/Assets.xcassets/second.imageset/second.pdf and /dev/null differ diff --git a/Music Tools/Network/NetTypes.swift b/Music Tools/Network/NetTypes.swift deleted file mode 100644 index 3609730..0000000 --- a/Music Tools/Network/NetTypes.swift +++ /dev/null @@ -1,33 +0,0 @@ -// -// EndPointType.swift -// Music Tools -// -// Created by Ellie McCarthy on 17/02/2020. -// Copyright © 2020 Sarsoo. All rights reserved. -// - -import Foundation - -protocol EndPointType { - var domain: URL { get } - var path: String { get } - var httpMethod: HTTPMethod { get } - var task: HTTPTask { get } - var headers: HTTPHeaders? { get } -} - -public enum HTTPMethod: String { - case get = "GET" - case post = "POST" - case put = "PUT" - case delete = "DELETE" -} - -public typealias HTTPHeaders = [String:String] -public typealias Parameters = [String:Any] - -public enum HTTPTask { - case request - - case requestParameters(bodyParameters: Parameters?, urlParameters: Parameters?) -} diff --git a/Music Tools/Network/Network.swift b/Music Tools/Network/Network.swift new file mode 100644 index 0000000..8ae40f8 --- /dev/null +++ b/Music Tools/Network/Network.swift @@ -0,0 +1,80 @@ +// +// Network.swift +// Music Tools +// +// Created by Andy Pack on 18/02/2020. +// Copyright © 2020 Sarsoo. All rights reserved. +// + +import Foundation +import Alamofire + +class MusicToolsNetwork { + + var baseBath: String = "https://music.sarsoo.xyz/" + + public func request(path: String, + method: Alamofire.HTTPMethod, + parameters: [String:String]? , + encoder: Alamofire.ParameterEncoder?, + headers: Alamofire.HTTPHeaders? ) { + + guard let uwParameters = parameters else { + AF.request(baseBath + path, + method: method, + headers: headers ).validate().response { response in + debugPrint(response) + } + return + } + + AF.request(baseBath + path, + method: method, + parameters: uwParameters, + headers: headers ).response { response in + debugPrint(response) + } + + } +} + +class BasicAuthNetwork: MusicToolsNetwork { + var username: String + var password: String + + init(username: String, password: String) { + self.username = username + self.password = password + } + + func getHeader() -> String { + return "\(username):\(password)".toBase64() + } + + public func authedRequest(path: String, + method: Alamofire.HTTPMethod, + parameters: [String:String]?, + encoder: Alamofire.ParameterEncoder?, + headers: Alamofire.HTTPHeaders? ) { + + let encoded = "\(username):\(password)".toBase64() + + var txHeaders = headers + + if headers == nil { + txHeaders = Alamofire.HTTPHeaders() + } + txHeaders?.add(name: "Authorization", value: "Basic \(encoded)") + + request(path: path, method: method, parameters: parameters, encoder: encoder, headers: txHeaders) + + } +} + +extension String { + + func toBase64() -> String { + return Data(self.utf8).base64EncodedString() + } + +} diff --git a/Music Tools/Views/LoginScreen.swift b/Music Tools/Views/LoginScreen.swift new file mode 100644 index 0000000..25b3664 --- /dev/null +++ b/Music Tools/Views/LoginScreen.swift @@ -0,0 +1,43 @@ +// +// LoginScreen.swift +// Music Tools +// +// Created by Andy Pack on 17/02/2020. +// Copyright © 2020 Sarsoo. All rights reserved. +// + +import SwiftUI + +struct LoginScreen: View { + var body: some View { + VStack { + Image("Logo") + .resizable() + .frame(width: 200.0, height: 200.0, alignment: .trailing) + .cornerRadius(18) + .shadow(radius: /*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/) + .padding(.bottom, 20) + Text("Sarsoo Music Tools") + .font(.largeTitle) + TextField("Username", text: /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Value@*/.constant("")/*@END_MENU_TOKEN@*/) + SecureField("Password", text: /*@START_MENU_TOKEN@*/ /*@PLACEHOLDER=Value@*/.constant("Apple")/*@END_MENU_TOKEN@*/) + HStack { + Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/) { + Text("Log In") + + } + .padding(.trailing, 20.0) + Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/) { + Text("Register") + } + } + } + .padding() + } +} + +struct LoginScreen_Previews: PreviewProvider { + static var previews: some View { + LoginScreen() + } +} diff --git a/Music Tools/Views/PlaylistList.swift b/Music Tools/Views/PlaylistList.swift index fd52270..d015846 100644 --- a/Music Tools/Views/PlaylistList.swift +++ b/Music Tools/Views/PlaylistList.swift @@ -1,8 +1,8 @@ // -// SwiftUIView.swift +// PlaylistList.swift // Music Tools // -// Created by Ellie McCarthy on 17/02/2020. +// Created by Andy Pack on 17/02/2020. // Copyright © 2020 Sarsoo. All rights reserved. // diff --git a/Music Tools/Views/PlaylistRow.swift b/Music Tools/Views/PlaylistRow.swift index fb7ed88..77d7e05 100644 --- a/Music Tools/Views/PlaylistRow.swift +++ b/Music Tools/Views/PlaylistRow.swift @@ -2,7 +2,7 @@ // PlaylistRow.swift // Music Tools // -// Created by Ellie McCarthy on 17/02/2020. +// Created by Andy Pack on 17/02/2020. // Copyright © 2020 Sarsoo. All rights reserved. // diff --git a/Music Tools/Views/PlaylistView.swift b/Music Tools/Views/PlaylistView.swift index a3c51c8..0624595 100644 --- a/Music Tools/Views/PlaylistView.swift +++ b/Music Tools/Views/PlaylistView.swift @@ -2,7 +2,7 @@ // PlaylistView.swift // Music Tools // -// Created by Ellie McCarthy on 16/02/2020. +// Created by Andy Pack on 16/02/2020. // Copyright © 2020 Sarsoo. All rights reserved. // diff --git a/Music Tools/Views/RootView.swift b/Music Tools/Views/RootView.swift index ed04305..e8c971a 100644 --- a/Music Tools/Views/RootView.swift +++ b/Music Tools/Views/RootView.swift @@ -1,5 +1,5 @@ // -// ContentView.swift +// RootView.swift // Music Tools // // Created by Andy Pack on 16/02/2020. @@ -7,44 +7,69 @@ // import SwiftUI +import Alamofire struct RootView: View { @State private var selection = 0 var body: some View { TabView(selection: $selection){ - List(/*@START_MENU_TOKEN@*/0 ..< 5/*@END_MENU_TOKEN@*/) { item in - Text("Playlists") - .font(.title) - + NavigationView { + List(/*@START_MENU_TOKEN@*/0 ..< 5/*@END_MENU_TOKEN@*/) { item in + Text("Playlist") + .font(.title) + + } + .navigationBarTitle(Text("Playlists").font(.title)) } .tabItem { VStack { - Image("first") + Image(systemName: "music.note.list") Text("Playlists") } } .tag(0) - Text("Tags") - .font(.title) - .tabItem { - VStack { - Image("second") - Text("Tags") - } + // + // + NavigationView { + List(/*@START_MENU_TOKEN@*/0 ..< 5/*@END_MENU_TOKEN@*/) { item in + Text("Tag") + .font(.title) + } - .tag(1) + .navigationBarTitle(Text("Tags")) + } + .tabItem { + VStack { + Image(systemName: "sum") + Text("Tags") + } + } + .tag(1) + // + // Text("Settings") .font(.title) .tabItem { VStack { - Image("first") + Image(systemName: "slider.horizontal.3") Text("Settings") } } .tag(2) + }.onAppear { + self.fetch() } } + + private func fetch() { + let net: BasicAuthNetwork = BasicAuthNetwork(username: "", password: "") + net.authedRequest(path: "api/playlist", + method: Alamofire.HTTPMethod.get, + parameters: ["name": ""], + encoder: nil, + headers: nil) + } } struct RootView_Previews: PreviewProvider { diff --git a/Music ToolsTests/Music_ToolsTests.swift b/Music ToolsTests/Music_ToolsTests.swift index 7dba602..3eaf556 100644 --- a/Music ToolsTests/Music_ToolsTests.swift +++ b/Music ToolsTests/Music_ToolsTests.swift @@ -2,7 +2,7 @@ // Music_ToolsTests.swift // Music ToolsTests // -// Created by Ellie McCarthy on 16/02/2020. +// Created by Andy Pack on 16/02/2020. // Copyright © 2020 Sarsoo. All rights reserved. // diff --git a/Music ToolsUITests/Music_ToolsUITests.swift b/Music ToolsUITests/Music_ToolsUITests.swift index e98f370..b500ccd 100644 --- a/Music ToolsUITests/Music_ToolsUITests.swift +++ b/Music ToolsUITests/Music_ToolsUITests.swift @@ -2,7 +2,7 @@ // Music_ToolsUITests.swift // Music ToolsUITests // -// Created by Ellie McCarthy on 16/02/2020. +// Created by Andy Pack on 16/02/2020. // Copyright © 2020 Sarsoo. All rights reserved. //