2019-09-19 04:56:43 +02:00
|
|
|
|
//
|
2019-09-23 09:29:53 +02:00
|
|
|
|
// FeedlyOperation.swift
|
2019-09-19 04:56:43 +02:00
|
|
|
|
// Account
|
|
|
|
|
//
|
|
|
|
|
// Created by Kiel Gillard on 20/9/19.
|
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
2019-11-25 08:19:33 +01:00
|
|
|
|
import RSWeb
|
2020-01-16 06:30:37 +01:00
|
|
|
|
import RSCore
|
2019-09-19 04:56:43 +02:00
|
|
|
|
|
2019-09-23 09:29:53 +02:00
|
|
|
|
protocol FeedlyOperationDelegate: class {
|
|
|
|
|
func feedlyOperation(_ operation: FeedlyOperation, didFailWith error: Error)
|
2019-09-19 04:56:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-19 23:19:06 +01:00
|
|
|
|
/// Abstract base class for Feedly sync operations.
|
|
|
|
|
///
|
|
|
|
|
/// Normally we don’t do inheritance — but in this case
|
|
|
|
|
/// it’s the best option.
|
2020-01-16 06:30:37 +01:00
|
|
|
|
class FeedlyOperation: MainThreadOperation {
|
|
|
|
|
|
2019-09-23 09:29:53 +02:00
|
|
|
|
weak var delegate: FeedlyOperationDelegate?
|
2020-01-19 23:19:06 +01:00
|
|
|
|
var downloadProgress: DownloadProgress? {
|
|
|
|
|
didSet {
|
|
|
|
|
oldValue?.completeTask()
|
|
|
|
|
downloadProgress?.addToNumberOfTasksAndRemaining(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-16 06:30:37 +01:00
|
|
|
|
|
2020-01-19 23:19:06 +01:00
|
|
|
|
// MainThreadOperation
|
2020-01-16 06:30:37 +01:00
|
|
|
|
var isCanceled = false {
|
|
|
|
|
didSet {
|
|
|
|
|
if isCanceled {
|
2020-01-19 23:19:06 +01:00
|
|
|
|
didCancel()
|
2020-01-16 06:30:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var id: Int?
|
|
|
|
|
weak var operationDelegate: MainThreadOperationDelegate?
|
|
|
|
|
var name: String?
|
2020-01-19 23:19:06 +01:00
|
|
|
|
var completionBlock: MainThreadOperation.MainThreadOperationCompletionBlock?
|
2020-01-16 06:30:37 +01:00
|
|
|
|
|
|
|
|
|
func run() {
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 04:56:43 +02:00
|
|
|
|
func didFinish() {
|
2020-01-16 06:30:37 +01:00
|
|
|
|
if !isCanceled {
|
|
|
|
|
operationDelegate?.operationDidComplete(self)
|
|
|
|
|
}
|
2020-01-20 01:55:39 +01:00
|
|
|
|
downloadProgress?.completeTask()
|
2019-09-19 04:56:43 +02:00
|
|
|
|
}
|
2020-01-19 23:19:06 +01:00
|
|
|
|
|
|
|
|
|
func didFinish(with error: Error) {
|
2019-09-23 09:29:53 +02:00
|
|
|
|
delegate?.feedlyOperation(self, didFailWith: error)
|
2019-09-19 04:56:43 +02:00
|
|
|
|
didFinish()
|
|
|
|
|
}
|
2020-01-19 23:19:06 +01:00
|
|
|
|
|
|
|
|
|
func didCancel() {
|
2020-01-20 01:55:39 +01:00
|
|
|
|
didFinish()
|
2020-01-19 23:19:06 +01:00
|
|
|
|
}
|
2019-09-19 04:56:43 +02:00
|
|
|
|
}
|