diff --git a/Zockerhoehle/ICloudManager.swift b/Zockerhoehle/ICloudManager.swift index 605fee2..2c15fe5 100644 --- a/Zockerhoehle/ICloudManager.swift +++ b/Zockerhoehle/ICloudManager.swift @@ -32,6 +32,7 @@ class ICloudManager { static public func fileExists(at path : String?) -> Bool { guard let path = path else { return false } + if path == "" { return false } if let url = documents_folder?.appendingPathComponent(path) { return FileManager.default.fileExists(atPath: url.path) diff --git a/Zockerhoehle/Views/ConsoleLibraryView.swift b/Zockerhoehle/Views/ConsoleLibraryView.swift index f7e1663..893cf85 100644 --- a/Zockerhoehle/Views/ConsoleLibraryView.swift +++ b/Zockerhoehle/Views/ConsoleLibraryView.swift @@ -95,6 +95,12 @@ struct ConsoleLibraryView : View { self.accessoryFetchRequest = FetchRequest(entity: Accessory.entity(), sortDescriptors: [NSSortDescriptor(key: "name", ascending: true)], predicate: NSPredicate(format: "console == %@", console)) } + let columns : [GridItem] = [ + GridItem(.adaptive(minimum: 100)) + ] + + let defaultImage = UIImage() + var body: some View { VStack { HStack { @@ -107,19 +113,38 @@ struct ConsoleLibraryView : View { Spacer() } if self.isVideogamesSelected { - List(games.filter({$0.inWishlist == self.showWishlist})) { game in - NavigationLink(destination: GameDetailView(game: game)) { - HStack { - Text("\(game.name ?? "n/a")") - - if game.isDigital { - Image("digitalGame") - .resizable() - .aspectRatio(contentMode: .fit) - .frame(height: 15) + ScrollView { + LazyVGrid(columns: columns, spacing: 20) { + ForEach(games.filter({$0.inWishlist == self.showWishlist})) { game in + NavigationLink(destination: GameDetailView(game: game)) { + if ICloudManager.fileExists(at: game.cover_icloud_path) { + Image(uiImage: ICloudManager.imageFrom(path: game.cover_icloud_path) ?? defaultImage) + .resizable() + .scaledToFit() + .cornerRadius(5) + }else{ + Group { + Text(game.name) + .font(.caption) + .foregroundColor(Color.black) + .padding() + .multilineTextAlignment(.center) + } + .frame(maxWidth: .infinity, maxHeight: .infinity) + .background(Color.gray) + .cornerRadius(5) + } + + +// if game.isDigital { +// Image("digitalGame") +// .resizable() +// .aspectRatio(contentMode: .fit) +// .frame(height: 15) +// } } } - } + }.padding() } }else { List(accessories.filter({$0.inWishlist == self.showWishlist})) {accessory in diff --git a/Zockerhoehle/Views/Overview.swift b/Zockerhoehle/Views/Overview.swift index 52c03b7..27beef0 100644 --- a/Zockerhoehle/Views/Overview.swift +++ b/Zockerhoehle/Views/Overview.swift @@ -91,7 +91,7 @@ struct Overview: View { Text("\(console.name)") .font(.caption) - .frame(width: 100) + .frame(width: 100) }.padding(.leading, 15) }.buttonStyle(PlainButtonStyle())