Skip to content

Commit

Permalink
Merge pull request #8 from kvyatkovskys/feature/fix-bugs
Browse files Browse the repository at this point in the history
fixed a scroll in timeline, a new algorithm to calculate events in Page View
  • Loading branch information
kvyatkovskys authored Jun 17, 2019
2 parents 33a2b51 + e8ab58a commit 06c8356
Show file tree
Hide file tree
Showing 44 changed files with 9,216 additions and 374 deletions.
18 changes: 0 additions & 18 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
disabled_rules: # rule identifiers to exclude from running
- trailing_whitespace
- variable_name
- type_body_length
- valid_docs
- vertical_parameter_alignment
- unused_closure_parameter
- closure_parameter_position
- empty_enum_arguments
opt_in_rules: # some rules are only opt-in
included: # paths to include during linting. `--path` is ignored if present.
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Pods
# - Source/ExcludedFolder
# - Source/ExcludedFile.swift

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
Expand Down Expand Up @@ -54,10 +43,3 @@ variable_name:
- URL
- GlobalAPIKey
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle)

custom_rules:
explicit_failure_calls:
name: "Avoid asserting 'false'"
regex: "((assert|precondition)\\(false)"
message: "Use assertionFailure() or preconditionFailure() instead."
severity: warning
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

osx_image: xcode10.2
language: swift
# cache: cocoapods
# before_install:
# - gem install cocoapods # Since Travis is not always on latest version
# - pod install --project-directory=Example
script:
- set -o pipefail && xcodebuild test -workspace Example/KVKCalendar.xcworkspace -scheme KVKCalendar-Example -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty
- set -o pipefail && xcodebuild test -workspace KVKCalendar.xcworkspace -scheme KVKCalendar -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty
- pod lib lint
116 changes: 116 additions & 0 deletions CalendarModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// CalendarModel.swift
// KVKCalendar
//
// Created by Sergei Kviatkovskii on 17/06/2019.
//

import Foundation

public enum TimeHourSystem: Int {
case twelveHour = 12
case twentyFourHour = 24

var hours: [String] {
switch self {
case .twelveHour:
var array = [String]()

for idx in 0...11 {
if idx == 0 {
array.append("12")
} else {
let string = String(idx)
array.append(string)
}
}
var am = array.map { $0 + " AM" }
var pm = array.map { $0 + " PM" }

am.append("Noon")
pm.removeFirst()
pm.append(am.first!)

return am + pm
case .twentyFourHour:
var array = [String]()

for i in 0...24 {
if i == 0 {
array.append("00:00")
} else {
let i = i % 24
var string = i < 10 ? "0" + "\(i)" : "\(i)"
string.append(":00")
array.append(string)
}
}

return array
}
}
}

public enum CalendarType: String, CaseIterable {
case day, week, month, year
}

public struct Event {
public var id: Any = 0
public var text: String = ""
public var start: Date = Date()
public var end: Date = Date()
public var color: UIColor? = nil {
didSet {
guard let color = color else { return }
backgroundColor = color.withAlphaComponent(0.3)
var hue: CGFloat = 0, saturation: CGFloat = 0, brightness: CGFloat = 0, alpha: CGFloat = 0
color.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha)
colorText = UIColor(hue: hue, saturation: saturation, brightness: brightness * 0.4, alpha: alpha)
}
}
public var backgroundColor: UIColor = UIColor.blue.withAlphaComponent(0.3)
public var colorText: UIColor = .black
public var isAllDay: Bool = false
public var isContainsFile: Bool = false
public var textForMonth: String = ""
public var eventData: Any?

public init() {}
}

protocol CalendarFrameProtocol {
func reloadFrame(frame: CGRect)
}

protocol CalendarPrivateDelegate: AnyObject {
func didSelectCalendarDate(_ date: Date?, type: CalendarType)
func didSelectCalendarEvents(_ events: [Event])
func didSelectCalendarEvent(_ event: Event, frame: CGRect?)
func didSelectCalendarMore(_ date: Date, frame: CGRect?)
func getEventViewerFrame(frame: CGRect)
}

extension CalendarPrivateDelegate {
func getEventViewerFrame(frame: CGRect) {}
}

public protocol CalendarDataSource: AnyObject {
func eventsForCalendar() -> [Event]
}

public protocol CalendarDelegate: AnyObject {
func didSelectDate(date: Date?, type: CalendarType)
func didSelectEvents(_ events: [Event])
func didSelectEvent(_ event: Event, type: CalendarType, frame: CGRect?)
func didSelectMore(_ date: Date, frame: CGRect?)
func eventViewerFrame(_ frame: CGRect)
}

public extension CalendarDelegate {
func didSelectDate(date: Date?, type: CalendarType) {}
func didSelectEvents(_ events: [Event]) {}
func didSelectEvent(_ event: Event, type: CalendarType, frame: CGRect?) {}
func didSelectMore(_ date: Date, frame: CGRect?) {}
func eventViewerFrame(_ frame: CGRect) {}
}
Loading

0 comments on commit 06c8356

Please sign in to comment.