mirror of
https://github.com/neon443/NearFuture.git
synced 2026-03-11 14:56:15 +00:00
forgot to commit 2.0, but just finished 3.0
3.0: home screen widgets small,med,large they auto refresh! major bug fixes inclluding past date handling past dates are now allowed 2.0: icloud sync ios required is 15, down from 18! auto icloud sync added icloud settings to manually push,pull or sync
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"platform" : "ios",
|
||||
"size" : "1024x1024"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
6
NearFutureWidgets/Assets.xcassets/Contents.json
Normal file
6
NearFutureWidgets/Assets.xcassets/Contents.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "extended-srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.135",
|
||||
"green" : "0.135",
|
||||
"red" : "0.135"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
11
NearFutureWidgets/Info.plist
Normal file
11
NearFutureWidgets/Info.plist
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.widgetkit-extension</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
208
NearFutureWidgets/NearFutureWidgets.swift
Normal file
208
NearFutureWidgets/NearFutureWidgets.swift
Normal file
@@ -0,0 +1,208 @@
|
||||
//
|
||||
// NearFutureWidgets.swift
|
||||
// NearFutureWidgets
|
||||
//
|
||||
// Created by Nihaal Sharma on 02/01/2025.
|
||||
//
|
||||
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
// Timeline Entry for Widget
|
||||
struct EventWidgetEntry: TimelineEntry {
|
||||
let date: Date
|
||||
let events: [Event]
|
||||
}
|
||||
|
||||
// Timeline Provider to handle widget data
|
||||
struct EventWidgetProvider: TimelineProvider {
|
||||
func placeholder(in context: Context) -> EventWidgetEntry {
|
||||
EventWidgetEntry(date: Date(), events: [])
|
||||
}
|
||||
|
||||
func getSnapshot(in context: Context, completion: @escaping (EventWidgetEntry) -> ()) {
|
||||
let entry = EventWidgetEntry(date: Date(), events: getEvents())
|
||||
completion(entry)
|
||||
}
|
||||
|
||||
func getTimeline(in context: Context, completion: @escaping (Timeline<EventWidgetEntry>) -> ()) {
|
||||
let events = getEvents()
|
||||
let currentDate = Date()
|
||||
|
||||
// Timeline entry for the current date
|
||||
let entry = EventWidgetEntry(date: currentDate, events: events)
|
||||
|
||||
// Set timeline to refresh every 15 minutes
|
||||
let nextUpdateDate = Calendar.current.date(byAdding: .minute, value: 15, to: currentDate)!
|
||||
let timeline = Timeline(entries: [entry], policy: .after(nextUpdateDate))
|
||||
|
||||
completion(timeline)
|
||||
}
|
||||
|
||||
private func getEvents() -> [Event] {
|
||||
let viewModel = EventViewModel()
|
||||
viewModel.loadEvents()
|
||||
return viewModel.events
|
||||
}
|
||||
}
|
||||
|
||||
// Event Widget View
|
||||
struct EventWidgetView: View {
|
||||
var entry: EventWidgetEntry
|
||||
@Environment(\.widgetFamily) var widgetFamily
|
||||
var showedEvents: Int {
|
||||
switch widgetFamily {
|
||||
case .systemSmall:
|
||||
return 3
|
||||
case .systemMedium:
|
||||
return 3
|
||||
case .systemLarge:
|
||||
return 6
|
||||
default:
|
||||
return 3
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let isLarge = widgetFamily == .systemLarge
|
||||
let events = entry.events
|
||||
VStack {
|
||||
Text("Upcoming Events")
|
||||
.font(.subheadline)
|
||||
.padding(.top, -12)
|
||||
// .padding(.bottom, -5)
|
||||
|
||||
ForEach(events.prefix(showedEvents), id: \.id) { event in
|
||||
HStack {
|
||||
RoundedRectangle(cornerRadius: 5)
|
||||
.frame(width: 5)
|
||||
.frame(maxHeight: isLarge ? 50 : 30)
|
||||
.foregroundStyle(event.color.color)
|
||||
.padding(.leading, -18)
|
||||
.padding(.vertical, 2)
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Image(systemName: event.symbol)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 15, height: 15)
|
||||
.foregroundStyle(event.color.color)
|
||||
Text("\(event.name)")
|
||||
.font(.footnote)
|
||||
.padding(.leading, -5)
|
||||
}
|
||||
|
||||
if isLarge {
|
||||
if !event.description.isEmpty {
|
||||
Text(event.description)
|
||||
.font(.caption2)
|
||||
.foregroundColor(.gray)
|
||||
.padding(.top, -5)
|
||||
}
|
||||
Text(event.date.formatted(date: .long, time: .omitted))
|
||||
.font(.caption2)
|
||||
.foregroundColor(event.color.color)
|
||||
.padding(.top, -5)
|
||||
}
|
||||
if event.recurrence != .none {
|
||||
Text("\(event.recurrence.rawValue.capitalized)")
|
||||
.font(.caption2)
|
||||
.padding(.top, -5)
|
||||
}
|
||||
}
|
||||
.padding(.leading, -15)
|
||||
|
||||
Spacer()
|
||||
|
||||
Text(daysUntilEvent(event.date, short: !isLarge))
|
||||
.font(.caption)
|
||||
.foregroundColor(event.color.color)
|
||||
.padding(.trailing, -12)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
if showedEvents < events.count {
|
||||
let xMoreEvents = events.count - showedEvents
|
||||
Text("+\(xMoreEvents) more event\(xMoreEvents == 1 ? "" : "s")")
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.gray)
|
||||
.padding(.top, -5)
|
||||
.padding(.bottom, -15)
|
||||
}
|
||||
}
|
||||
.containerBackground(Color.widgetBackground, for: .widget)
|
||||
}
|
||||
}
|
||||
|
||||
struct Widget_Previews: PreviewProvider {
|
||||
static var events = [
|
||||
Event(
|
||||
name: "Event Name",
|
||||
symbol: "gear",
|
||||
color: ColorCodable(.blue),
|
||||
description: "Event description",
|
||||
date: Date.distantFuture,
|
||||
recurrence: .yearly
|
||||
),
|
||||
Event(
|
||||
name: "A Day",
|
||||
symbol: "star",
|
||||
color: ColorCodable(.orange),
|
||||
description: "description",
|
||||
date: Date(),
|
||||
recurrence: .daily
|
||||
),
|
||||
Event(
|
||||
name: "A Day",
|
||||
symbol: "star",
|
||||
color: ColorCodable(.orange),
|
||||
description: "description",
|
||||
date: Date(),
|
||||
recurrence: .daily
|
||||
),
|
||||
Event(
|
||||
name: "A Day",
|
||||
symbol: "star",
|
||||
color: ColorCodable(.orange),
|
||||
description: "description",
|
||||
date: Date(),
|
||||
recurrence: .daily
|
||||
),
|
||||
Event(
|
||||
name: "A Day",
|
||||
symbol: "star",
|
||||
color: ColorCodable(.orange),
|
||||
description: "description",
|
||||
date: Date(),
|
||||
recurrence: .daily
|
||||
)
|
||||
]
|
||||
static var previews: some View {
|
||||
Group {
|
||||
EventWidgetView(
|
||||
entry: EventWidgetEntry(
|
||||
date: Date(),
|
||||
events: events
|
||||
)
|
||||
)
|
||||
.previewContext(WidgetPreviewContext(family: .systemLarge))
|
||||
.previewDisplayName("Large")
|
||||
EventWidgetView(
|
||||
entry: EventWidgetEntry(
|
||||
date: Date(),
|
||||
events: events
|
||||
)
|
||||
)
|
||||
.previewContext(WidgetPreviewContext(family: .systemMedium))
|
||||
.previewDisplayName("Medium")
|
||||
EventWidgetView(
|
||||
entry: EventWidgetEntry(
|
||||
date: Date(),
|
||||
events: events
|
||||
)
|
||||
)
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
.previewDisplayName("Small")
|
||||
}
|
||||
}
|
||||
}
|
||||
31
NearFutureWidgets/NearFutureWidgetsBundle.swift
Normal file
31
NearFutureWidgets/NearFutureWidgetsBundle.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// NearFutureWidgetsBundle.swift
|
||||
// NearFutureWidgets
|
||||
//
|
||||
// Created by Nihaal Sharma on 02/01/2025.
|
||||
//
|
||||
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
//@main
|
||||
//struct NearFutureWidgetsBundle: WidgetBundle {
|
||||
// var body: some Widget {
|
||||
// NearFutureWidgets()
|
||||
// NearFutureWidgetsLiveActivity()
|
||||
// }
|
||||
//}
|
||||
|
||||
@main
|
||||
struct NearFutureWidget: Widget {
|
||||
let kind: String = "NearFutureWidget"
|
||||
|
||||
var body: some WidgetConfiguration {
|
||||
StaticConfiguration(kind: kind, provider: EventWidgetProvider()) { entry in
|
||||
EventWidgetView(entry: entry)
|
||||
}
|
||||
.configurationDisplayName("Upcoming Events Widget")
|
||||
.description("Displays your upcoming events.")
|
||||
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
|
||||
}
|
||||
}
|
||||
10
NearFutureWidgets/NearFutureWidgetsExtension.entitlements
Normal file
10
NearFutureWidgets/NearFutureWidgetsExtension.entitlements
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.com.neon443.NearFuture</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
80
NearFutureWidgets/NearFutureWidgetsLiveActivity.swift
Normal file
80
NearFutureWidgets/NearFutureWidgetsLiveActivity.swift
Normal file
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// NearFutureWidgetsLiveActivity.swift
|
||||
// NearFutureWidgets
|
||||
//
|
||||
// Created by Nihaal Sharma on 02/01/2025.
|
||||
//
|
||||
|
||||
import ActivityKit
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
struct NearFutureWidgetsAttributes: ActivityAttributes {
|
||||
public struct ContentState: Codable, Hashable {
|
||||
// Dynamic stateful properties about your activity go here!
|
||||
var emoji: String
|
||||
}
|
||||
|
||||
// Fixed non-changing properties about your activity go here!
|
||||
var name: String
|
||||
}
|
||||
|
||||
struct NearFutureWidgetsLiveActivity: Widget {
|
||||
var body: some WidgetConfiguration {
|
||||
ActivityConfiguration(for: NearFutureWidgetsAttributes.self) { context in
|
||||
// Lock screen/banner UI goes here
|
||||
VStack {
|
||||
Text("Hello \(context.state.emoji)")
|
||||
}
|
||||
.activityBackgroundTint(Color.cyan)
|
||||
.activitySystemActionForegroundColor(Color.black)
|
||||
|
||||
} dynamicIsland: { context in
|
||||
DynamicIsland {
|
||||
// Expanded UI goes here. Compose the expanded UI through
|
||||
// various regions, like leading/trailing/center/bottom
|
||||
DynamicIslandExpandedRegion(.leading) {
|
||||
Text("Leading")
|
||||
}
|
||||
DynamicIslandExpandedRegion(.trailing) {
|
||||
Text("Trailing")
|
||||
}
|
||||
DynamicIslandExpandedRegion(.bottom) {
|
||||
Text("Bottom \(context.state.emoji)")
|
||||
// more content
|
||||
}
|
||||
} compactLeading: {
|
||||
Text("L")
|
||||
} compactTrailing: {
|
||||
Text("T \(context.state.emoji)")
|
||||
} minimal: {
|
||||
Text(context.state.emoji)
|
||||
}
|
||||
.widgetURL(URL(string: "http://www.apple.com"))
|
||||
.keylineTint(Color.red)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension NearFutureWidgetsAttributes {
|
||||
fileprivate static var preview: NearFutureWidgetsAttributes {
|
||||
NearFutureWidgetsAttributes(name: "World")
|
||||
}
|
||||
}
|
||||
|
||||
extension NearFutureWidgetsAttributes.ContentState {
|
||||
fileprivate static var smiley: NearFutureWidgetsAttributes.ContentState {
|
||||
NearFutureWidgetsAttributes.ContentState(emoji: "😀")
|
||||
}
|
||||
|
||||
fileprivate static var starEyes: NearFutureWidgetsAttributes.ContentState {
|
||||
NearFutureWidgetsAttributes.ContentState(emoji: "🤩")
|
||||
}
|
||||
}
|
||||
|
||||
#Preview("Notification", as: .content, using: NearFutureWidgetsAttributes.preview) {
|
||||
NearFutureWidgetsLiveActivity()
|
||||
} contentStates: {
|
||||
NearFutureWidgetsAttributes.ContentState.smiley
|
||||
NearFutureWidgetsAttributes.ContentState.starEyes
|
||||
}
|
||||
Reference in New Issue
Block a user