Skip to content

Commit

Permalink
feat(RL-95): widget updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NoodleOfDeath committed Oct 5, 2023
1 parent 7d79bec commit 3d2535e
Show file tree
Hide file tree
Showing 15 changed files with 564 additions and 195 deletions.
4 changes: 2 additions & 2 deletions src/mobile/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ android {
applicationId "ai.readless.ReadLess"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 98
versionName "1.15.2"
versionCode 99
versionName "1.16.0"
missingDimensionStrategy "store", "play"
}

Expand Down
6 changes: 3 additions & 3 deletions src/mobile/ios/Extensions/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ extension Date {
func distanceFromNow() -> String {
let interval = Calendar.current.dateComponents([.minute, .hour, .day], from: self, to: Date())
if let day = interval.day, day > 0 {
return "\(day) day\(day == 1 ? "" : "s") ago"
return "\(day)d"
} else if let hour = interval.hour, hour > 0 {
return "\(hour) hour\(hour == 1 ? "" : "s") ago"
return "\(hour)h"
} else if let minute = interval.minute, minute > 0 {
return "\(minute) minute\(minute == 1 ? "" : "s") ago"
return "\(minute)m"
} else {
return "just now"
}
Expand Down
43 changes: 43 additions & 0 deletions src/mobile/ios/Extensions/Image.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Image.swift
// ReadLess
//
// Created by thom on 10/4/23.
//

import Foundation
import SwiftUI

public extension Image {

static func loadAsync(from string: String) async -> Image? {
guard let url = URL(string: string) else { return nil }
return await self.loadAsync(from: url)
}

static func loadAsync(from url: URL?) async -> Image? {
guard let url = url else { return nil }
let request = URLRequest(url: url)
guard let (data, _) = try? await URLSession.shared.data(for: request) else { return nil }
guard let image = UIImage(data: data) else { return nil }
return Image(uiImage: image)
}

static func load(from string: String, completion: @escaping @Sendable (_ image: Image?) -> Void) {
guard let imageUrl = URL(string: string) else { return }
return self.load(from: imageUrl, completion: completion)
}

static func load(from url: URL?, completion: @escaping @Sendable (_ image: Image?) -> Void) {
guard let url = url else {
completion(nil)
return
}
URLSession.shared.dataTask(with: url) { data, _, error in
if let data = data, let image = UIImage(data: data) {
completion(Image(uiImage: image))
}
}.resume()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,31 @@ import Foundation
import AnyCodable
#endif

public struct BulkResponse<T: Codable, M: Codable>: Codable {
public struct BulkResponse<T: Codable>: Codable {

public var count: Int
public var rows: [T]

public init(count: Int, rows: [T]) {
self.count = count
self.rows = rows
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case count
case rows
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(count, forKey: .count)
try container.encode(rows, forKey: .rows)
}
}

public struct BulkMetadataResponse<T: Codable, M: Codable>: Codable {

public var count: Int
public var rows: [T]
Expand Down
4 changes: 2 additions & 2 deletions src/mobile/ios/Models/PublicPublisherAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public struct PublicPublisherAttributes: Codable, Hashable {
public var displayName: String
public var description: String?

public var icon: String {
return "https://readless.nyc3.cdn.digitaloceanspaces.com/img/pub/\(self.name).png"
public var icon: URL {
return URL(string: "https://readless.nyc3.cdn.digitaloceanspaces.com/img/pub/\(self.name).png")!
}

public init(name: String, displayName: String, description: String? = nil) {
Expand Down
96 changes: 95 additions & 1 deletion src/mobile/ios/Models/PublicSummaryAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import SwiftUI
#if canImport(AnyCodable)
import AnyCodable
#endif
Expand Down Expand Up @@ -77,4 +78,97 @@ public struct PublicSummaryAttributes: Codable, Hashable {

}

public var MOCK_SUMMARY = PublicSummaryAttributes(id: 1, url: "https://readless.ai", title: "Summary Preview", shortSummary: "Short Summary", publisher: PublicPublisherAttributes(name: "cnn", displayName: "CNN"), category: PublicCategoryAttributes(name: "sports", displayName: "Sports", icon: "basketball"))
public class Summary {

public var root: PublicSummaryAttributes
public var id: Int
public var url: String
public var title: String
public var shortSummary: String?
public var publisher: PublicPublisherAttributes
public var category: PublicCategoryAttributes
public var imageUrl: String?
public var media: [String: String]?
public var originalDate: Date?
public var translations: [String: String]?

public var deeplink: URL {
return URL(string: "https://readless.ai/read/?s=\(id)")!
}

public var primaryImageUrl: URL? {
return URL(string: media?["imageArticle"] ?? media?["imageAi1"] ?? imageUrl ?? "")
}

public init(_ summary: PublicSummaryAttributes) {
self.root = summary
self.id = summary.id
self.url = summary.url
self.title = summary.title
self.shortSummary = summary.shortSummary
self.publisher = summary.publisher
self.category = summary.category
self.imageUrl = summary.imageUrl
self.media = summary.media
self.originalDate = summary.originalDate
self.translations = summary.translations
}

@Published public var image: Image?
@Published public var publisherIcon: Image?

public func loadImages() {
Image.load(from: primaryImageUrl) { self.image = $0 }
Image.load(from: publisher.icon) { self.publisherIcon = $0 }
}

}


public var MOCK_SUMMARY_1 = Summary(
PublicSummaryAttributes(id: 1,
url: "https://readless.ai",
title: "Summary Preview",
shortSummary: "Short Summary",
publisher: PublicPublisherAttributes(name: "cnn",
displayName: "CNN"),
category: PublicCategoryAttributes(name: "sports",
displayName: "Sports",
icon: "basketball")
))

public var MOCK_SUMMARY_2 = Summary(
PublicSummaryAttributes(id: 2,
url: "https://readless.ai",
title: "Summary Preview",
shortSummary: "Short Summary",
publisher: PublicPublisherAttributes(name: "forbes",
displayName: "Forbes"),
category: PublicCategoryAttributes(name: "politics",
displayName: "politics",
icon: "bank")
))

public var MOCK_SUMMARY_3 = Summary(
PublicSummaryAttributes(id: 3,
url: "https://readless.ai",
title: "Summary Preview",
shortSummary: "Short Summary",
publisher: PublicPublisherAttributes(name: "forbes",
displayName: "Forbes"),
category: PublicCategoryAttributes(name: "politics",
displayName: "politics",
icon: "bank")
))

public var MOCK_SUMMARY_4 = Summary(
PublicSummaryAttributes(id: 4,
url: "https://readless.ai",
title: "Summary Preview",
shortSummary: "Short Summary",
publisher: PublicPublisherAttributes(name: "forbes",
displayName: "Forbes"),
category: PublicCategoryAttributes(name: "politics",
displayName: "politics",
icon: "bank")
))
Loading

0 comments on commit 3d2535e

Please sign in to comment.