WIP - a lot of uncommitted work
This commit is contained in:
@@ -23,13 +23,15 @@ struct AddMoodHeaderView: View {
|
||||
.foregroundColor(Color(UIColor.label))
|
||||
.padding()
|
||||
HStack{
|
||||
ForEach(Mood.allValues) { mood in
|
||||
ForEach(Mood.allValues.reversed()) { mood in
|
||||
VStack {
|
||||
Button(action: {
|
||||
addItem(withMoodValue: mood.rawValue)
|
||||
}, label: {
|
||||
mood.icon
|
||||
.font(.system(size: 50))
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50, alignment: .center)
|
||||
.foregroundColor(mood.color)
|
||||
})
|
||||
|
||||
//Text(mood.strValue)
|
||||
@@ -50,7 +52,7 @@ struct AddMoodHeaderView: View {
|
||||
let newItem = MoodEntry(context: viewContext)
|
||||
newItem.timestamp = Date()
|
||||
newItem.moodValue = Int16(moodValue)
|
||||
newItem.date = Date()
|
||||
newItem.forDate = Date()
|
||||
|
||||
do {
|
||||
try viewContext.save()
|
||||
|
||||
41
Shared/views/CircleView.swift
Normal file
41
Shared/views/CircleView.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// CircleView.swift
|
||||
// Feels (iOS)
|
||||
//
|
||||
// Created by Trey Tartt on 1/13/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct DayChartView: View, Hashable {
|
||||
|
||||
enum ViewType: Hashable {
|
||||
case cicle
|
||||
case square
|
||||
case text(String)
|
||||
}
|
||||
|
||||
let color: Color
|
||||
let weekDay: Int
|
||||
let viewType: ViewType
|
||||
|
||||
var body: some View {
|
||||
switch viewType {
|
||||
case .cicle:
|
||||
Circle()
|
||||
.fill(color)
|
||||
.frame(minWidth: 5, idealWidth: 50, maxWidth: 50, minHeight: 5, idealHeight: 20, maxHeight: 50, alignment: .center)
|
||||
.opacity(color == Mood.missing.color ? 0.5 : 1.0)
|
||||
case .square:
|
||||
Rectangle()
|
||||
.fill(color)
|
||||
.frame(minWidth: 5, idealWidth: 50, maxWidth: 50, minHeight: 5, idealHeight: 20, maxHeight: 50, alignment: .center)
|
||||
case .text(let value):
|
||||
Text(value)
|
||||
.font(.footnote)
|
||||
.frame(minWidth: 5, idealWidth: 50, maxWidth: 50, minHeight: 5, idealHeight: 20, maxHeight: 50, alignment: .center)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ struct ContentView: View {
|
||||
@State private var showTodayInput = true
|
||||
|
||||
@FetchRequest(
|
||||
sortDescriptors: [NSSortDescriptor(keyPath: \MoodEntry.date, ascending: false)],
|
||||
sortDescriptors: [NSSortDescriptor(keyPath: \MoodEntry.forDate, ascending: false)],
|
||||
animation: .spring())
|
||||
private var items: FetchedResults<MoodEntry>
|
||||
|
||||
@@ -29,10 +29,16 @@ struct ContentView: View {
|
||||
Label("Main", systemImage: "list.dash")
|
||||
}
|
||||
|
||||
FilterView()
|
||||
.tabItem {
|
||||
Label("Filter", systemImage: "calendar.circle")
|
||||
}
|
||||
|
||||
GraphView()
|
||||
.tabItem {
|
||||
Label("Graph", systemImage: "chart.line.uptrend.xyaxis")
|
||||
Label("Stats", systemImage: "chart.line.uptrend.xyaxis")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,13 +62,15 @@ struct ContentView: View {
|
||||
ForEach(items) { item in
|
||||
HStack {
|
||||
item.mood.icon
|
||||
.font(.system(size: 50))
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50, alignment: .center)
|
||||
.foregroundColor(item.mood.color)
|
||||
VStack {
|
||||
Text("\(item.moodString)")
|
||||
.font(.title)
|
||||
.foregroundColor(Color(UIColor.systemGray))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Text(item.date!, style: .date)
|
||||
Text(item.forDate ?? Date(), style: .date)
|
||||
.font(.body)
|
||||
.foregroundColor(Color(UIColor.label))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
@@ -123,8 +131,8 @@ struct ContentView: View {
|
||||
// Note: Times are printed in UTC. Depending on where you live it won't print 00:00:00 but it will work with UTC times which can be converted to local time
|
||||
|
||||
// Set predicate as date being today's date
|
||||
let fromPredicate = NSPredicate(format: "%@ <= %K", dateFrom as NSDate, #keyPath(MoodEntry.date))
|
||||
let toPredicate = NSPredicate(format: "%K < %@", #keyPath(MoodEntry.date), dateTo as NSDate)
|
||||
let fromPredicate = NSPredicate(format: "%@ <= %K", dateFrom as NSDate, #keyPath(MoodEntry.forDate))
|
||||
let toPredicate = NSPredicate(format: "%K < %@", #keyPath(MoodEntry.forDate), dateTo as NSDate)
|
||||
let datePredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [fromPredicate, toPredicate])
|
||||
fetchRequest.predicate = datePredicate
|
||||
let entries = try! self.viewContext.count(for: fetchRequest)
|
||||
|
||||
362
Shared/views/FilterView.swift
Normal file
362
Shared/views/FilterView.swift
Normal file
@@ -0,0 +1,362 @@
|
||||
//
|
||||
// FilterView.swift
|
||||
// Feels
|
||||
//
|
||||
// Created by Trey Tartt on 1/12/22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import CoreData
|
||||
|
||||
class DataHolder: ObservableObject {
|
||||
// year, month, items
|
||||
@Published var data = [Int: [Int: [DayChartView]]]()
|
||||
@Published var numberOfRatings: Int = 0
|
||||
var uncategorizedData = [MoodEntry]() {
|
||||
didSet {
|
||||
self.numberOfRatings = uncategorizedData.count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct FilterView: View {
|
||||
typealias Year = Int
|
||||
typealias Month = Int
|
||||
|
||||
let weekdays = [("Sun", 1), ("mon", 2), ("tue", 3), ("wed", 4), ("thur", 5), ("fri", 6), ("sat", 7)]
|
||||
let months = [(0, "J"), (1, "F"), (2,"M"), (3,"A"), (4,"M"), (5, "J"), (6,"J"), (7,"A"), (8,"S"), (9,"O"), (10, "N"), (11,"D")]
|
||||
|
||||
@State private var toggle = true
|
||||
@State var selectedDays = [Int]()
|
||||
@State private var entryStartDate: Date = Date()
|
||||
@State private var entryEndDate: Date = Date()
|
||||
@State private var showFilter = false
|
||||
|
||||
@FetchRequest(
|
||||
sortDescriptors: [NSSortDescriptor(keyPath: \MoodEntry.forDate, ascending: false)],
|
||||
animation: .spring())
|
||||
private var items: FetchedResults<MoodEntry>
|
||||
|
||||
@StateObject private var dataHolder = DataHolder()
|
||||
//[
|
||||
// 2001: [0: [], 1: [], 2: []],
|
||||
// 2002: [0: [], 1: [], 2: []]
|
||||
// ]
|
||||
let columns = [
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 50)),
|
||||
]
|
||||
|
||||
private func filterEntries(startDate: Date, endDate: Date) {
|
||||
let filteredEntries = PersistenceController.shared.getData(startDate: startDate, endDate: endDate)
|
||||
self.dataHolder.data.removeAll()
|
||||
let filledOutData = buildGridData(withData: filteredEntries)
|
||||
self.dataHolder.data = filledOutData
|
||||
self.dataHolder.uncategorizedData = filteredEntries
|
||||
}
|
||||
|
||||
private func buildGridData(withData data: [MoodEntry]) -> [Year: [Month: [DayChartView]]] {
|
||||
var returnData = [Year: [Month: [DayChartView]]]()
|
||||
|
||||
if let earliestEntry = data.first,
|
||||
let lastEntry = data.last {
|
||||
|
||||
let calendar = Calendar.current
|
||||
let components = calendar.dateComponents([.year], from: earliestEntry.forDate!)
|
||||
let earliestYear = components.year!
|
||||
|
||||
let latestComponents = calendar.dateComponents([.year], from: lastEntry.forDate!)
|
||||
let latestYear = latestComponents.year!
|
||||
|
||||
for year in earliestYear...latestYear {
|
||||
var allMonths = [Int: [DayChartView]]()
|
||||
|
||||
// add back in if months header has leading (-1, ""),
|
||||
// and add back gridItem
|
||||
// var dayViews = [DayChartView]()
|
||||
// for day in 0...32 {
|
||||
// let view = DayChartView(color: Mood.missing.color,
|
||||
// weekDay: 2,
|
||||
// viewType: .text(String(day+1)))
|
||||
// dayViews.append(view)
|
||||
// }
|
||||
// allMonths[0] = dayViews
|
||||
|
||||
for month in (1...12) {
|
||||
var components = DateComponents()
|
||||
components.month = month
|
||||
components.year = year
|
||||
let startDateOfMonth = Calendar.current.date(from: components)!
|
||||
|
||||
let items = data.filter({ entry in
|
||||
let components = calendar.dateComponents([.month, .year], from: startDateOfMonth)
|
||||
let entryComponents = calendar.dateComponents([.month, .year], from: entry.forDate!)
|
||||
return (components.month == entryComponents.month && components.year == entryComponents.year)
|
||||
})
|
||||
|
||||
allMonths[month] = createViewFor(monthEntries: items, forMonth: startDateOfMonth)
|
||||
}
|
||||
returnData[year] = allMonths
|
||||
}
|
||||
}
|
||||
return returnData
|
||||
}
|
||||
|
||||
private func createViewFor(monthEntries: [MoodEntry], forMonth month: Date) -> [DayChartView] {
|
||||
var filledOutArray = [DayChartView]()
|
||||
|
||||
let calendar = Calendar.current
|
||||
let range = calendar.range(of: .day, in: .month, for: month)!
|
||||
let numDays = range.count
|
||||
|
||||
for day in 1...numDays {
|
||||
if let item = monthEntries.filter({ entry in
|
||||
let components = calendar.dateComponents([.day, .weekday], from: entry.forDate!)
|
||||
let date = components.day
|
||||
let weekday = components.weekday!
|
||||
|
||||
if selectedDays.isEmpty {
|
||||
return day == date
|
||||
} else {
|
||||
return day == date && selectedDays.contains(weekday)
|
||||
}
|
||||
}).first {
|
||||
let view = DayChartView(color: item.mood.color,
|
||||
weekDay: Int(item.weekDay),
|
||||
viewType: .cicle)
|
||||
filledOutArray.append(view)
|
||||
} else {
|
||||
let thisDate = Calendar.current.date(bySetting: .day, value: day, of: month)!
|
||||
let view = DayChartView(color: Mood.missing.color,
|
||||
weekDay: Calendar.current.component(.weekday, from: thisDate),
|
||||
viewType: .cicle)
|
||||
filledOutArray.append(view)
|
||||
}
|
||||
}
|
||||
|
||||
for _ in filledOutArray.count...32 {
|
||||
let view = DayChartView(color: Mood.missing.color,
|
||||
weekDay: 2,
|
||||
viewType: .cicle)
|
||||
filledOutArray.append(view)
|
||||
}
|
||||
|
||||
return filledOutArray
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Button(action: {
|
||||
withAnimation{
|
||||
showFilter.toggle()
|
||||
}
|
||||
}, label: {
|
||||
Text("filter")
|
||||
.textCase(.uppercase)
|
||||
})
|
||||
.padding([.leading, .trailing, .top])
|
||||
|
||||
statsView
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 120, maxHeight: 120)
|
||||
.cornerRadius(25)
|
||||
.padding([.leading, .trailing])
|
||||
|
||||
if showFilter {
|
||||
filterView
|
||||
}
|
||||
|
||||
gridView
|
||||
.onAppear(perform: {
|
||||
let monthEntries = PersistenceController.shared.getData(startDate: Date(timeIntervalSince1970: 0), endDate: Date())
|
||||
entryStartDate = monthEntries.first!.forDate!
|
||||
entryEndDate = monthEntries.last!.forDate!
|
||||
self.dataHolder.data = buildGridData(withData: monthEntries)
|
||||
self.dataHolder.uncategorizedData = monthEntries
|
||||
// filterEntries(startDate: entryStartDate, endDate: entryEndDate)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct StatsSubView: View {
|
||||
let data: [MoodEntry]
|
||||
let mood: Mood
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text(String(Stats.getCountFor(moodType: mood,
|
||||
inData: data)))
|
||||
.font(.title)
|
||||
Text(mood.strValue)
|
||||
.foregroundColor(mood.color)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var statsView: some View {
|
||||
ZStack {
|
||||
Color(UIColor.secondarySystemBackground)
|
||||
|
||||
HStack {
|
||||
Spacer()
|
||||
ForEach(Mood.allValues.reversed(), id: \.self) { mood in
|
||||
StatsSubView(data: self.dataHolder.uncategorizedData, mood: mood)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
.cornerRadius(25)
|
||||
.padding()
|
||||
}
|
||||
|
||||
private var filterView: some View {
|
||||
VStack {
|
||||
VStack {
|
||||
ZStack {
|
||||
Color(UIColor.secondarySystemBackground)
|
||||
DatePicker(
|
||||
"Start Date",
|
||||
selection: $entryStartDate,
|
||||
displayedComponents: [.date]
|
||||
).onChange(of: entryStartDate, perform: { value in
|
||||
filterEntries(startDate: self.entryStartDate, endDate: self.entryEndDate)
|
||||
})
|
||||
.padding()
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 44, maxHeight: 44)
|
||||
.cornerRadius(25)
|
||||
.padding([.leading, .trailing])
|
||||
|
||||
ZStack {
|
||||
Color(UIColor.secondarySystemBackground)
|
||||
DatePicker(
|
||||
"End Date",
|
||||
selection: $entryEndDate,
|
||||
displayedComponents: [.date]
|
||||
).onChange(of: entryStartDate, perform: { value in
|
||||
filterEntries(startDate: self.entryStartDate, endDate: self.entryEndDate)
|
||||
})
|
||||
.padding()
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 44, maxHeight: 44)
|
||||
.cornerRadius(25)
|
||||
.padding([.leading, .trailing])
|
||||
|
||||
ZStack {
|
||||
Color(UIColor.secondarySystemBackground)
|
||||
HStack {
|
||||
Spacer()
|
||||
ForEach(weekdays.indices, id: \.self) { dayIdx in
|
||||
let day = String(weekdays[dayIdx].0)
|
||||
let value = weekdays[dayIdx].1
|
||||
|
||||
Button(day.capitalized, action: {
|
||||
if let index = selectedDays.firstIndex(of: value) {
|
||||
selectedDays.remove(at: index)
|
||||
} else {
|
||||
selectedDays.append(value)
|
||||
}
|
||||
filterEntries(startDate: entryStartDate, endDate: entryEndDate)
|
||||
})
|
||||
.frame(maxWidth: .infinity)
|
||||
.foregroundColor(selectedDays.contains(value) || selectedDays.isEmpty ? .green : .red)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 44, maxHeight: 44)
|
||||
.cornerRadius(25)
|
||||
.padding([ .leading, .trailing])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var monthsHeader: some View {
|
||||
LazyVGrid(columns: columns, spacing: 0) {
|
||||
ForEach(months, id: \.self.0) { item in
|
||||
Text(item.1)
|
||||
.textCase(.uppercase)
|
||||
}
|
||||
}.padding([.leading, .trailing, .top])
|
||||
}
|
||||
|
||||
private var gridView: some View {
|
||||
VStack {
|
||||
Text("Total: \(self.dataHolder.numberOfRatings)")
|
||||
.font(.title2)
|
||||
|
||||
monthsHeader
|
||||
.cornerRadius(25)
|
||||
.padding([.leading, .trailing])
|
||||
|
||||
VStack {
|
||||
ScrollView {
|
||||
ForEach(Array(self.dataHolder.data.keys.sorted(by: >)), id: \.self) { yearKey in
|
||||
let yearData = self.dataHolder.data[yearKey]!
|
||||
Text(String(yearKey))
|
||||
.font(.title)
|
||||
yearGridView(yearData: yearData, columns: columns)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct yearGridView: View {
|
||||
let yearData: [Int: [DayChartView]]
|
||||
let columns: [GridItem]
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color(UIColor.secondarySystemBackground)
|
||||
|
||||
VStack {
|
||||
LazyVGrid(columns: columns, spacing: 0) {
|
||||
ForEach(Array(yearData.keys.sorted(by: <)), id: \.self) { monthKey in
|
||||
let monthData = yearData[monthKey]!
|
||||
VStack {
|
||||
monthGridView(monthData: monthData)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding([.leading, .trailing, .top, .bottom])
|
||||
}
|
||||
}
|
||||
.cornerRadius(25)
|
||||
}
|
||||
}
|
||||
|
||||
private struct monthGridView: View {
|
||||
let monthData: [DayChartView]
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
ForEach(monthData, id: \.self) { view in
|
||||
view
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct FilterView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Group {
|
||||
FilterView()
|
||||
|
||||
FilterView()
|
||||
.preferredColorScheme(.dark)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,137 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import CoreData
|
||||
import Charts
|
||||
|
||||
struct GraphView: View {
|
||||
var body: some View {
|
||||
Text("this is a graph")
|
||||
ZStack {
|
||||
Color(UIColor.secondarySystemBackground)
|
||||
VStack {
|
||||
VStack {
|
||||
HStack {
|
||||
ZStack {
|
||||
Color(UIColor.systemBackground)
|
||||
BarChartGraph(entries: [
|
||||
BarChartDataEntry(x: 1, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 2, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 3, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 4, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 5, y: Double(Int.random(in: 0...10)))
|
||||
])
|
||||
}
|
||||
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
||||
.padding()
|
||||
|
||||
ZStack {
|
||||
Color(UIColor.systemBackground)
|
||||
BarChartGraph(entries: [
|
||||
BarChartDataEntry(x: 1, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 2, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 3, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 4, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 5, y: Double(Int.random(in: 0...10)))
|
||||
])
|
||||
}
|
||||
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
||||
.padding()
|
||||
}
|
||||
|
||||
ZStack {
|
||||
Color(UIColor.systemBackground)
|
||||
BarChartGraph(entries: [
|
||||
BarChartDataEntry(x: 1, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 2, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 3, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 4, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 5, y: Double(Int.random(in: 0...10)))
|
||||
])
|
||||
}.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
||||
.padding()
|
||||
|
||||
ZStack {
|
||||
Color(UIColor.systemBackground)
|
||||
BarChartGraph(entries: [
|
||||
BarChartDataEntry(x: 1, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 2, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 3, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 4, y: Double(Int.random(in: 0...10))),
|
||||
BarChartDataEntry(x: 5, y: Double(Int.random(in: 0...10)))
|
||||
])
|
||||
}.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct BarChartGraph: UIViewRepresentable {
|
||||
//Bar chart accepts data as array of BarChartDataEntry objects
|
||||
var entries : [BarChartDataEntry]
|
||||
|
||||
// this func is required to conform to UIViewRepresentable protocol
|
||||
func makeUIView(context: Context) -> BarChartView {
|
||||
//crate new chart
|
||||
let chart = BarChartView()
|
||||
chart.drawGridBackgroundEnabled = false
|
||||
chart.drawValueAboveBarEnabled = false
|
||||
|
||||
chart.xAxis.drawAxisLineEnabled = false
|
||||
chart.xAxis.labelTextColor = .clear
|
||||
|
||||
chart.rightAxis.drawAxisLineEnabled = false
|
||||
chart.rightAxis.labelTextColor = .clear
|
||||
|
||||
chart.leftAxis.drawAxisLineEnabled = false
|
||||
chart.leftAxis.labelTextColor = .clear
|
||||
|
||||
chart.xAxis.drawGridLinesEnabled = false
|
||||
chart.leftAxis.drawGridLinesEnabled = false
|
||||
chart.leftAxis.axisLineColor = .clear
|
||||
chart.rightAxis.axisLineColor = .clear
|
||||
|
||||
chart.legend.textColor = .clear
|
||||
chart.legend.enabled = false
|
||||
|
||||
chart.drawBordersEnabled = false
|
||||
chart.drawMarkers = false
|
||||
// chart.yAxis.drawGridLinesEnabled = false
|
||||
chart.rightAxis.drawGridLinesEnabled = false
|
||||
chart.borderColor = .clear
|
||||
//it is convenient to form chart data in a separate func
|
||||
chart.data = addData()
|
||||
return chart
|
||||
}
|
||||
|
||||
// this func is required to conform to UIViewRepresentable protocol
|
||||
func updateUIView(_ uiView: BarChartView, context: Context) {
|
||||
//when data changes chartd.data update is required
|
||||
uiView.data = addData()
|
||||
}
|
||||
|
||||
func addData() -> BarChartData{
|
||||
let data = BarChartData()
|
||||
//BarChartDataSet is an object that contains information about your data, styling and more
|
||||
let dataSet = BarChartDataSet(entries: entries)
|
||||
// change bars color to green
|
||||
dataSet.colors = [NSUIColor.green]
|
||||
//change data label
|
||||
data.append(dataSet)
|
||||
return data
|
||||
}
|
||||
|
||||
typealias UIViewType = BarChartView
|
||||
}
|
||||
|
||||
|
||||
struct GraphView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Group {
|
||||
GraphView()
|
||||
|
||||
GraphView()
|
||||
.preferredColorScheme(.dark)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ struct HeaderStatsView : UIViewRepresentable {
|
||||
// change bars color to green
|
||||
dataSet.colors = [NSUIColor.green]
|
||||
//change data label
|
||||
data.addDataSet(dataSet)
|
||||
data.append(dataSet)
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -10,47 +10,32 @@ import SwiftUI
|
||||
struct SettingsView: View {
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
@State private var currentDate = Date() {
|
||||
@AppStorage("notificationDate") private var notificationDate = Date() {
|
||||
didSet {
|
||||
if self.showReminder {
|
||||
LocalNotification.scheduleReminder(atTime: self.currentDate)
|
||||
LocalNotification.scheduleReminder(atTime: self.notificationDate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@State private var showReminder: Bool = false {
|
||||
didSet {
|
||||
if self.showReminder {
|
||||
LocalNotification.testIfEnabled(completion: { result in
|
||||
switch result{
|
||||
case .success(_):
|
||||
LocalNotification.scheduleReminder(atTime: self.currentDate)
|
||||
case .failure(_):
|
||||
// show error
|
||||
break
|
||||
}
|
||||
})
|
||||
} else {
|
||||
LocalNotification.removeNotificaiton()
|
||||
}
|
||||
}
|
||||
}
|
||||
@AppStorage("showReminder") private var showReminder: Bool = false
|
||||
|
||||
var body: some View { ZStack {
|
||||
Color(UIColor.secondarySystemBackground)
|
||||
|
||||
VStack {
|
||||
closeButtonView
|
||||
.padding()
|
||||
notificationCell
|
||||
randomShitCell
|
||||
addTestDataCell
|
||||
clearDB
|
||||
whyBackgroundMode
|
||||
Spacer()
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color(UIColor.secondarySystemBackground)
|
||||
|
||||
VStack {
|
||||
closeButtonView
|
||||
.padding()
|
||||
notificationCell
|
||||
randomShitCell
|
||||
addTestDataCell
|
||||
clearDB
|
||||
whyBackgroundMode
|
||||
Spacer()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
private var closeButtonView: some View {
|
||||
@@ -71,8 +56,14 @@ struct SettingsView: View {
|
||||
Color(UIColor.systemBackground)
|
||||
VStack {
|
||||
Toggle("Would you like to be reminded?", isOn: $showReminder)
|
||||
.onChange(of: showReminder, perform: { value in
|
||||
self.maybeNotificaiotns(areEnabled: value)
|
||||
})
|
||||
.padding()
|
||||
DatePicker("", selection: $currentDate, displayedComponents: .hourAndMinute)
|
||||
DatePicker("", selection: $notificationDate, displayedComponents: .hourAndMinute)
|
||||
.onChange(of: notificationDate, perform: { value in
|
||||
self.updateNotificationTimes(toDate: value)
|
||||
})
|
||||
.disabled(showReminder == false)
|
||||
.padding()
|
||||
}
|
||||
@@ -85,7 +76,11 @@ struct SettingsView: View {
|
||||
ZStack {
|
||||
Color(UIColor.systemBackground)
|
||||
VStack {
|
||||
Text("random shit")
|
||||
Button(action: {
|
||||
|
||||
}, label: {
|
||||
Text("Special thanks to")
|
||||
})
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
@@ -130,6 +125,29 @@ struct SettingsView: View {
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
||||
}
|
||||
|
||||
private func updateNotificationTimes(toDate date: Date) {
|
||||
LocalNotification.removeNotificaiton()
|
||||
|
||||
LocalNotification.scheduleReminder(atTime: date)
|
||||
}
|
||||
|
||||
private func maybeNotificaiotns(areEnabled: Bool) {
|
||||
if areEnabled {
|
||||
LocalNotification.testIfEnabled(completion: { result in
|
||||
switch result{
|
||||
case .success(_):
|
||||
LocalNotification.scheduleReminder(atTime: self.notificationDate)
|
||||
case .failure(let error):
|
||||
print(error)
|
||||
// show error
|
||||
break
|
||||
}
|
||||
})
|
||||
} else {
|
||||
LocalNotification.removeNotificaiton()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SettingsView_Previews: PreviewProvider {
|
||||
|
||||
Reference in New Issue
Block a user