Skip to content

Commit

Permalink
Show colors in entry overview
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonCat4012 committed Mar 12, 2024
1 parent 3d311c9 commit 575b79d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Lotus/Screens/EditEntrysScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ struct EditEntrysScreen: View {
var body: some View {
List {
Section {
HStack {
Text("settings_SectionEditTypes_exampleDate")
Spacer()
Text("settings_SectionEditTypes_exampleID")
}.foregroundColor(.gray)
ForEach(vm.allEntries) { entry in
HStack {
Text(formatDate(entry.timestamp)) // TODO: show colors
Text(formatDate(entry.timestamp))
Spacer()
Text(String(entry.value))
typeView(entry)
}.swipeActions {
Button {
vm.deleteEntry(entry)
Expand All @@ -35,6 +40,16 @@ struct EditEntrysScreen: View {
}
}

func typeView(_ entry: Entry) -> some View {
ZStack {
RoundedRectangle(cornerRadius: 8)
.fill(vm.getColorForEntry(entry))
.frame(width: 35, height: 25)
Text(String(entry.value))
.frame(width: 35, height: 25)
}
}

func formatDate(_ date: Date) -> String {
let formatter = DateFormatter()
formatter.dateFormat = "dd.MM.yyyy"
Expand Down
7 changes: 7 additions & 0 deletions Lotus/Screens/RootScreenModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ class RootScreenModel: ObservableObject {
return Color(hexString: type.color)
}

func getColorForEntry(_ entry: Entry) -> Color {
guard let type = CoreData.getTypes().filter({ $0.rawValue == entry.value}).first else {
return Color.white.opacity(0.2)
}
return Color(hexString: type.color)
}

func getDaysInMonth(month: Int) -> Int {
let year = Int(selectedYear)
let calendar = Calendar.current
Expand Down
2 changes: 2 additions & 0 deletions Lotus/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"addEntry_type"="Typ auswählen";
"addEntry_addButtonTitle"="Hinzufügen";

"settings_SectionEditTypes_exampleID"="Typ ID";
"settings_SectionEditTypes_exampleDate"="Datum";
"settings_SectionEditTypes_title"="Typ bearbeiten";
"settings_SectionEditTypes_typename"="Typname";
"settings_SectionEditTypes_color"="Typfarbe";
Expand Down
2 changes: 2 additions & 0 deletions Lotus/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"addEntry_type"="Choose a type";
"addEntry_addButtonTitle"="Add";

"settings_SectionEditTypes_exampleID"="Type ID";
"settings_SectionEditTypes_exampleDate"="Date";
"settings_SectionEditTypes_title"="Edit Type";
"settings_SectionEditTypes_typename"="Typename";
"settings_SectionEditTypes_color"="Typecolor";
Expand Down

0 comments on commit 575b79d

Please sign in to comment.