Added release and pickup date. Pickup date is optional

This commit is contained in:
2021-06-06 10:09:33 +02:00
parent aa64cd0600
commit 87dbc9d1da
9 changed files with 32 additions and 21 deletions

View File

@@ -22,7 +22,7 @@ public class Console: NSManagedObject, Identifiable {
Game.compareByCreationDate(gameA: $0, gameB: $1) Game.compareByCreationDate(gameA: $0, gameB: $1)
}) else { return false } }) else { return false }
return newestGameConsoleA.pickupOrReleaseDate > newestGameConsoleB.pickupOrReleaseDate return newestGameConsoleA.releaseDate > newestGameConsoleB.releaseDate
} }
// Defining default values during creation // Defining default values during creation

View File

@@ -15,14 +15,14 @@ import SwiftUI
public class Game: NSManagedObject, Identifiable { public class Game: NSManagedObject, Identifiable {
public static func compareByCreationDate(gameA : Game, gameB : Game) -> Bool { public static func compareByCreationDate(gameA : Game, gameB : Game) -> Bool {
return gameA.pickupOrReleaseDate < gameB.pickupOrReleaseDate return gameA.releaseDate < gameB.releaseDate
} }
@objc @objc
private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) { private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context) super.init(entity: entity, insertInto: context)
self.pickupOrReleaseDate = Date() self.releaseDate = Date()
self.uuid = UUID() self.uuid = UUID()
print("Set UUID to \(self.uuid)") print("Set UUID to \(self.uuid)")
} }
@@ -35,8 +35,8 @@ extension Game : Encodable {
case notes case notes
case isDigital case isDigital
case lentTo case lentTo
case pickupOrReleaseDate case releaseDate
case isPickupDate case pickupDate
case publisher case publisher
case isFinished case isFinished
case finishedDate case finishedDate
@@ -56,8 +56,10 @@ extension Game : Encodable {
try container.encode(notes ?? "", forKey: .notes) try container.encode(notes ?? "", forKey: .notes)
try container.encode(isDigital, forKey: .isDigital) try container.encode(isDigital, forKey: .isDigital)
try container.encode(lentTo ?? "", forKey: .lentTo) try container.encode(lentTo ?? "", forKey: .lentTo)
try container.encode(pickupOrReleaseDate.formattedInTimeZone(), forKey: .pickupOrReleaseDate) try container.encode(releaseDate.formattedInTimeZone(), forKey: .releaseDate)
try container.encode(isPickupDate, forKey: .isPickupDate) if let pickupDate = pickupDate {
try container.encode(pickupDate.formattedInTimeZone(), forKey: .pickupDate)
}
try container.encode(pickupDescription ?? "", forKey: .pickupDescription) try container.encode(pickupDescription ?? "", forKey: .pickupDescription)
try container.encode(publisher ?? "", forKey: .publisher) try container.encode(publisher ?? "", forKey: .publisher)
try container.encode(isFinished, forKey: .isFinished) try container.encode(isFinished, forKey: .isFinished)

View File

@@ -18,8 +18,8 @@ extension Game {
} }
@NSManaged public var circumstances: String? @NSManaged public var circumstances: String?
@NSManaged public var isPickupDate : Bool @NSManaged public var releaseDate : Date
@NSManaged public var pickupOrReleaseDate: Date @NSManaged public var pickupDate: Date?
@NSManaged public var pickupDescription : String? @NSManaged public var pickupDescription : String?
@NSManaged public var inWishlist: Bool @NSManaged public var inWishlist: Bool
@NSManaged public var isDigital: Bool @NSManaged public var isDigital: Bool

View File

@@ -92,13 +92,18 @@ class LibraryImport {
cdGame.isDigital = game.isDigital cdGame.isDigital = game.isDigital
cdGame.playtime_h = game.playtime_h ?? 0 cdGame.playtime_h = game.playtime_h ?? 0
cdGame.playtime_min = game.playtime_min ?? 0 cdGame.playtime_min = game.playtime_min ?? 0
cdGame.isPickupDate = game.isPickupDate
if let date = Date.from(string: game.pickupOrReleaseDate) { if let pickupDate = game.pickupDate, let date = Date.from(string: pickupDate) {
cdGame.pickupOrReleaseDate = date cdGame.pickupDate = date
}else{
print("Could not decode date '\(game.pickupDate)' for game '\(cdGame.name)'")
}
if let date = Date.from(string: game.releaseDate) {
cdGame.releaseDate = date
}else{ }else{
print("Could not decode date '\(game.pickupOrReleaseDate)' for game '\(cdGame.name)'") print("Could not decode date '\(game.releaseDate)' for game '\(cdGame.name)'")
} }
cdConsole.addToGames(cdGame) cdConsole.addToGames(cdGame)
@@ -220,8 +225,8 @@ struct BHLGame : Decodable {
let isFinished : Bool let isFinished : Bool
let finishedDate : Date? let finishedDate : Date?
let notes : String? let notes : String?
let pickupOrReleaseDate : String let releaseDate : String
let isPickupDate : Bool = false let pickupDate : String?
let pickupDescription : String? let pickupDescription : String?
let publisher : String? let publisher : String?
let console : UUID let console : UUID

View File

@@ -68,7 +68,7 @@ struct GameView : View {
LazyVGrid(columns: columns) { LazyVGrid(columns: columns) {
InfoItem(headline: "Gekauft") { InfoItem(headline: "Gekauft") {
Text("\(game.pickupOrReleaseDate.formattedInTimeZone(dateFormat: Date.view_date_format))") Text("\(game.releaseDate.formattedInTimeZone(dateFormat: Date.view_date_format))")
.bold() .bold()
} }

View File

@@ -181,10 +181,14 @@ struct GameEditMode : View {
Section(header: Text("Details")) { Section(header: Text("Details")) {
DatePicker("In Sammlung seit", DatePicker("In Sammlung seit",
selection: $game.pickupOrReleaseDate, selection: $game.releaseDate,
in: ...Date(), in: ...Date(),
displayedComponents: [.date]) displayedComponents: [.date])
// Toggle(isOn: $game.isPickupDate, label: {
// Text("An dem Tag gesammelt?")
// })
HStack { HStack {
Text("Anlass") Text("Anlass")
TextEditor(text: pickupDscriptionBinding).frame(height: 100) TextEditor(text: pickupDscriptionBinding).frame(height: 100)

View File

@@ -16,7 +16,7 @@ struct GamePickupsView: View {
init() { init() {
let gamesFR = NSFetchRequest<Game>(entityName: "Game") let gamesFR = NSFetchRequest<Game>(entityName: "Game")
gamesFR.sortDescriptors = [NSSortDescriptor(key: "pickupOrReleaseDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)] gamesFR.sortDescriptors = [NSSortDescriptor(key: "releaseDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)]
gamesFR.fetchLimit = 50; gamesFR.fetchLimit = 50;
_games = FetchRequest(fetchRequest: gamesFR) _games = FetchRequest(fetchRequest: gamesFR)
} }

View File

@@ -54,7 +54,7 @@ struct EmptyCategory : View {
struct Overview: View { struct Overview: View {
@Environment(\.managedObjectContext) private var viewContext @Environment(\.managedObjectContext) private var viewContext
@FetchRequest(entity: Game.entity(), sortDescriptors: [NSSortDescriptor(key: "pickupOrReleaseDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)]) @FetchRequest(entity: Game.entity(), sortDescriptors: [NSSortDescriptor(key: "releaseDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)])
var games: FetchedResults<Game> var games: FetchedResults<Game>
@FetchRequest(entity: Game.entity(), sortDescriptors: [NSSortDescriptor(key: "finishedDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)]) @FetchRequest(entity: Game.entity(), sortDescriptors: [NSSortDescriptor(key: "finishedDate", ascending: false), NSSortDescriptor(key: "name", ascending: true)])

View File

@@ -27,15 +27,15 @@
<attribute name="inWishlist" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/> <attribute name="inWishlist" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="isDigital" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/> <attribute name="isDigital" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="isFinished" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/> <attribute name="isFinished" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isPickupDate" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="lentTo" optional="YES" attributeType="String"/> <attribute name="lentTo" optional="YES" attributeType="String"/>
<attribute name="name" attributeType="String" defaultValueString=""/> <attribute name="name" attributeType="String" defaultValueString=""/>
<attribute name="notes" optional="YES" attributeType="String"/> <attribute name="notes" optional="YES" attributeType="String"/>
<attribute name="pickupDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="pickupDescription" optional="YES" attributeType="String"/> <attribute name="pickupDescription" optional="YES" attributeType="String"/>
<attribute name="pickupOrReleaseDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="playtime_h" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/> <attribute name="playtime_h" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="playtime_min" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/> <attribute name="playtime_min" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="publisher" optional="YES" attributeType="String"/> <attribute name="publisher" optional="YES" attributeType="String"/>
<attribute name="releaseDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="uuid" optional="YES" attributeType="UUID" defaultValueString="00000000-0000-0000-0000-000000000000" usesScalarValueType="NO"/> <attribute name="uuid" optional="YES" attributeType="UUID" defaultValueString="00000000-0000-0000-0000-000000000000" usesScalarValueType="NO"/>
<relationship name="console" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Console" inverseName="games" inverseEntity="Console"/> <relationship name="console" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Console" inverseName="games" inverseEntity="Console"/>
<relationship name="series" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="GameSeries" inverseName="games" inverseEntity="GameSeries"/> <relationship name="series" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="GameSeries" inverseName="games" inverseEntity="GameSeries"/>