rerewrote daysUntillEvent, now acc can count days

inlineLarge titlebar, backwards compatible view extension
competed events go to archive
fix long event name and notes alignemnts
can refresh icloud settings to sync
This commit is contained in:
neon443
2025-05-04 12:31:01 +01:00
parent c97d37711c
commit ffbd17fad8
9 changed files with 191 additions and 150 deletions

View File

@@ -12,6 +12,6 @@ TEAM_ID = 8JGND254B7
BUNDLE_ID = com.neon443.NearFuture
BUNDLE_ID_WIDGETS = com.neon443.NearFuture.widgets
GROUP_ID = group.NearFuture
VERSION = 3.1.1
VERSION = 3.2.1
NAME = Near Future
BUILD_NUMBER = 5

View File

@@ -94,8 +94,10 @@ struct AddEventView: View {
// date picker
HStack {
Spacer()
DatePicker("", selection: $eventDate, displayedComponents: .date)
.datePickerStyle(WheelDatePickerStyle())
Spacer()
Button() {
eventDate = Date()
} label: {

View File

@@ -36,6 +36,14 @@ struct ArchiveView: View {
AddEventButton(showingAddEventView: $showAddEvent)
}
}
.navigationTitle("Archive")
.apply {
if #available(iOS 17, *) {
$0.toolbarTitleDisplayMode(.inlineLarge)
} else {
$0.navigationBarTitleDisplayMode(.inline)
}
}
}
.sheet(isPresented: $showAddEvent) {
AddEventView(

View File

@@ -34,7 +34,7 @@ struct ContentView: View {
@State private var searchInput: String = ""
var filteredEvents: [Event] {
if searchInput.isEmpty {
return viewModel.events
return viewModel.events.filter() {!$0.complete}
} else {
return viewModel.events.filter {
$0.name.localizedCaseInsensitiveContains(searchInput) ||
@@ -86,14 +86,23 @@ struct ContentView: View {
}
.padding(.horizontal)
if /*!searchInput.isEmpty && */filteredEvents.isEmpty {
HelpView(searchInput: $searchInput, focusedField: focusedField)
HelpView(
searchInput: $searchInput,
focusedField: focusedField
)
}
Spacer()
}
}
}
.navigationTitle("Near Future")
.navigationBarTitleDisplayMode(.inline)
.apply {
if #available(iOS 17, *) {
$0.toolbarTitleDisplayMode(.inlineLarge)
} else {
$0.navigationBarTitleDisplayMode(.inline)
}
}
.sheet(isPresented: $showingAddEventView) {
AddEventView(
viewModel: viewModel,
@@ -193,3 +202,7 @@ extension View {
.ignoresSafeArea(.all)
}
}
extension View {
func apply<V: View>(@ViewBuilder _ block: (Self) -> V) -> V { block(self) }
}

View File

@@ -44,11 +44,13 @@ struct EventListView: View {
.font(.headline)
.foregroundStyle(.one)
.strikethrough(event.complete)
.multilineTextAlignment(.leading)
}
if !event.notes.isEmpty {
Text(event.notes)
.font(.subheadline)
.foregroundStyle(.one.opacity(0.8))
.multilineTextAlignment(.leading)
}
Text(
event.date.formatted(

View File

@@ -76,30 +76,24 @@ struct ColorCodable: Codable, Equatable {
func daysUntilEvent(_ eventDate: Date) -> (long: String, short: String) {
let calendar = Calendar.current
let now = Date()
let isToday = calendar.isDate(now, inSameDayAs: eventDate)
let components = calendar.dateComponents([.second, .day], from: now, to: eventDate)
guard !isToday else { return ("Today", "Today") }
let secsComponents = eventDate.timeIntervalSinceNow
guard let daysCompontents = components.day else { return ("N/A", "N/A") }
let secs = Double(secsComponents)
var days = 0
var long = ""
var short = ""
if secs < 0 {
let startOfDayNow = calendar.startOfDay(for: Date())
let startOfDayEvent = calendar.startOfDay(for: eventDate)
let components = calendar.dateComponents([.day], from: startOfDayNow, to: startOfDayEvent)
guard let days = components.day else { return ("N/A", "N/A") }
guard days != 0 else { return ("Today", "Today") }
if days < 0 {
//past
days = Int(floor(secs/86400))
long = "\(-days) day\(plu(days)) ago"
short = "\(days)d"
return (
"\(-days) day\(plu(days)) ago",
"\(days)d"
)
} else {
//future
days = Int(ceil(secs/86400))
long = "\(days) day\(plu(days))"
short = "\(days)d"
return (
"\(days) day\(plu(days))",
"\(days)d"
)
}
return (long, short)
}
class EventViewModel: ObservableObject {

View File

@@ -108,7 +108,13 @@ struct SettingsView: View {
}
.scrollContentBackground(.hidden)
.navigationTitle("Settings")
.navigationBarTitleDisplayMode(.inline)
.apply {
if #available(iOS 17, *) {
$0.toolbarTitleDisplayMode(.inlineLarge)
} else {
$0.navigationBarTitleDisplayMode(.inline)
}
}
}
}
}

View File

@@ -58,7 +58,13 @@ struct StatsView: View {
}
.scrollContentBackground(.hidden)
.navigationTitle("Statistics")
.navigationBarTitleDisplayMode(.inline)
.apply {
if #available(iOS 17, *) {
$0.toolbarTitleDisplayMode(.inlineLarge)
} else {
$0.navigationBarTitleDisplayMode(.inline)
}
}
}
}
}

View File

@@ -37,6 +37,7 @@ struct iCloudSettingsView: View {
ZStack {
backgroundGradient
List {
Section {
HStack {
Spacer()
VStack {
@@ -152,7 +153,7 @@ struct iCloudSettingsView: View {
.foregroundStyle(lastSyncWasNormalAgo ? .green : .red)
Text("Last Sync")
Spacer()
Text("\(viewModel.lastSync?.formatted() ?? "Never")")
Text("\(viewModel.lastSync?.formatted(date: .long, time: .standard) ?? "Never")")
.bold()
}
@@ -175,6 +176,15 @@ struct iCloudSettingsView: View {
Text("\(viewModel.icloudEventCount)")
.bold()
}
} header: {
Text("Sync Status")
} footer: {
Text("Pull to sync\nOr use the arrows to force push/pull")
}
}
.refreshable {
viewModel.sync()
updateStatus()
}
.scrollContentBackground(.hidden)
.navigationTitle("iCloud")