Open poller to any action. Drop the fallback response as it will be taken care of by openPage handler.
This commit is contained in:
parent
adc15bd6d8
commit
22ad11840a
@ -14,14 +14,37 @@ public class PollingBehaviorModel: PageBehaviorModelProtocol {
|
||||
public var shouldAllowMultipleInstances: Bool { true }
|
||||
|
||||
public let refreshInterval: TimeInterval
|
||||
public let refreshAction: ActionOpenPageModel
|
||||
public let refreshAction: ActionModelProtocol
|
||||
|
||||
@DecodableDefault.False public var runWhileHidden: Bool
|
||||
@DecodableDefault.False public var refreshOnFirstLoad: Bool
|
||||
@DecodableDefault.False public var refreshOnShown: Bool
|
||||
|
||||
@DecodableDefault.False public var alwaysUseFallbackResponse: Bool
|
||||
public let fallbackResponse: JSONValueDictionary?
|
||||
public var runWhileHidden: Bool
|
||||
public var refreshOnFirstLoad: Bool
|
||||
public var refreshOnShown: Bool
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case refreshInterval
|
||||
case refreshAction
|
||||
case runWhileHidden
|
||||
case refreshOnFirstLoad
|
||||
case refreshOnShown
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
refreshInterval = try typeContainer.decode(TimeInterval.self, forKey: .refreshInterval)
|
||||
refreshAction = try typeContainer.decodeModel(codingKey: .refreshAction)
|
||||
runWhileHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .runWhileHidden) ?? false
|
||||
refreshOnFirstLoad = try typeContainer.decodeIfPresent(Bool.self, forKey: .refreshOnFirstLoad) ?? false
|
||||
refreshOnShown = try typeContainer.decodeIfPresent(Bool.self, forKey: .refreshOnShown) ?? false
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(refreshInterval, forKey: .refreshInterval)
|
||||
try container.encode(refreshAction, forKey: .refreshAction)
|
||||
try container.encode(runWhileHidden, forKey: .runWhileHidden)
|
||||
try container.encode(refreshOnFirstLoad, forKey: .refreshOnFirstLoad)
|
||||
try container.encode(refreshOnShown, forKey: .refreshOnShown)
|
||||
}
|
||||
}
|
||||
|
||||
public class PollingBehavior: NSObject, PageVisibilityBehavior {
|
||||
@ -58,8 +81,8 @@ public class PollingBehavior: NSObject, PageVisibilityBehavior {
|
||||
pollTimer?.cancel()
|
||||
}
|
||||
|
||||
func resumePollingTimer(withRemainingTime timeRemaining: TimeInterval, refreshAction: ActionOpenPageModel, interval: TimeInterval) {
|
||||
let delegateObject = DelegateObject.create(withDelegateForAll: self)
|
||||
func resumePollingTimer(withRemainingTime timeRemaining: TimeInterval, refreshAction: ActionModelProtocol, interval: TimeInterval) {
|
||||
let delegateObject = delegateObject
|
||||
pollTimer?.cancel()
|
||||
pollTimer = DispatchSource.makeTimerSource()
|
||||
pollTimer?.schedule(deadline: .now() + timeRemaining, repeating: interval)
|
||||
@ -74,16 +97,4 @@ public class PollingBehavior: NSObject, PageVisibilityBehavior {
|
||||
deinit {
|
||||
pollTimer?.cancel()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension PollingBehavior: MVMCoreLoadDelegateProtocol {
|
||||
|
||||
public func loadFinished(_ loadObject: MVMCoreLoadObject?, loadedViewController: (UIViewController & MVMCoreViewControllerProtocol)?, error: MVMCoreErrorObject?) {
|
||||
|
||||
if error != nil {
|
||||
// Apply the default response.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user