Program a files app for my phone similar to the music app so I can shuffle my muscle…
- User
Program a files app for my phone similar to the music app so I can shuffle my muscle files iPhone
- Assistant
Program a files app for my phone similar to the music app so I can shuffle my muscle files iPhone
Creating a full-fledged iPhone app similar to the Music app for managing and shuffling your "muscle files" (I assume you mean muscle-related workout files, PDFs, or media) is quite involved and typically requires Xcode, Swift, and iOS development knowledge.
However, I can help you get started with a simple SwiftUI app that lists files from your app’s document directory and allows you to shuffle and open them. You can then customize this basic app to handle your specific file types (e.g., PDFs, images, workout videos).
import SwiftUI
import UniformTypeIdentifiers
struct ContentView: View {
@State private var files: [URL] = []
@State private var shuffledFiles: [URL] = []
@State private var selectedFile: URL?
@State private var showDocumentPicker = false
var body: some View {
NavigationView {
VStack {
HStack {
Button("Add Files") {
showDocumentPicker = true
}
.padding()
Button("Shuffle Files") {
shuffledFiles = files.shuffled()
}
.padding()
.disabled(files.isEmpty)
}
List(shuffledFiles.isEmpty ? files : shuffledFiles, id: \.self) { file in
Button(action: {
selectedFile = file
}) {
Text(file.lastPathComponent)
}
}
.listStyle(PlainListStyle())
}
.navigationTitle("Muscle Files")
.sheet(item: $selectedFile) { file in
DocumentPreview(url: file)
}
.fileImporter(isPresented: $showDocumentPicker, allowedContentTypes: [.pdf, .image, .movie, .text]) { result in
switch result {
case .success(let url):
copyFileToDocuments(url: url)
case .failure(let error):
print("Failed to import file: \(error.localizedDescription)")
}
}
.onAppear {
loadFiles()
}
}
}
func documentsDirectory() -> URL {
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
}
func loadFiles() {
do {
let docsURL = documentsDirectory()
let fileURLs = try FileManager.default.contentsOfDirectory(at: docsURL, includingPropertiesForKeys: nil)
self.files = fileURLs
} catch {
print("Error loading files: \(error.localizedDescription)")
}
}
func copyFileToDocuments(url: URL) {
let destURL = documentsDirectory().appendingPathComponent(url.lastPathComponent)
do {
if FileManager.default.fileExists(atPath: destURL.path) {
try FileManager.default.removeItem(at: destURL)
}
try FileManager.default.copyItem(at: url, to: destURL)
loadFiles()
} catch {
print("Error copying file: \(error.localizedDescription)")
}
}
}
struct DocumentPreview: UIViewControllerRepresentable {
let url: URL
func makeUIViewController(context: Context) -> UIDocumentInteractionControllerViewController {
return UIDocumentInteractionControllerViewController(url: url)
}
func updateUIViewController(_ uiViewController: UIDocumentInteractionControllerViewController, context: Context) {}
}
class UIDocumentInteractionControllerViewController: UIViewController, UIDocumentInteractionControllerDelegate {
var documentInteractionController: UIDocumentInteractionController!
let url: URL
init(url: URL) {
self.url = url
super.init(nibName: nil, bundle: nil)
documentInteractionController = UIDocumentInteractionController(url: url)
documentInteractionController.delegate = self
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
documentInteractionController.presentPreview(animated: true)
}
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
func documentInteractionControllerDidEndPreview(_ controller: UIDocumentInteractionController) {
dismiss(animated: true)
}
}
UIDocumentInteractionController).If you want me to help you with specific features or file types, or help with packaging this into a full app with more advanced UI, just let me know!
Not yet included in a published release.