Update duration format for buttons
This commit is contained in:
@@ -108,3 +108,28 @@ class DataController: ObservableObject {
|
|||||||
// return nil
|
// return nil
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extension Int64 {
|
||||||
|
func convertDurationSecondsToString() -> String {
|
||||||
|
var result = ""
|
||||||
|
// Separate into days, hours, minutes and seconds and take the largest one
|
||||||
|
let days: Int64 = self / 86400
|
||||||
|
let hours: Int64 = self / 60 / 60 % 60
|
||||||
|
let minutes: Int64 = self / 60 % 60
|
||||||
|
let seconds: Int64 = self % 60
|
||||||
|
if days > 0 {
|
||||||
|
result = "\(days)d"
|
||||||
|
} else if hours > 0 {
|
||||||
|
result = "\(hours)h"
|
||||||
|
} else if minutes > 0 {
|
||||||
|
result = "\(minutes)min"
|
||||||
|
} else if seconds > 0 {
|
||||||
|
result = "\(seconds)s"
|
||||||
|
} else {
|
||||||
|
result = "\(self)"
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -28,16 +28,16 @@ public class Flashcard: NSManagedObject {
|
|||||||
allCases.sorted {$0.rawValue < $1.rawValue }
|
allCases.sorted {$0.rawValue < $1.rawValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
static func getNext(milestone: SpacedRepetitionMilestoneEnum?) -> SpacedRepetitionMilestoneEnum? {
|
static func getNext(milestone: SpacedRepetitionMilestoneEnum?) -> SpacedRepetitionMilestoneEnum {
|
||||||
let sorted = SpacedRepetitionMilestoneEnum.allCasesSorted
|
let sorted = SpacedRepetitionMilestoneEnum.allCasesSorted
|
||||||
if milestone == nil {
|
if milestone == nil {
|
||||||
return sorted.first
|
return SpacedRepetitionMilestoneEnum.TenMinutes
|
||||||
}
|
}
|
||||||
let milestoneIndex = sorted.firstIndex(where: {$0.rawValue == milestone!.rawValue})!
|
let milestoneIndex = sorted.firstIndex(where: {$0.rawValue == milestone!.rawValue})!
|
||||||
if milestoneIndex < SpacedRepetitionMilestoneEnum.allCasesSorted.count {
|
if milestoneIndex < SpacedRepetitionMilestoneEnum.allCasesSorted.count {
|
||||||
return sorted[milestoneIndex + 1]
|
return sorted[milestoneIndex + 1]
|
||||||
}
|
}
|
||||||
return nil
|
return SpacedRepetitionMilestoneEnum.OneYear
|
||||||
}
|
}
|
||||||
|
|
||||||
static func getMilestoneFromInt(value: Int64) -> SpacedRepetitionMilestoneEnum {
|
static func getMilestoneFromInt(value: Int64) -> SpacedRepetitionMilestoneEnum {
|
||||||
|
|||||||
@@ -36,35 +36,35 @@ struct AnkiView: View {
|
|||||||
// .font(.subheadline)
|
// .font(.subheadline)
|
||||||
// .foregroundStyle(.gray)
|
// .foregroundStyle(.gray)
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
// TODO: Fix timeText, maybe using DateIntervallFormatter?
|
// TODO: Maybe create an algorithm to take into account the shownCount and not just always restart from 1 min?
|
||||||
NextRepetitionButtonView(
|
NextRepetitionButtonView(
|
||||||
buttonText: "Wrong",
|
buttonText: "Wrong",
|
||||||
nextMilestone: flashcards.first!.getSpacedRepetitionMilestone(),
|
nextMilestone: DataController.SpacedRepetitionMilestoneEnum.OneMinute,
|
||||||
flashcardId: flashcards.first!.id!,
|
flashcardId: flashcards.first!.id!,
|
||||||
width: geometry.size.width,
|
width: geometry.size.width,
|
||||||
color: .red,
|
color: .red,
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
timeText: "1m",
|
timeText: DataController.SpacedRepetitionMilestoneEnum.OneMinute.rawValue.convertDurationSecondsToString(),
|
||||||
showDescription: $showDescription
|
showDescription: $showDescription
|
||||||
)
|
)
|
||||||
NextRepetitionButtonView(
|
NextRepetitionButtonView(
|
||||||
buttonText: "Correct",
|
buttonText: "Correct",
|
||||||
nextMilestone: Flashcard.SpacedRepetitionMilestoneEnum.getNext(milestone: flashcards.first!.getSpacedRepetitionMilestone()),
|
nextMilestone: flashcards.first!.getSpacedRepetitionMilestone(),
|
||||||
flashcardId: flashcards.first!.id!,
|
flashcardId: flashcards.first!.id!,
|
||||||
width:geometry.size.width,
|
width:geometry.size.width,
|
||||||
color: .orange,
|
color: .orange,
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
timeText: "10m",
|
timeText: flashcards.first!.getSpacedRepetitionMilestone().rawValue.convertDurationSecondsToString(),
|
||||||
showDescription: $showDescription
|
showDescription: $showDescription
|
||||||
)
|
)
|
||||||
NextRepetitionButtonView(
|
NextRepetitionButtonView(
|
||||||
buttonText: "Easy",
|
buttonText: "Easy",
|
||||||
nextMilestone: Flashcard.SpacedRepetitionMilestoneEnum.getNext(milestone: Flashcard.SpacedRepetitionMilestoneEnum.getNext(milestone: flashcards.first!.getSpacedRepetitionMilestone())),
|
nextMilestone: Flashcard.SpacedRepetitionMilestoneEnum.getNext(milestone: flashcards.first!.getSpacedRepetitionMilestone()),
|
||||||
flashcardId: flashcards.first!.id!,
|
flashcardId: flashcards.first!.id!,
|
||||||
width: geometry.size.width,
|
width: geometry.size.width,
|
||||||
color: .green,
|
color: .green,
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
timeText: "1h",
|
timeText: Flashcard.SpacedRepetitionMilestoneEnum.getNext(milestone: flashcards.first!.getSpacedRepetitionMilestone()).rawValue.convertDurationSecondsToString(),
|
||||||
showDescription: $showDescription
|
showDescription: $showDescription
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ struct NextRepetitionButtonView: View {
|
|||||||
}) {
|
}) {
|
||||||
VStack {
|
VStack {
|
||||||
Text(buttonText)
|
Text(buttonText)
|
||||||
Text(">" + timeText)
|
Text(timeText)
|
||||||
.font(.footnote)
|
.font(.footnote)
|
||||||
.bold()
|
.bold()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user