Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
202 changes: 198 additions & 4 deletions Schedule_B.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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 = "24392DAD-2AB7-484B-A601-BCAE1D57D6B1"
type = "1"
version = "2.0">
</Bucket>
21 changes: 21 additions & 0 deletions Schedule_B/Assets.xcassets/google_calendar.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "google_calendar.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Schedule_B/Assets.xcassets/sign_with_google.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "googleLogin.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
644 changes: 567 additions & 77 deletions Schedule_B/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions Schedule_B/CalendarExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// CalendarExtension.swift
// Schedule_B
//
// Created by KEEN on 2021/02/23.
//

import Foundation

extension Calendar {
static func getDaysInMonth(_ yearAndMonth: Int) -> Int {
let firstDate = firstDateOfMonth(yearAndMonth)
let range = Calendar.current.range(
of: .day,
in: .month,
for: firstDate)
return range!.count
}
static func firstDateOfMonth(_ yearAndMonth: Int) -> Date {
return DateComponents(
calendar: Calendar.current,
timeZone: .current,
year: yearAndMonth / 100,
month: yearAndMonth % 100).date!
}
}

extension Date {
var year: Int {
Calendar.current.component(.year, from: self)
}
var month: Int {
Calendar.current.component(.month, from: self)
}
var day: Int {
Calendar.current.component(.day, from: self)
}
var weekDay: Int {
Calendar.current.component(.weekday, from: self)
}
var hour: Int {
Calendar.current.component(.hour, from: self)
}
var minute: Int {
Calendar.current.component(.minute, from: self)
}

var aMonthAgo: Date {
return Calendar.current.date(
byAdding: DateComponents(month: -1), to: self)!
}
var aMonthAfter: Date {
return Calendar.current.date(
byAdding: DateComponents(month: 1), to: self)!
}
func isSameDay(with toCompare: Date) -> Bool {
return self.year == toCompare.year && self.month == toCompare.month && self.day == toCompare.day
}
var toInt: Int {
return (self.year * 10000) + (self.month * 100) + self.day
}
func getNext(by component: ComponentType) -> Date{
var nextComponent = Calendar.current.dateComponents([.hour, .minute], from: self)

switch component {
case .day(let day):
nextComponent.day = day
case .weekday(let weekday):
nextComponent.weekday = weekday
}

return Calendar.current.nextDate(
after: self,
matching: nextComponent,
matchingPolicy: .nextTime)!
}
enum ComponentType {
case day (Int)
case weekday (Int)
}
}

extension Int {
var toDate: Date?{
DateComponents(
calendar: Calendar.current,
timeZone: .current,
year: self / 10000,
month: (self / 100) % 100,
day: self % 100).date
}
}
28 changes: 28 additions & 0 deletions Schedule_B/CalenderCellVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// CalenderCellVC.swift
// Schedule_B
//
// Created by KEEN on 2021/02/23.
//

import SwiftUI
import Combine

class CalendarCellVC: UICollectionViewCell {
var cellView: CellContentsView {
get {
hostingController.rootView
}
set{
hostingController.rootView = newValue
}
}


// Swift UI
var hostingController = UIHostingController(rootView: CellContentsView())
static func size(in frameSize: CGSize) -> CGSize{
CGSize(width: ((frameSize.width - 2) / 8),
height: ((frameSize.height - 2) / 7))
}
}
96 changes: 96 additions & 0 deletions Schedule_B/CellContentsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// CellContentsView.swift
// Schedule_B
//
// Created by KEEN on 2021/02/23.
//

import SwiftUI

struct CellContentsView: View {
var date: Int?
var isToday = false
var schedules = [Schedule]()
var searchRequest: SingleCalendarViewController.SearchRequest?
var holiday: HolidayGather.Holiday?
private var filteredSchedules: Array<Schedule>.SubSequence {
let filtered = schedules.filter() {
if let search = searchRequest {
if search.priority != nil, search.priority != $0.priority{
return false
}
if search.text != nil{
return $0.title.lowercased().contains(search.text!) || $0.description.lowercased().contains(search.text!)
}else {
return true
}
}else {
return true
}
}
// fillter by priority
return filtered.sorted { lhs, rhs in
if lhs.priority == rhs.priority {
return lhs > rhs
}else {
return lhs.priority < rhs.priority
}
}.prefix(3)
}
private var dateFontColor: Color {
if holiday != nil {
if date!.toDate!.weekDay == 1 || holiday!.type == .national {
return Color.red
}else if date!.toDate!.weekDay == 7 {
return Color.blue
}else {
return Color.gray
}
}else {
return Color.forDate(date!.toDate!)
}
}

var body: some View {
if date != nil {
GeometryReader{ geometry in
VStack{
Text(String(date! % 100))
.font(.body)
.overlay(isToday ? RoundedRectangle(
cornerRadius: 10)
.stroke(Color.red.opacity(0.8),
lineWidth: 2.5)
: nil)
if holiday != nil{
Text(holiday!.title)
.font(.system(size: 10))
.lineLimit(1)
}
}
.foregroundColor(dateFontColor)
.padding(3)
.position(x: geometry.size.width / 2, y: geometry.size.height * 0.2)
VStack{
ForEach(filteredSchedules, id:\.id) { schedule in
HStack{
RoundedRectangle(cornerRadius: 10, style: .circular)
.inset(by: CGFloat(4.5 - Double(schedules.count)))
.fill(Color.byPriority(schedule.priority))
.aspectRatio(0.3, contentMode: .fit)
Text(schedule.title)
.font(.system(size: 10))
.lineLimit(1)
.foregroundColor(Color.byPriority(schedule.priority))
.padding(.leading, -7)
}
.frame(width: geometry.size.width,
height:
(geometry.size.height * 0.7) / CGFloat(schedules.count + 1))
}
}
.padding(.top, holiday == nil ? 25: 35)
}
}
}
}
49 changes: 49 additions & 0 deletions Schedule_B/ColorExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// ColorExtension.swift
// Schedule_B
//
// Created by KEEN on 2021/02/23.
//

import SwiftUI

extension CGColor {
static var salmon: CGColor {
CGColor(red: 0.98, green: 0.52, blue: 0.55, alpha: 0.8)
}
}
extension Color {
static func forDate(_ date: Date) -> Color {
if date.weekDay == 1 {
return Color.pink
}else if date.weekDay == 7 {
return Color.blue
}else {
return Color.black
}
}
enum Button: String, CaseIterable {
case red = "🔴"
case orange = "🟠"
case green = "🟢"
case blue = "🔵"
case black = "⚫️"
}
static func byPriority(_ priority: Int) -> Color {
guard priority > 0 , priority < 6 else {
fatalError("Drawing fail: Invalid priority of schedule is passed to cell")
}
switch priority {
case 1:
return Color.red
case 2:
return Color.orange
case 3:
return Color.green
case 4:
return Color.blue
default:
return Color.black
}
}
}
Loading