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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Demo/Bulletin.xcodeproj/project.xcworkspace/xcuserdata/pranav.xcuserdatad/UserInterfaceState.xcuserstate
Demo/Bulletin.xcodeproj/xcuserdata/pranav.xcuserdatad/xcschemes/xcschememanagement.plist
87 changes: 87 additions & 0 deletions BulletinSDK/BulletinDataStore.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// BulletinDataStore.swift
// Bulletin
//
// Created by Pranav Panchal on 22/09/22.
//

import Foundation

class BulletinDataStore {


// MARK: - Variable
public private(set) var data = [BulletinInfo]()


// MARK: - Initialisation Methods
public init() {}

public init?(attributes: [String : Any]) {

}


// MARK: - Helper Methods
public func registerVersionInfo(version: Version, items: [[String: Any]]) {

var bulletinItems = [BulletinItem]()
for itemAttributes in items {
guard let bulletinItem = BulletinItem.createBulletinItem(forAttributes: itemAttributes) else { continue }
bulletinItems.append(bulletinItem)
}

registerVersionInfo(version: version, items: bulletinItems)
}

public func registerVersionInfo(version: Version, items: [BulletinItem]) {

// Validation
guard items.isEmpty == false else { return }

// Create Bulletin Info Object
let bulletinInfo = BulletinInfo(version: version, items: items)

for (i,item) in data.enumerated() {

// Check If Same Version Available In Data
if item.version == version {

// Remove Value
data.remove(at: i)

// Add New Value
data.append(bulletinInfo)
return
}
}

data.append(bulletinInfo)
}

public func getData(fromNewVersion newVersion: Version?, toOldVersion oldVersion: Version?, limit: Int? = nil) -> [BulletinInfo]? {

// Sort Bulletin Info
let sortedInfos = data.sorted(by: { $0.version > $1.version })

var filteredInfos = [BulletinInfo]()
for info in sortedInfos {

// Add Info Only When Conditions Are True
if let newVersion = newVersion, info.version <= newVersion {
filteredInfos.append(info)
} else if let oldVersion = oldVersion, info.version >= oldVersion {
filteredInfos.append(info)
} else {
filteredInfos.append(info)
}

// Validation For Limit
if let limit = limit, filteredInfos.count >= limit {
return filteredInfos
}
}

return filteredInfos
}
}
84 changes: 84 additions & 0 deletions BulletinSDK/BulletinSDK.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// BulletinSDK.swift
// Bulletin
//
// Created by Pranav Panchal on 22/09/22.
//

import Foundation

class BulletinSDK {


// MARK: - Variables
public let dataStore: BulletinDataStore


// MARK: Initialisation Method
public init(dataStore: BulletinDataStore, appearance: Appearance) {

// Set Data Store
self.dataStore = dataStore
applyAppearance(theme: appearance)
}


// MARK: - Helper Methods
public func getFullBulletin() -> BulletinListVC? {

// Get Bulletin Items
let items = dataStore.getData(fromNewVersion: nil, toOldVersion: nil)

// Show Bulletin
return getBulletin(items: items)
}

public func getLastBulletins(limit: Int = 1) -> BulletinListVC? {

// Get Bulletin Items
let items = dataStore.getData(fromNewVersion: nil, toOldVersion: nil, limit: limit)

// Show Bulletin
return getBulletin(items: items)
}

public func getUnseenBulletins(limit: Int? = nil) -> BulletinListVC? {

// Get Last Seen Version
guard let lastSeenVersion = UserDefaults.lastSeenVersion else { return nil }

// Get Bulletin Items
let items = dataStore.getData(fromNewVersion: lastSeenVersion, toOldVersion: nil, limit: limit)

// Show Bulletin
return getBulletin(items: items)
}

private func getBulletin(items: [BulletinInfo]?) -> BulletinListVC? {

// Validation
guard let items = items,
items.isEmpty == false else { return nil }

let bulletinListVC = BulletinListVC.instance(items: items)

return bulletinListVC
}

private func applyAppearance(theme: Appearance) {

// Apply Theme
switch theme {
case .darkKnight:

// Apply Dark Knight Theme
Appearance.darkKnight.apply(shouldBroadcastUpdate: true)

case .whiteKnight:

// Apply Dark Knight Theme
Appearance.whiteKnight.apply(shouldBroadcastUpdate: true)
}

}
}
45 changes: 45 additions & 0 deletions BulletinSDK/Classes/Base/View/BaseCollectionViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// BaseTableViewCell.swift
// Bulletin
//
// Created by Daxesh Nagar on 17/07/23.
// Copyright © 2023 Copyright © 2022 Zanmai Labs Private Limited. All rights reserved.
//

import UIKit

class BaseCollectionViewCell: UICollectionViewCell {

// MARK: - Constants
public class func identifier() -> String {
return String(describing: self)
}


// MARK: - Initialisation Methods
override func awakeFromNib() {
super.awakeFromNib()

if #available(iOS 13.0, *) {
layer.cornerCurve = .continuous
}

// Load Variables
loadVariables()

// Update Appearance
updateAppearance()

}


// MARK: - Override Methods
open func loadVariables() {
// Override This Method In Subclass To Initialize Variables
}

open func updateAppearance() {
// Override This Method In Subclass To Set/Update Appearance
}

}
20 changes: 20 additions & 0 deletions BulletinSDK/Classes/Categories/NSAttributedString+Utility.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// NSAttributedString+Utility.swift
// Bulletin
//
// Created by Daxesh Nagar on 21/07/23.
// Copyright © 2023 Copyright © 2022 Zanmai Labs Private Limited. All rights reserved.
//

import Foundation

extension NSAttributedString {

var trailingNewlineChopped: NSAttributedString {
if string.hasSuffix("\n") {
return attributedSubstring(from: NSRange(location: 0, length: length - 1))
} else {
return self
}
}
}
38 changes: 38 additions & 0 deletions BulletinSDK/Classes/Categories/String+HTML.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// String+HTML.swift
// Bulletin
//
// Created by Daxesh Nagar on 21/07/23.
// Copyright © 2023 Copyright © 2022 Zanmai Labs Private Limited. All rights reserved.
//

import UIKit

extension String {

public func html2AttributedString(usingFont font: UIFont?, color: UIColor = .black) -> NSMutableAttributedString? {

let text : String

// Add Font Attributes
if let font = font {
let colorHashCode = color.hexString()
let startTag = "<SPAN style=\"font-size:\(font.pointSize)px; font-family:'\(font.fontName)','-apple-system'; color:\(colorHashCode)\">"
let endTag = "</SPAN>"
text = (startTag + self + endTag)
}
else {
text = self as String
}

// Convert HTML To Attributed String
do {
return try NSMutableAttributedString(data: Data(text.utf8), options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch {
print("error:", error)
return nil
}

}
}

21 changes: 21 additions & 0 deletions BulletinSDK/Classes/Categories/String+Unicode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// String+Unicode.swift
// Bulletin
//
// Created by Daxesh Nagar on 26/07/23.
// Copyright © 2023 Copyright © 2022 Zanmai Labs Private Limited. All rights reserved.
//

import Foundation

extension String {

var unicodeString: String? {
if let charCode = UInt32(self, radix: 16),
let unicode = UnicodeScalar(charCode) {
let str = String(unicode)
return str
}
return nil
}
}
Loading