wip
This commit is contained in:
@@ -40,6 +40,6 @@ struct EmptyHomeView: View {
|
||||
|
||||
struct EmptyHomeView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
EmptyHomeView(viewModel: ContentModeViewModel())
|
||||
EmptyHomeView(viewModel: ContentModeViewModel(addMonthStartWeekdayPadding: false))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ struct HomeViewConstants {
|
||||
struct HomeView: View {
|
||||
@Environment(\.managedObjectContext) private var viewContext
|
||||
|
||||
@AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true
|
||||
|
||||
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
|
||||
|
||||
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
||||
@@ -46,7 +44,7 @@ struct HomeView: View {
|
||||
@State private var headerOpacity: Double = 1.0
|
||||
//
|
||||
|
||||
@ObservedObject var viewModel = ContentModeViewModel()
|
||||
@ObservedObject var viewModel = ContentModeViewModel(addMonthStartWeekdayPadding: false)
|
||||
|
||||
init(){
|
||||
UIPageControl.appearance().currentPageIndicatorTintColor = UIColor.label
|
||||
@@ -56,7 +54,7 @@ struct HomeView: View {
|
||||
|
||||
var body: some View {
|
||||
mainView
|
||||
.alert(updateTitleHeader(forEntry: selectedEntry),
|
||||
.alert(ContentModeViewModel.updateTitleHeader(forEntry: selectedEntry),
|
||||
isPresented: $showUpdateEntryAlert) {
|
||||
ForEach(Mood.allValues) { mood in
|
||||
Button(mood.strValue, action: {
|
||||
@@ -112,30 +110,7 @@ struct HomeView: View {
|
||||
// SCROLLING DOWN
|
||||
headerHeight = newValue
|
||||
}
|
||||
|
||||
private func updateTitleHeader(forEntry entry: MoodEntry?) -> String {
|
||||
guard let entry = entry else {
|
||||
return ""
|
||||
}
|
||||
|
||||
guard let forDate = entry.forDate else {
|
||||
return ""
|
||||
}
|
||||
|
||||
let components = Calendar.current.dateComponents([.day, .month, .year], from: forDate)
|
||||
// let day = components.day!
|
||||
let month = components.month!
|
||||
let year = components.year!
|
||||
|
||||
let monthName = Random.monthName(fromMonthInt: month)
|
||||
let weekday = Random.weekdayName(fromDate:entry.forDate!)
|
||||
let dayz = Random.dayFormat(fromDate:entry.forDate!)
|
||||
|
||||
let string = weekday + " " + monthName + " " + dayz + " " + String(year)
|
||||
|
||||
return String(format: String(localized: "content_view_fill_in_missing_entry"), string)
|
||||
}
|
||||
|
||||
// MARK: Views
|
||||
public var mainView: some View {
|
||||
VStack {
|
||||
@@ -153,8 +128,7 @@ struct HomeView: View {
|
||||
.opacity(headerOpacity)
|
||||
|
||||
VStack {
|
||||
SmallRollUpHeaderView(fakeData: false,
|
||||
backDays: $currentSelectedHeaderViewBackDays,
|
||||
SmallRollUpHeaderView(entries: getBackEntries(),
|
||||
viewType: $currentSelectedHeaderViewViewType)
|
||||
.background(
|
||||
Color(theme.currentTheme.secondaryBGColor)
|
||||
@@ -200,7 +174,7 @@ struct HomeView: View {
|
||||
viewModel.updateData()
|
||||
}
|
||||
}, updateBoardingDataClosure: { onboardingData in
|
||||
viewModel.updateOnboardingData(onboardingData: onboardingData)
|
||||
OnboardingDataDataManager.shared.updateOnboardingData(onboardingData: onboardingData)
|
||||
})
|
||||
}.padding(.trailing)
|
||||
}
|
||||
@@ -293,6 +267,13 @@ struct HomeView: View {
|
||||
}
|
||||
.cornerRadius(10, corners: [.topLeft, .topRight])
|
||||
}
|
||||
|
||||
func getBackEntries() -> [MoodEntry] {
|
||||
var daysAgo = Calendar.current.date(byAdding: .day, value: -self.currentSelectedHeaderViewBackDays, to: Date())!
|
||||
daysAgo = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: daysAgo)!
|
||||
|
||||
return PersistenceController.shared.getData(startDate: daysAgo, endDate: Date(), includedDays: [1,2,3,4,5,6,7])
|
||||
}
|
||||
}
|
||||
|
||||
// view that make up the list body
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
//
|
||||
// HomeViewTwo.swift
|
||||
// Feels (iOS)
|
||||
//
|
||||
// Created by Trey Tartt on 2/18/22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct HomeViewTwo: View {
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
}
|
||||
|
||||
struct HomeViewTwo_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HomeViewTwo()
|
||||
}
|
||||
}
|
||||
110
Shared/views/HomeViewTwo/HomeViewTwo.swift
Normal file
110
Shared/views/HomeViewTwo/HomeViewTwo.swift
Normal file
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// HomeViewTwo.swift
|
||||
// Feels (iOS)
|
||||
//
|
||||
// Created by Trey Tartt on 2/18/22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct HomeViewTwo: View {
|
||||
@AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true
|
||||
|
||||
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
||||
|
||||
@ObservedObject var viewModel = ContentModeViewModel(addMonthStartWeekdayPadding: true)
|
||||
|
||||
@StateObject private var selectedDetail = StupidAssDetailViewObservableObject()
|
||||
|
||||
class StupidAssDetailViewObservableObject: ObservableObject {
|
||||
@Published var fuckingWrapped: MonthDetailView? = nil
|
||||
@Published var showFuckingSheet = false
|
||||
}
|
||||
|
||||
let columns = [
|
||||
GridItem(.flexible(minimum: 5, maximum: 400)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 400)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 400)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 400)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 400)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 400)),
|
||||
GridItem(.flexible(minimum: 5, maximum: 400))
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
topView
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.frame(height: 200)
|
||||
.background(
|
||||
.blue
|
||||
)
|
||||
LazyVStack(spacing: 5, pinnedViews: [.sectionHeaders]) {
|
||||
ForEach(viewModel.grouped.sorted(by: { $0.key > $1.key }), id: \.key) { year, months in
|
||||
|
||||
// for reach month
|
||||
ForEach(months.sorted(by: { $0.key > $1.key }), id: \.key) { month, entries in
|
||||
Section(header: homeViewTwoSectionHeaderView(month: month, year: year)) {
|
||||
homeViewTwoMonthListView(month: month, year: year, entries: entries)
|
||||
}
|
||||
.onTapGesture{
|
||||
let deailView = MonthDetailView(monthInt: month,
|
||||
yearInt: year,
|
||||
entries: entries)
|
||||
|
||||
selectedDetail.fuckingWrapped = deailView
|
||||
selectedDetail.showFuckingSheet = true
|
||||
}
|
||||
}
|
||||
.padding(.bottom)
|
||||
}
|
||||
}
|
||||
.padding([.leading, .trailing])
|
||||
}.sheet(isPresented: $selectedDetail.showFuckingSheet,
|
||||
onDismiss: didDismiss) {
|
||||
selectedDetail.fuckingWrapped
|
||||
}
|
||||
}
|
||||
|
||||
func didDismiss() {
|
||||
selectedDetail.showFuckingSheet = false
|
||||
selectedDetail.fuckingWrapped = nil
|
||||
}
|
||||
}
|
||||
|
||||
extension HomeViewTwo {
|
||||
private var topView: some View {
|
||||
HStack {
|
||||
Text("dis top")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// view that make up the list body
|
||||
extension HomeViewTwo {
|
||||
private func homeViewTwoSectionHeaderView(month: Int, year: Int) -> some View {
|
||||
Text("\(Random.monthName(fromMonthInt: month)) \(String(year))")
|
||||
.font(.body)
|
||||
.foregroundColor(Color(UIColor.label))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(
|
||||
Color(theme.currentTheme.secondaryBGColor)
|
||||
)
|
||||
}
|
||||
|
||||
private func homeViewTwoMonthListView(month: Int, year: Int, entries: [MoodEntry]) -> some View {
|
||||
LazyVGrid(columns: columns, spacing: 15) {
|
||||
ForEach(entries, id: \.self) { entry in
|
||||
Circle()
|
||||
.foregroundColor(entry.mood.color)
|
||||
.frame(minHeight: 5, idealHeight: 20, maxHeight: 50, alignment: .center)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct HomeViewTwo_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HomeViewTwo()
|
||||
}
|
||||
}
|
||||
122
Shared/views/HomeViewTwo/MonthDetailView.swift
Normal file
122
Shared/views/HomeViewTwo/MonthDetailView.swift
Normal file
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// MonthDetailView.swift
|
||||
// Feels (iOS)
|
||||
//
|
||||
// Created by Trey Tartt on 2/18/22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MonthDetailView: View {
|
||||
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
||||
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
|
||||
|
||||
@State private var showingUpdateEntryAlert = false
|
||||
|
||||
let monthInt: Int
|
||||
let yearInt: Int
|
||||
let entries: [MoodEntry]
|
||||
|
||||
lazy var dateFormatter: DateFormatter = {
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "dd"
|
||||
return dateFormatter
|
||||
}()
|
||||
|
||||
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))
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text("\(Random.monthName(fromMonthInt: monthInt)) \(String(yearInt))")
|
||||
.font(.title)
|
||||
.foregroundColor(Color(UIColor.label))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding()
|
||||
.background(
|
||||
Color(theme.currentTheme.secondaryBGColor)
|
||||
)
|
||||
|
||||
ScrollView {
|
||||
LazyVGrid(columns: columns, spacing: 25) {
|
||||
ForEach(entries, id: \.self) { entry in
|
||||
VStack {
|
||||
if entry.mood != .placeholder {
|
||||
Text(entry.forDate!,
|
||||
format: Date.FormatStyle().day())
|
||||
.font(.title3)
|
||||
.foregroundColor(Color(UIColor.label))
|
||||
|
||||
entry.mood.icon
|
||||
.resizable()
|
||||
.frame(minWidth: 5,
|
||||
maxWidth: 50,
|
||||
minHeight: 5,
|
||||
maxHeight: 50,
|
||||
alignment: .center)
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.foregroundColor(entry.mood.color)
|
||||
}
|
||||
}
|
||||
.alert(ContentModeViewModel.updateTitleHeader(forEntry: entry),
|
||||
isPresented: $showingUpdateEntryAlert) {
|
||||
ForEach(Mood.allValues) { mood in
|
||||
Button(mood.strValue, action: {
|
||||
PersistenceController.shared.update(entryDate: entry.forDate!, withModd: mood)
|
||||
// viewModel.update(entry: selectedEntry, toMood: mood)
|
||||
})
|
||||
}
|
||||
|
||||
if deleteEnabled,
|
||||
entry.mood != .missing {
|
||||
Button(String(localized: "content_view_delete_entry"), action: {
|
||||
PersistenceController.shared.update(entryDate: entry.forDate!, withModd: Mood.missing)
|
||||
// viewModel.update(entry: selectedEntry, toMood: Mood.missing)
|
||||
})
|
||||
}
|
||||
|
||||
Button(String(localized: "content_view_fill_in_missing_entry_cancel"), role: .cancel, action: {
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding([.leading, .trailing])
|
||||
|
||||
monthDetails
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(
|
||||
Color(theme.currentTheme.secondaryBGColor)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private var monthDetails: some View {
|
||||
VStack {
|
||||
SmallRollUpHeaderView(entries: entries,
|
||||
viewType: .constant(.total))
|
||||
|
||||
SmallRollUpHeaderView(entries: entries,
|
||||
viewType: .constant(.percentageCircle))
|
||||
.padding(.top, -20)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
struct MonthDetailView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MonthDetailView(monthInt: 5, yearInt: 2022, entries:
|
||||
PersistenceController.shared.randomEntries(count: 30).sorted(by: {
|
||||
$0.forDate! < $1.forDate!
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,16 @@ import SwiftUI
|
||||
|
||||
struct MainTabView: View {
|
||||
@AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true
|
||||
@ObservedObject var viewModel = ContentModeViewModel()
|
||||
|
||||
let onboardingData = OnboardingDataDataManager.shared.savedOnboardingData
|
||||
|
||||
var body: some View {
|
||||
TabView {
|
||||
HomeViewTwo()
|
||||
.tabItem {
|
||||
Label(String(localized: "content_view_tab_main"), systemImage: "list.dash")
|
||||
}
|
||||
|
||||
HomeView()
|
||||
.tabItem {
|
||||
Label(String(localized: "content_view_tab_main"), systemImage: "list.dash")
|
||||
@@ -30,10 +36,10 @@ struct MainTabView: View {
|
||||
}.sheet(isPresented: $needsOnboarding, onDismiss: {
|
||||
|
||||
}, content: {
|
||||
OnboardingMain(onboardingData: viewModel.savedOnboardingData,
|
||||
OnboardingMain(onboardingData: onboardingData,
|
||||
updateBoardingDataClosure: { onboardingData in
|
||||
needsOnboarding = false
|
||||
viewModel.updateOnboardingData(onboardingData: onboardingData)
|
||||
OnboardingDataDataManager.shared.updateOnboardingData(onboardingData: onboardingData)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,47 +9,18 @@ import SwiftUI
|
||||
|
||||
struct SmallRollUpHeaderView: View {
|
||||
@Binding var viewType: MainSwitchableViewType
|
||||
@Binding var backDays: Int
|
||||
|
||||
typealias Model = (mood: Mood, total: Int, percent: Float)
|
||||
private var entries = [Model]()
|
||||
let entries: [MoodEntry]
|
||||
private var moodMetrics = [MoodGroupingMetrics]()
|
||||
|
||||
init(fakeData: Bool, backDays: Binding<Int>, viewType: Binding<MainSwitchableViewType>) {
|
||||
init(entries: [MoodEntry], viewType: Binding<MainSwitchableViewType>) {
|
||||
self.entries = entries
|
||||
self._viewType = viewType
|
||||
|
||||
self._backDays = backDays
|
||||
|
||||
var moodEntries: [MoodEntry]?
|
||||
|
||||
if fakeData {
|
||||
moodEntries = PersistenceController.shared.randomEntries(count: 10)
|
||||
} else {
|
||||
var daysAgo = Calendar.current.date(byAdding: .day, value: -self.backDays, to: Date())!
|
||||
daysAgo = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: daysAgo)!
|
||||
|
||||
moodEntries = PersistenceController.shared.getData(startDate: daysAgo, endDate: Date(), includedDays: [1,2,3,4,5,6,7])
|
||||
}
|
||||
|
||||
let totalEntryCount = moodEntries?.count ?? 0
|
||||
|
||||
if let moodEntries = moodEntries {
|
||||
for (_, mood) in Mood.allValues.enumerated() {
|
||||
|
||||
let moodEntries = moodEntries.filter({
|
||||
Int($0.moodValue) == mood.rawValue
|
||||
})
|
||||
let total = moodEntries.count
|
||||
let perc = (Float(total) / Float(totalEntryCount)) * 100
|
||||
entries.append((mood, total, perc))
|
||||
}
|
||||
}
|
||||
|
||||
entries = entries.sorted(by: {
|
||||
$0.0.rawValue > $1.0.rawValue
|
||||
})
|
||||
moodMetrics = Random.createTotalPerc(fromEntries: entries)
|
||||
}
|
||||
|
||||
private func textView(forModel model: Model) -> Text {
|
||||
private func textView(forModel model: MoodGroupingMetrics) -> Text {
|
||||
switch viewType {
|
||||
case .total:
|
||||
return Text(String(model.total))
|
||||
@@ -60,12 +31,43 @@ struct SmallRollUpHeaderView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var modelTextViews: some View {
|
||||
private var textViews: some View {
|
||||
HStack {
|
||||
ForEach(entries, id: \.0) { model in
|
||||
ForEach(moodMetrics, id: \.0) { model in
|
||||
textView(forModel: model)
|
||||
.font(.title2)
|
||||
.fontWeight(.bold)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(model.mood.color)
|
||||
.frame(width: 70, height: 70)
|
||||
}
|
||||
}
|
||||
.padding([.top, .bottom])
|
||||
}
|
||||
|
||||
private var circularViews: some View {
|
||||
HStack {
|
||||
ForEach(moodMetrics, id: \.0) { model in
|
||||
ZStack {
|
||||
Circle().fill(model.mood.color)
|
||||
.frame(minWidth: 5,
|
||||
maxWidth: 70,
|
||||
minHeight: 5,
|
||||
maxHeight: 70,
|
||||
alignment: .center)
|
||||
.overlay(
|
||||
textView(forModel: model)
|
||||
.font(.title3)
|
||||
.fontWeight(.bold)
|
||||
.lineLimit(1)
|
||||
.clipShape(ContainerRelativeShape()).padding()
|
||||
.foregroundColor(Color(UIColor.white))
|
||||
.minimumScaleFactor(0.1)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding([.top, .bottom])
|
||||
}
|
||||
|
||||
private var viewOnViewtype : some View {
|
||||
@@ -79,51 +81,21 @@ struct SmallRollUpHeaderView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var textViews: some View {
|
||||
HStack {
|
||||
ForEach(entries, id: \.0) { model in
|
||||
textView(forModel: model)
|
||||
.font(.title2)
|
||||
.fontWeight(.bold)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(model.mood.color)
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
}
|
||||
.padding([.top, .bottom])
|
||||
}
|
||||
|
||||
private var circularViews: some View {
|
||||
HStack {
|
||||
ForEach(entries, id: \.0) { model in
|
||||
ZStack {
|
||||
Circle().fill(model.mood.color)
|
||||
.frame(width: 50, height: 50)
|
||||
|
||||
textView(forModel: model)
|
||||
.font(.title3)
|
||||
.fontWeight(.bold)
|
||||
.frame(width: 40, height: 40)
|
||||
.scaledToFill()
|
||||
.minimumScaleFactor(0.5)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(Color(UIColor.white))
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding([.top, .bottom])
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
viewOnViewtype
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
struct SmallHeaderView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SmallRollUpHeaderView(fakeData: true, backDays: .constant(30), viewType: .constant(.total))
|
||||
|
||||
SmallRollUpHeaderView(fakeData: true, backDays: .constant(7), viewType: .constant(.total))
|
||||
Group {
|
||||
SmallRollUpHeaderView(entries: PersistenceController.shared.randomEntries(count: 10),
|
||||
viewType: .constant(.total))
|
||||
|
||||
SmallRollUpHeaderView(entries: PersistenceController.shared.randomEntries(count: 10),
|
||||
viewType: .constant(.total))
|
||||
.frame(height: 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user