-
Notifications
You must be signed in to change notification settings - Fork 25
/
SuggestedSites.swift
46 lines (40 loc) · 1.55 KB
/
SuggestedSites.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import UIKit
import Shared
open class SuggestedSite: Site {
override open var tileURL: URL {
return URL(string: url as String) ?? URL(string: "about:blank")!
}
let trackingId: Int
init(data: SuggestedSiteData) {
self.trackingId = data.trackingId
super.init(url: data.url, title: data.title, bookmarked: nil)
self.guid = "default" + data.title // A guid is required in the case the site might become a pinned site
}
}
public let SuggestedSites = SuggestedSitesCursor()
open class SuggestedSitesCursor: ArrayCursor<SuggestedSite> {
fileprivate init() {
let locale = Locale.current
let sites = DefaultSuggestedSites.sites[locale.identifier] ??
DefaultSuggestedSites.sites["default"]! as [SuggestedSiteData]
let tiles = sites.map({ data -> SuggestedSite in
var site = data
if let domainMap = DefaultSuggestedSites.urlMap[data.url], let localizedURL = domainMap[locale.identifier] {
site.url = localizedURL
}
return SuggestedSite(data: site)
})
super.init(data: tiles, status: .success, statusMessage: "Loaded")
}
}
public struct SuggestedSiteData {
var url: String
var bgColor: String
var imageUrl: String
var faviconUrl: String
var trackingId: Int
var title: String
}