Skip to content

Commit

Permalink
Migrate to multiplatform
Browse files Browse the repository at this point in the history
  • Loading branch information
bourvill committed Feb 18, 2021
0 parents commit d668d17
Show file tree
Hide file tree
Showing 117 changed files with 5,886 additions and 0 deletions.
1 change: 1 addition & 0 deletions .swiftversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.3
11 changes: 11 additions & 0 deletions Shared/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
148 changes: 148 additions & 0 deletions Shared/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Shared/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
81 changes: 81 additions & 0 deletions Shared/Entity/Entry.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import CoreData
import CoreSpotlight
import Foundation
// import MobileCoreServices
import WallabagKit

class Entry: NSManagedObject, Identifiable {}

extension Entry {
@nonobjc class func fetchRequestSorted() -> NSFetchRequest<Entry> {
let fetchRequest = NSFetchRequest<Entry>(entityName: "Entry")
let sortDescriptor = NSSortDescriptor(key: "id", ascending: false)
fetchRequest.sortDescriptors = [sortDescriptor]
return fetchRequest
}

@nonobjc class func fetchOneById(_ id: Int) -> NSFetchRequest<Entry> {
let fetchRequest = NSFetchRequest<Entry>(entityName: "Entry")
fetchRequest.predicate = NSPredicate(format: "id == %ld", id)
return fetchRequest
}

@NSManaged dynamic var content: String?
@NSManaged dynamic var createdAt: Date?
@NSManaged dynamic var domainName: String?
@NSManaged dynamic var id: Int
@NSManaged dynamic var isArchived: Bool
@NSManaged dynamic var isStarred: Bool
@NSManaged dynamic var previewPicture: String?
@NSManaged dynamic var title: String?
@NSManaged dynamic var updatedAt: Date?
@NSManaged dynamic var url: String?
@NSManaged dynamic var readingTime: Int
@NSManaged dynamic var screenPosition: Float
@NSManaged var tags: Set<Tag>
}

extension Entry {
var spotlightIdentifier: String {
"\(Bundle.main.bundleIdentifier!).spotlight.\(Int(id))"
}

var searchableItemAttributeSet: CSSearchableItemAttributeSet {
let searchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String)
searchableItemAttributeSet.title = title
searchableItemAttributeSet.contentDescription = content?.withoutHTML

return searchableItemAttributeSet
}

func hydrate(from article: WallabagEntry) {
id = article.id
title = article.title
content = article.content
createdAt = Date.fromISOString(article.createdAt)
updatedAt = Date.fromISOString(article.updatedAt)
domainName = article.domainName
isArchived = article.isArchived.bool
isStarred = article.isStarred.bool
previewPicture = article.previewPicture
url = article.url
readingTime = article.readingTime ?? 0
}

func toggleArchive() {
isArchived.toggle()
objectWillChange.send()
}

func toggleStarred() {
isStarred.toggle()
objectWillChange.send()
}

var screenPositionForWebView: Double {
if screenPosition < 0 {
return 0.0
}
return Double(screenPosition)
}
}
8 changes: 8 additions & 0 deletions Shared/Entity/Podcast.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

struct Podcast {
let id: Int
let title: String
let content: String
let picture: String?
}
25 changes: 25 additions & 0 deletions Shared/Entity/Tag.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import CoreData
import Foundation

class Tag: NSManagedObject, Identifiable {
@Published var isChecked: Bool = false
}

extension Tag {
@nonobjc class func fetchRequestSorted() -> NSFetchRequest<Tag> {
let fetchRequest = NSFetchRequest<Tag>(entityName: "Tag")
let sortDescriptor = NSSortDescriptor(key: "label", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
return fetchRequest
}

@nonobjc class func fetchOneById(_ id: Int) -> NSFetchRequest<Tag> {
let fetchRequest = NSFetchRequest<Tag>(entityName: "Tag")
fetchRequest.predicate = NSPredicate(format: "id == %ld", id)
return fetchRequest
}

@NSManaged dynamic var id: Int
@NSManaged dynamic var label: String
@NSManaged dynamic var slug: String
}
7 changes: 7 additions & 0 deletions Shared/Extension/Bool.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

extension Bool {
var int: Int {
self ? 1 : 0
}
}
9 changes: 9 additions & 0 deletions Shared/Extension/Date.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

extension Date {
static func fromISOString(_ string: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssX"
return dateFormatter.date(from: string)
}
}
12 changes: 12 additions & 0 deletions Shared/Extension/Dictionary.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

extension Dictionary {
func merge(dict: [Key: Value]) -> [Key: Value] {
var mutableCopy = self
for (key, value) in dict {
// If both dictionaries have a value for same key, the value of the other dictionary is used.
mutableCopy[key] = value
}
return mutableCopy
}
}
21 changes: 21 additions & 0 deletions Shared/Extension/Int.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation
// import UIKit

extension Int {
var readingTime: String {
let date = Date(timeIntervalSince1970: TimeInterval(self * 60))
let dayTimePeriodFormatter = DateFormatter()
dayTimePeriodFormatter.timeZone = TimeZone(secondsFromGMT: 0)
dayTimePeriodFormatter.dateFormat = "HH:mm:ss"

return dayTimePeriodFormatter.string(from: date as Date)
}

var rgb: CGFloat {
CGFloat(self) / 255.0
}

var bool: Bool {
self == 1
}
}
12 changes: 12 additions & 0 deletions Shared/Extension/SKProduct.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation
import StoreKit

extension SKProduct {
var title: String {
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.locale = priceLocale

return "\(localizedTitle) \(formatter.string(from: price)!)"
}
}
Loading

0 comments on commit d668d17

Please sign in to comment.