Created
June 6, 2020 07:41
-
-
Save InukVT/8ea7f0ad94fd92ef1a97aa0eccee69be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct ContentView: View { | |
| @Environment(\.managedObjectContext) | |
| var moc | |
| /* | |
| @FetchRequest(entity: Songs.entity(), | |
| sortDescriptors: []) | |
| var songs: FetchedResults<Songs> | |
| */ | |
| @EnvironmentObject | |
| var player: Player | |
| @State private var links: [URL] = [ | |
| URL(string: "https://twitter.com/mecid")! | |
| ] | |
| var body: some View { | |
| VStack { | |
| NavigationView { | |
| List { | |
| ForEach(player.all, id: \.self) { song in | |
| SongCellView(song: song) | |
| } | |
| .onDrop(of: ["public.url"], delegate: songDropDelegate(bookmarks: $links)) | |
| //.onInsert(of: Player.supportedFiles, perform: self.drop) | |
| } | |
| .onAppear { | |
| UITableView.appearance() | |
| .separatorStyle = .none | |
| } | |
| .navigationBarTitle(Text("Song")) | |
| .navigationBarItems(trailing: DocumentPickerButton(documentTypes: Player.supportedFiles, | |
| onOpen: self.openSong){ | |
| Image(systemName: "plus.circle.fill") | |
| .resizable() | |
| .padding() | |
| } ) | |
| } | |
| if self.player.nowPlaying != nil { | |
| GlobalControls() | |
| } else { | |
| EmptyView() | |
| } | |
| } | |
| } | |
| func openSong (urls: [URL]) -> () { | |
| print("Reading URLS") | |
| urls.forEach { url in | |
| guard url.startAccessingSecurityScopedResource() else { | |
| print("Failed to open the file") | |
| return | |
| } | |
| print(url) | |
| defer { url.stopAccessingSecurityScopedResource() } | |
| self.player.add(url: url) | |
| } | |
| } | |
| } | |
| struct songDropDelegate: DropDelegate { | |
| @Binding var bookmarks: [URL] | |
| func performDrop(info: DropInfo) -> Bool { | |
| guard info.hasItemsConforming(to: ["public.url"]) else { | |
| return false | |
| } | |
| let items = info.itemProviders(for: ["public.url"]) | |
| items.forEach { item in | |
| _ = item.loadObject(ofClass: URL.self) { url, error in | |
| print(url) | |
| } | |
| } | |
| return true | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment