Skip to content

Commit

Permalink
updated Code
Browse files Browse the repository at this point in the history
  • Loading branch information
shankarmadeshvaran committed Aug 1, 2019
1 parent c41ab2e commit bee838e
Show file tree
Hide file tree
Showing 29 changed files with 1,203 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SwiftUI_Tasks
This is a basic app that lets you create a list of todos with specific date and time by user, mark the todos complete and then delete them.It will also send local notification based on the user preference of each tasks.

<p align="center">
<img src="https://github.com/shankarmadeshvaran/SwiftUI_Tasks/blob/master/ToDo-tasks.gif" width="30%"/>
</p>

This project was made for fun to try out Swift UI and see how it interacts with other layers of the application now that we don't have view controllers. We're all still learning. This project is merely my attempt to put something together based on the ideas put accross in WWDC videos and in the documentation.

## Platforms
Task app will currently run from iOS 13 beta.
This app is updated for Xcode 11 beta 5. I'll be updating the code for upcoming betas also.

## Issues
This task app having design issues and I'm still adding features , updating and fixing bugs whenever I came across.



Binary file added ToDo-tasks.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
371 changes: 371 additions & 0 deletions TodoList SwiftUI.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "BE439ADE-C197-4011-B629-45415FC10896"
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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>SchemeUserState</key>
<dict>
<key>TodoList SwiftUI.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
92 changes: 92 additions & 0 deletions TodoList SwiftUI/AddNewToDoTaskHeaderView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@


import SwiftUI

struct AddNewToDoTaskHeaderView: View {
@ObservedObject var toDoStore: ToDoStore
@State var dueDate = Date()

@State var newToDo: String = ""
@State var textfieldText: String = ""

@State var isShowAlert: Bool = false
@State var showDatePicker = false

var dateClosedRange: ClosedRange<Date> {
let min = Calendar.current.date(byAdding: .day, value: 0, to: Date())!
let max = Calendar.current.date(byAdding: .day, value: 7, to: Date())!
return min...max
}

var alert: Alert {
Alert(title: Text("Please enter the Task name"), message: Text("Next Task to Do"), dismissButton: .default(Text("OK")))
}
var dateFormatter: DateFormatter {
let dateFormatter = DateFormatter()
dateFormatter.timeStyle = .short
dateFormatter.dateStyle = .long
return dateFormatter
}

var body: some View {
VStack(alignment: .center, spacing: 20) {
TextField("Enter the new task to do",text: $newToDo)
.textFieldStyle(RoundedBorderTextFieldStyle())
.foregroundColor(.primary)
.font(.system(size: 20))
.frame(height: 60)

HStack(alignment: .center, spacing: 10) {
Text("Due Date")
.foregroundColor(.primary)
.font(.system(size: 21))
.bold()

Text("\(dueDate, formatter: dateFormatter)")
.foregroundColor(.secondary)
.font(.system(size: 20))
.bold()
}.onTapGesture {
self.showDatePicker.toggle()
}
if self.showDatePicker {
DatePicker(
selection: $dueDate,
in: dateClosedRange,
displayedComponents: [.hourAndMinute, .date],
label: {Text("")})
.datePickerStyle(DefaultDatePickerStyle())
}
Button(action: {
self.addNewTask(dueDate: self.dueDate)
}) {
AddNewTaskButtonView()
.frame(width: 250, height: 45, alignment: .center)
.background(Color.blue)
.cornerRadius(8)
}
} .padding(EdgeInsets(top: 15, leading: 15, bottom: 15, trailing: 15))
.alert(isPresented: $isShowAlert, content: {
alert
})
}

func addNewTask(dueDate: Date) {
if !self.newToDo.isEmpty {
self.toDoStore.toDOData.append(ToDo(title: self.newToDo, due: dueDate, isNotify: true))
self.newToDo = ""
} else {
self.isShowAlert = true
}
}
}

struct AddNewTaskButtonView: View {
var body: some View {
Text("Add New Task")
.bold()
.foregroundColor(.white)
.font(.system(size: 22))
}
}

105 changes: 105 additions & 0 deletions TodoList SwiftUI/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@




import UIKit
import Combine
import SwiftUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

@ObservedObject var data = ToDoStore()
let notificationCenter = UNUserNotificationCenter.current()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

notificationCenter.delegate = self

let options: UNAuthorizationOptions = [.alert, .sound, .badge]
notificationCenter.requestAuthorization(options: options) {
(didAllow, error) in
if !didAllow {
print("User has declined notifications")
}
}
return true
}

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

}

extension AppDelegate: UNUserNotificationCenterDelegate {

func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

completionHandler([.alert, .sound])
}

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

if response.notification.request.identifier == "tasks_remainder" {
print(response.notification.request.content.title)
print(response.notification.request.content.attachments)
print(response.notification.request.content.body)
print(response.notification.request.content.subtitle)
}
completionHandler()
}

func scheduleNotification(notificationType: ToDo) {

let content = UNMutableNotificationContent()
let categoryIdentifier = "Delete Notification Type"

content.title = "Remainder: Task about to Expire"
content.body = "Your task " + notificationType.title + " needs to be completed on or before \(notificationType.due.dateFormatterString())"
content.subtitle = "TASK"

let imageName = "Swift"
guard let imageURL = Bundle.main.url(forResource: imageName, withExtension: "png") else { return }
let attachment = try! UNNotificationAttachment(identifier: imageName, url: imageURL, options: .none)

content.attachments = [attachment]

content.sound = UNNotificationSound.default
content.badge = 1
content.categoryIdentifier = categoryIdentifier

let dateComponentsNotify = notificationType.due.dateComponentsToNotify()

let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponentsNotify, repeats: false)
let identifier = "tasks_remainder"
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)

notificationCenter.add(request) { (error) in
if let error = error {
print("Error \(error.localizedDescription)")
}
}

let snoozeAction = UNNotificationAction(identifier: "Complete", title: "Mark as Complete", options: [])
let deleteAction = UNNotificationAction(identifier: "Delete", title: "Delete", options: [.destructive])
let category = UNNotificationCategory(identifier: categoryIdentifier,
actions: [snoozeAction, deleteAction],
intentIdentifiers: [],
options: [])

notificationCenter.setNotificationCategories([category])
}
}
98 changes: 98 additions & 0 deletions TodoList SwiftUI/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
6 changes: 6 additions & 0 deletions TodoList SwiftUI/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
21 changes: 21 additions & 0 deletions TodoList SwiftUI/Assets.xcassets/Swift.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Swift.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit bee838e

Please sign in to comment.