Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #657 from razeware/development
Browse files Browse the repository at this point in the history
emitron-ios-1.0.9-s🐼rels-paper
  • Loading branch information
Jessy Catterwaul authored Feb 11, 2022
2 parents cc5dd66 + 171436d commit 34f288e
Show file tree
Hide file tree
Showing 273 changed files with 1,906 additions and 1,685 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DerivedData/
*.perspectivev3
!default.perspectivev3
xcuserdata/
.DS_Store

## Other
*.moved-aside
Expand Down
42 changes: 21 additions & 21 deletions Emitron/Emitron.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
"repositoryURL": "https://github.com/groue/GRDB.swift.git",
"state": {
"branch": null,
"revision": "32b2923e890df320906e64cbd0faca22a8bfda14",
"version": "5.12.0"
"revision": "dfca044433050bb3e297761bf827e01ef376f5d9",
"version": "5.18.0"
}
},
{
"package": "KeychainSwift",
"repositoryURL": "https://github.com/evgenyneu/keychain-swift",
"state": {
"branch": null,
"revision": "96fb84f45a96630e7583903bd7e08cf095c7a7ef",
"version": "19.0.0"
"revision": "d108a1fa6189e661f91560548ef48651ed8d93b9",
"version": "20.0.0"
}
},
{
"package": "Kingfisher",
"repositoryURL": "https://github.com/onevcat/Kingfisher",
"state": {
"branch": null,
"revision": "318e319998bf555c3e914d5c3adb6da05af86a32",
"version": "7.1.1"
"revision": "0c02c46cfdc0656ce74fd0963a75e5000a0b7f23",
"version": "7.1.2"
}
},
{
Expand Down
39 changes: 23 additions & 16 deletions Emitron/Emitron/EmitronApp.swift → Emitron/Emitron/App.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Razeware LLC
// Copyright (c) 2022 Razeware LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -31,10 +31,8 @@ import SwiftUI
import GRDB

@main
struct EmitronApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

typealias EmitronObjects = (
struct App {
typealias Objects = (
persistenceStore: PersistenceStore,
guardpost: Guardpost,
sessionController: SessionController,
Expand All @@ -43,7 +41,8 @@ struct EmitronApp: App {
dataManager: DataManager,
messageBus: MessageBus
)


@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
private var persistenceStore: PersistenceStore
private var guardpost: Guardpost
private var dataManager: DataManager
Expand All @@ -54,9 +53,8 @@ struct EmitronApp: App {
private var iconManager: IconManager

init() {

// setup objects
let emitronObjects = EmitronApp.emitronObjects()
let emitronObjects = App.objects
persistenceStore = emitronObjects.persistenceStore
guardpost = emitronObjects.guardpost
dataManager = emitronObjects.dataManager
Expand All @@ -78,7 +76,10 @@ struct EmitronApp: App {
// additional setup
setupAppReview()
}
}

// MARK: - SwiftUI.App
extension App: SwiftUI.App {
var body: some Scene {
WindowGroup {
ZStack {
Expand All @@ -97,8 +98,11 @@ struct EmitronApp: App {
}
}
}
}

static func emitronObjects() -> EmitronObjects {
// MARK: - internal
extension App {
static var objects: Objects {
// Initialise the database
// swiftlint:disable:next force_try
let databaseURL = try! FileManager.default
Expand All @@ -117,7 +121,7 @@ struct EmitronApp: App {
let messageBus = MessageBus()
let dataManager = DataManager(sessionController: sessionController, persistenceStore: persistenceStore, downloadService: downloadService, messageBus: messageBus, settingsManager: settingsManager)

return EmitronObjects(
return Objects(
persistenceStore: persistenceStore,
guardpost: guardpost,
sessionController: sessionController,
Expand All @@ -127,8 +131,11 @@ struct EmitronApp: App {
messageBus: messageBus
)
}
}

private mutating func startServices() {
// MARK: - private
private extension App {
mutating func startServices() {
// guardpost
guardpost = Guardpost(baseURL: "https://accounts.raywenderlich.com",
urlScheme: "com.razeware.emitron://",
Expand Down Expand Up @@ -163,7 +170,7 @@ struct EmitronApp: App {
downloadService.startProcessing()
}

private func customizeNavigationBar() {
func customizeNavigationBar() {
UINavigationBar.appearance().backgroundColor = .backgroundColor

UINavigationBar.appearance().largeTitleTextAttributes = [
Expand All @@ -176,21 +183,21 @@ struct EmitronApp: App {
]
}

private func customizeTableView() {
func customizeTableView() {
UITableView.appearance().separatorColor = .clear
UITableViewCell.appearance().backgroundColor = .backgroundColor
UITableViewCell.appearance().selectionStyle = .none

UITableView.appearance().backgroundColor = .backgroundColor
}

private func customizeControls() {
func customizeControls() {
UISwitch.appearance().onTintColor = .accent
}

private func setupAppReview() {
func setupAppReview() {
if NSUbiquitousKeyValueStore.default.object(forKey: LookupKey.requestReview) == nil {
NSUbiquitousKeyValueStore.default.set(Date().timeIntervalSince1970, forKey: LookupKey.requestReview)
NSUbiquitousKeyValueStore.default.set(Date.now.timeIntervalSince1970, forKey: LookupKey.requestReview)
}
}
}
2 changes: 1 addition & 1 deletion Emitron/Emitron/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 Razeware LLC
// Copyright (c) 2022 Razeware LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Emitron/Emitron/Combine/PublishedPrePostFacto.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Razeware LLC
// Copyright (c) 2022 Razeware LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Emitron/Emitron/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 Razeware LLC
// Copyright (c) 2022 Razeware LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Emitron/Emitron/Configuration/secrets.template.xcconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 Razeware LLC
// Copyright (c) 2022 Razeware LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 2 additions & 3 deletions Emitron/Emitron/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 Razeware LLC
// Copyright (c) 2022 Razeware LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -67,7 +67,6 @@ extension String {
static let progressRemovedError = "There was a problem removing progress."
static let progressMarkedAsCompleteError = "There was a problem marking content as complete."

static let downloadRequestedSuccessfully = "Download enqueued."
static let downloadRequestedButQueueInactive = "Download will begin when WiFi available."
static let downloadNotPermitted = "Download not permitted."
static let downloadContentNotFound = "Invalid download request."
Expand Down Expand Up @@ -101,7 +100,7 @@ extension String {

// MARK: Settings screens
static let settingsPlaybackSpeedLabel = "Video Playback Speed"
static let settingsWifiOnlyDownloadsLabel = "Downloads (WiFi only)"
static let settingsAllowDownloadsOverCellularLabel = "Allow Downloads Over Cellular"
static let settingsDownloadQualityLabel = "Downloads Quality"
static let settingsClosedCaptionOnLabel = "Subtitles"
}
Expand Down
28 changes: 14 additions & 14 deletions Emitron/Emitron/Data Synchronisation/ProgressEngine.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Razeware LLC
// Copyright (c) 2022 Razeware LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -95,14 +95,14 @@ final class ProgressEngine {
}
}

func updateProgress(for contentId: Int, progress: Int) -> Future<Progression, ProgressEngineError> {
let progression = updateCacheWithProgress(for: contentId, progress: progress)
func updateProgress(for contentID: Int, progress: Int) -> Future<Progression, ProgressEngineError> {
let progression = updateCacheWithProgress(for: contentID, progress: progress)

switch mode {
case .offline:
do {
try syncAction?.updateProgress(for: contentId, progress: progress)
try syncAction?.recordWatchStats(for: contentId, secondsWatched: .videoPlaybackProgressTrackingInterval)
try syncAction?.updateProgress(for: contentID, progress: progress)
try syncAction?.recordWatchStats(for: contentID, secondsWatched: .videoPlaybackProgressTrackingInterval)

return Future { promise in
promise(.success(progression))
Expand All @@ -117,7 +117,7 @@ final class ProgressEngine {
return Future { promise in
// Don't bother trying if the playback token is empty.
guard let playbackToken = self.playbackToken else { return }
self.contentsService.reportPlaybackUsage(for: contentId, progress: progress, playbackToken: playbackToken) { [weak self] response in
self.contentsService.reportPlaybackUsage(for: contentID, progress: progress, playbackToken: playbackToken) { [weak self] response in
guard let self = self else { return promise(.failure(.notImplemented)) }
switch response {
case .failure(let error):
Expand All @@ -131,7 +131,7 @@ final class ProgressEngine {
// Update the cache and return the updated progression
self.repository.apply(update: cacheUpdate)
// Do we need to update the parent?
if let parentContent = self.repository.parentContent(for: contentId),
if let parentContent = self.repository.parentContent(for: contentID),
let childProgressUpdate = self.repository.childProgress(for: parentContent.id),
var existingProgression = self.repository.progression(for: parentContent.id) {
existingProgression.progress = childProgressUpdate.completed
Expand All @@ -155,21 +155,21 @@ final class ProgressEngine {
}
}

@discardableResult private func updateCacheWithProgress(for contentId: Int, progress: Int, target: Int? = nil) -> Progression {
let content = repository.content(for: contentId)
@discardableResult private func updateCacheWithProgress(for contentID: Int, progress: Int, target: Int? = nil) -> Progression {
let content = repository.content(for: contentID)
let progression: Progression

if var existingProgression = repository.progression(for: contentId) {
if var existingProgression = repository.progression(for: contentID) {
existingProgression.progress = progress
progression = existingProgression
} else {
progression = Progression(
id: -1,
target: target ?? content?.duration ?? 0,
progress: progress,
createdAt: Date(),
updatedAt: Date(),
contentId: contentId
createdAt: .now,
updatedAt: .now,
contentID: contentID
)
}

Expand All @@ -178,7 +178,7 @@ final class ProgressEngine {

// See whether we need to update parent content
if progression.finished,
let parentContent = repository.parentContent(for: contentId),
let parentContent = repository.parentContent(for: contentID),
let childProgress = repository.childProgress(for: parentContent.id) {
updateCacheWithProgress(for: parentContent.id, progress: childProgress.completed, target: childProgress.total)
}
Expand Down
14 changes: 7 additions & 7 deletions Emitron/Emitron/Data Synchronisation/SyncAction.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Razeware LLC
// Copyright (c) 2022 Razeware LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -27,12 +27,12 @@
// THE SOFTWARE.

protocol SyncAction: AnyObject {
func createBookmark(for contentId: Int) throws
func deleteBookmark(for contentId: Int) throws
func createBookmark(for contentID: Int) throws
func deleteBookmark(for contentID: Int) throws

func markContentAsComplete(contentId: Int) throws
func removeProgress(for contentId: Int) throws
func updateProgress(for contentId: Int, progress: Int) throws
func markContentAsComplete(contentID: Int) throws
func removeProgress(for contentID: Int) throws
func updateProgress(for contentID: Int, progress: Int) throws

func recordWatchStats(for contentId: Int, secondsWatched: Int) throws
func recordWatchStats(for contentID: Int, secondsWatched: Int) throws
}
Loading

0 comments on commit 34f288e

Please sign in to comment.