Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lufzi committed Apr 10, 2018
2 parents a0c7fa3 + c5bfb78 commit 18364cb
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 127 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# CHANGELOG

The changelog for `Pai`. Also see the [releases](https://github.com/lkmfz/Pai/releases) on GitHub.
The changelog for `Pai`. Also see the [releases](https://github.com/kaodim/Pai/releases) on GitHub.

--------------------------------------

## Upcoming Releases

### [Pre-release 0.1.0](https://github.com/lkmfz/Ubud/releases/tag/0.1.0)
### [Pre-release 0.1.0](https://github.com/kaodim/Pai/releases/tag/0.1.0)

### [Pre-release 0.2.0](https://github.com/kaodim/Pai/releases/tag/0.2.0)
* Alignment user interface & specs according to [Kaodim](https://github.com/kaodim) product needs.
* Ownership transfer of the project to [Kaodim](https://github.com/kaodim).
6 changes: 3 additions & 3 deletions Pai-Example/Pai-Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = "Luqman Fauzi";
ORGANIZATIONNAME = Kaodim;
TargetAttributes = {
D588F2831FEBF54000AEE201 = {
CreatedOnToolsVersion = 9.2;
Expand Down Expand Up @@ -638,7 +638,7 @@
DEVELOPMENT_TEAM = R2XF3NYPAG;
INFOPLIST_FILE = "Pai-Example/Supporting Files/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "me.luqmanfauzi.Pai-Example";
PRODUCT_BUNDLE_IDENTIFIER = "com.kaodim.pai-example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -654,7 +654,7 @@
DEVELOPMENT_TEAM = R2XF3NYPAG;
INFOPLIST_FILE = "Pai-Example/Supporting Files/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "me.luqmanfauzi.Pai-Example";
PRODUCT_BUNDLE_IDENTIFIER = "com.kaodim.pai-example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
9 changes: 5 additions & 4 deletions Pai-Example/Pai-Example/ExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ final class ExampleViewController: UIViewController, PaiCalendarDelegate, PaiCal
title = month + " " + year
}

// MARK: - PaiCalendarDataSourc

func calendarDateEvents(in calendar: MonthCollectionView) -> [PaiDateEvent] {
let events = PaiDateEvent.generateRandom(numberOfEvents: 6)
// MARK: - PaiCalendarDataSource3
func calendarDateEvents(in calendar: MonthCollectionView) -> [PaiMonthEvent] {
let events = PaiMonthEvent.generateRandom(numberOfEvents: 6, numberOfDays: 3, monthYearArr: ["2018 3","2018 4","2018 5"])
return events


}
}
6 changes: 3 additions & 3 deletions Pai-Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Pai (0.0.1)
- Pai (0.1.0)

DEPENDENCIES:
- Pai (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: ../

SPEC CHECKSUMS:
Pai: 99dbbbd7bb121d409120d3de14b10544a1a4bea9
Pai: 5bc90c0dd19da9faf2bae514e2b75909b9fdde26

PODFILE CHECKSUM: b2f25666c2d0afccc931dbd6c838c61a7bf216f7

COCOAPODS: 1.3.1
COCOAPODS: 1.4.0
9 changes: 4 additions & 5 deletions Pai.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Pod::Spec.new do |s|
s.name = 'Pai'
s.version = '0.1.0'
s.version = '0.2.0'
s.license = { :type => "MIT", :file => "LICENSE.md" }

s.summary = 'Calendar view library for iOS.'
s.homepage = 'https://github.com/lkmfz/Pai'
s.social_media_url = 'https://twitter.com/lkmfz'
s.author = { "Luqman Fauzi" => "[email protected]" }
s.homepage = 'https://github.com/kaodim/Pai'
s.author = { "Kaodim" => "[email protected]" }

s.source = { :git => 'https://github.com/lkmfz/Pai.git', :tag => s.version }
s.source = { :git => 'https://github.com/kaodim/Pai.git', :tag => s.version }
s.source_files = 'Pai/Sources/**/*.swift'

s.pod_target_xcconfig = {
Expand Down
10 changes: 7 additions & 3 deletions Pai.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
D588F2691FEBF48C00AEE201 /* Pai.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D588F25F1FEBF48C00AEE201 /* Pai.framework */; };
D588F26E1FEBF48C00AEE201 /* PaiTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D588F26D1FEBF48C00AEE201 /* PaiTests.swift */; };
D588F2701FEBF48C00AEE201 /* Pai.h in Headers */ = {isa = PBXBuildFile; fileRef = D588F2621FEBF48C00AEE201 /* Pai.h */; settings = {ATTRIBUTES = (Public, ); }; };
D59A40C0207C5E1D00F6B3A2 /* PaiMonthEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D59A40BF207C5E1C00F6B3A2 /* PaiMonthEvent.swift */; };
D5A0EB682007DA9E00CC4A2E /* PaiDateEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A0EB672007DA9E00CC4A2E /* PaiDateEvent.swift */; };
D5D3AD8B2006F113002C74E4 /* UICollectionView+Custom.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5D3AD8A2006F113002C74E4 /* UICollectionView+Custom.swift */; };
D5D3AD9220071787002C74E4 /* PaiCalendarDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5D3AD9120071787002C74E4 /* PaiCalendarDelegate.swift */; };
Expand Down Expand Up @@ -46,6 +47,7 @@
D588F2681FEBF48C00AEE201 /* PaiTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PaiTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D588F26D1FEBF48C00AEE201 /* PaiTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaiTests.swift; sourceTree = "<group>"; };
D588F26F1FEBF48C00AEE201 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D59A40BF207C5E1C00F6B3A2 /* PaiMonthEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PaiMonthEvent.swift; path = Pai/Sources/Models/PaiMonthEvent.swift; sourceTree = SOURCE_ROOT; };
D5A0EB672007DA9E00CC4A2E /* PaiDateEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaiDateEvent.swift; sourceTree = "<group>"; };
D5D3AD8A2006F113002C74E4 /* UICollectionView+Custom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Custom.swift"; sourceTree = "<group>"; };
D5D3AD9120071787002C74E4 /* PaiCalendarDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaiCalendarDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -107,6 +109,7 @@
D5D3AD93200756B1002C74E4 /* PaiMonth.swift */,
D5D3AD95200756F8002C74E4 /* PaiDate.swift */,
D5A0EB672007DA9E00CC4A2E /* PaiDateEvent.swift */,
D59A40BF207C5E1C00F6B3A2 /* PaiMonthEvent.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -243,7 +246,7 @@
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = "Luqman Fauzi";
ORGANIZATIONNAME = Kaodim;
TargetAttributes = {
D588F25E1FEBF48C00AEE201 = {
CreatedOnToolsVersion = 9.2;
Expand Down Expand Up @@ -323,6 +326,7 @@
D5E3FCE51FF28CF90059433E /* MonthHeaderView.swift in Sources */,
D54FC8EF1FECA8FD00EC148D /* MonthCollectionView.swift in Sources */,
D5D3AD9220071787002C74E4 /* PaiCalendarDelegate.swift in Sources */,
D59A40C0207C5E1D00F6B3A2 /* PaiMonthEvent.swift in Sources */,
D5D3AD8B2006F113002C74E4 /* UICollectionView+Custom.swift in Sources */,
D5E3FCF11FF2BBFA0059433E /* DayCollectionView.swift in Sources */,
D54FC8F61FECB04E00EC148D /* DayViewCell.swift in Sources */,
Expand Down Expand Up @@ -475,7 +479,7 @@
INFOPLIST_FILE = "Pai/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.luqmanfauzi.Pai;
PRODUCT_BUNDLE_IDENTIFIER = com.kaodim.pai;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -498,7 +502,7 @@
INFOPLIST_FILE = "Pai/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.luqmanfauzi.Pai;
PRODUCT_BUNDLE_IDENTIFIER = com.kaodim.pai;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
Expand Down
33 changes: 16 additions & 17 deletions Pai/Sources/Models/PaiDateEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,28 @@ public struct PaiDateEvent {

public let date: Date

public let name: String?
public let tagColors: [UIColor]

public let tagColor: UIColor
public var monthYearStr: String {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy M"
return formatter.string(from: date)
}

public var dateStr: String {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy M dd"
return formatter.string(from: date)

}

/// Initlizer of the struct
///
/// - Parameters:
/// - date: `Date` of event
/// - name: optional `String` of event name
/// - tagColor: `UIColor` tag color of event
public static func initObject(date: Date, name: String?, tagColor: UIColor) -> PaiDateEvent {
return PaiDateEvent(date: date, name: name, tagColor: tagColor)
/// - tagColors: `[UIColor]` array of tag color
public static func initObject(date: Date, tagColors: [UIColor]) -> PaiDateEvent {
return PaiDateEvent(date: date, tagColors: tagColors)
}
}

public extension PaiDateEvent {
public static func generateRandom(numberOfEvents: Int) -> [PaiDateEvent] {
var events: [PaiDateEvent] = []
for i in 1...numberOfEvents {
let color: UIColor = (i % 2 == 0) ? .red : .blue
let event = PaiDateEvent(date: Date(), name: nil, tagColor: color)
events.append(event)
}
return events
}
}
61 changes: 61 additions & 0 deletions Pai/Sources/Models/PaiMonthEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// PaiMonthEvent.swift
// Pai
//
// Created by augustius cokroe on 23/03/2018.
//

import Foundation

public struct PaiMonthEvent {

public let monthYearStr: String // yyyy M

public let monthEvents: [PaiDateEvent]

/// Initlizer of the struct
///
/// - Parameters:
/// - monthYearStr: date of event in `yyyy M` format
/// - monthEvents: array of PaiDateEvent object
public static func initObject(monthYearStr: String, monthEvents: [PaiDateEvent]) -> PaiMonthEvent {
return PaiMonthEvent(monthYearStr: monthYearStr, monthEvents: monthEvents)
}
}

public extension PaiMonthEvent {
/// Generate random events
///
/// - Parameters:
/// - numberOfEvents: `Date` of event
/// - numberOfDays: `[UIColor]` array of tag color
/// - monthYearArr: `[String]` array of string of date with format `yyyy M`
public static func generateRandom(numberOfEvents: Int, numberOfDays: Int, monthYearArr: [String]) -> [PaiMonthEvent] {

/// get array of color for each day
var tagColors = [UIColor]()
for i in 1...numberOfEvents {
let color: UIColor = (i % 2 == 0) ? .red : .blue
tagColors.append(color)
}

/// get array of PaiMonthEvent with events
var monthEvents: [PaiMonthEvent] = []
let secondsInDays: TimeInterval = 60 * 60 * 24
for (index,str) in monthYearArr.enumerated() {
var dayEvents: [PaiDateEvent] = []
for day in 1...numberOfDays {
var date = Date().addingTimeInterval(Double(day - 1) * secondsInDays)
date = Calendar.current.date(byAdding: .month, value: index, to: date) ?? Date()
let event = PaiDateEvent(date: date, tagColors: tagColors)
dayEvents.append(event)
}
let mEvent = PaiMonthEvent.initObject(monthYearStr: str, monthEvents: dayEvents)
monthEvents.append(mEvent)
}

return monthEvents
}
}


15 changes: 12 additions & 3 deletions Pai/Sources/Protocols/PaiCalendarDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import Foundation

public protocol PaiCalendarDataSource: class {

/// List of `[PaiDateEvent]` events to be displayed in calendar
/// List of `[PaiMonthEvent]` events to be displayed in calendar
///
/// - Parameter calendar: `MonthCollectionView`
/// - Returns: list of all events to be displayed in the calendar view
func calendarDateEvents(in calendar: MonthCollectionView) -> [PaiDateEvent]
func calendarDateEvents(in calendar: MonthCollectionView) -> [PaiMonthEvent]
}

public extension PaiCalendarDataSource {
func calendarDateEvents(in calendar: MonthCollectionView) -> [PaiDateEvent] {
func calendarDateEvents(in calendar: MonthCollectionView) -> [PaiMonthEvent] {
return []
}
}
Expand All @@ -41,9 +41,18 @@ public protocol PaiCalendarDelegate: class {
/// - month: string of selected month
/// - year: string of selected year
func calendarMonthViewDidScroll(in calendar: MonthCollectionView, at index: Int, month: String, year: String)

/// Send month string when month cell is currently at top of screen
///
/// - Parameters:
/// - calendar: `MonthCollectionView`
/// - datesString: array of formattable date string of current visible month [yyyy-MM-dd]
func calendarMonthVisibleMonth(in calendar: MonthCollectionView, datesString: [String])
}

public extension PaiCalendarDelegate {
func calendarDateDidSelect(in calendar: MonthCollectionView, at index: Int, date: PaiDate) { }
func calendarMonthViewDidScroll(in calendar: MonthCollectionView, at index: Int, month: String, year: String) { }
func calendarMonthVisibleMonth(in calendar: MonthCollectionView, datesString: [String]) { }
}

37 changes: 24 additions & 13 deletions Pai/Sources/Views/DayCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

internal typealias DailyEventsItem = (date: Date, events: [PaiDateEvent])
internal typealias DailyEventsItem = (date: Date, event: PaiDateEvent?)

public class DayCollectionView: UICollectionView {

Expand Down Expand Up @@ -54,18 +54,28 @@ public class DayCollectionView: UICollectionView {
/// - Parameters:
/// - month: `PaiMonth`
/// - events: events in particular `PaiMonth`
public func configure(_ month: PaiMonth, _ events: [PaiDateEvent]) {
public func configure(_ month: PaiMonth, _ events: PaiMonthEvent?) {
self.month = month
/// Map events of the particular date, according to collectionView item index.
var items: [DailyEventsItem] = []
dates.map({ $0.date }).forEach { (date) in
let dailyEvents = events.filter({
Calendar.autoupdatingCurrent.compare($0.date, to: date, toGranularity: .day) == .orderedSame
})
let item: DailyEventsItem = (date, dailyEvents)
items.append(item)
/// initiate dailyEventsItems
dailyEventsItems = dates.map({
let items: DailyEventsItem = ($0.date, nil)
return items
})

guard let events = events else { return }

let allDateStr = Set(events.monthEvents.map({$0.dateStr}).sorted())
allDateStr.forEach { (dateStr) in
let dayEvent = events.monthEvents.first(where: {$0.dateStr == dateStr})
if let index = dailyEventsItems.index(where: {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy M dd"
return formatter.string(from: $0.date) == dateStr
}) {
dailyEventsItems[index] = (dates[index].date, dayEvent)
}
}
dailyEventsItems = items
reloadData()
}
}

Expand All @@ -81,8 +91,8 @@ extension DayCollectionView: UICollectionViewDataSource, UICollectionViewDelegat
guard
let cell = collectionView.dequeueReusableCell(withClass: DayViewCell.self, for: indexPath),
let monthItem = month
else {
fatalError("DayViewCell not found.")
else {
fatalError("DayViewCell not found.")
}

let dateItem = dates[indexPath.item]
Expand Down Expand Up @@ -127,3 +137,4 @@ extension DayCollectionView: UICollectionViewDataSource, UICollectionViewDelegat
return CGSize(width: itemWidth, height: itemHeight)
}
}

Loading

0 comments on commit 18364cb

Please sign in to comment.