Commit abb22295 by Demid Merzlyakov

IOS-155: control feature availability based on Premium Subscription status.

parent 04542a02
...@@ -232,7 +232,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -232,7 +232,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
case .shorts: case .shorts:
availabilityCheckers[feature] = usOnly && isPhone availabilityCheckers[feature] = usOnly && isPhone
case .airQualityIndex: case .airQualityIndex:
break availabilityCheckers[feature] = premium
case .attPrompt: case .attPrompt:
break // config only break // config only
case .nwsAlertsViaMoEngage: case .nwsAlertsViaMoEngage:
...@@ -245,6 +245,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -245,6 +245,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
break // configOnly break // configOnly
case .subscriptionForPro: case .subscriptionForPro:
availabilityCheckers[feature] = premium availabilityCheckers[feature] = premium
case .extendedDailyForecast:
availabilityCheckers[feature] = premium
case .extendedHourlyForecast:
availabilityCheckers[feature] = premium
} }
} }
......
...@@ -195,7 +195,7 @@ fileprivate extension AppFeature { ...@@ -195,7 +195,7 @@ fileprivate extension AppFeature {
return "shorts_swipe_down_nudge_enabled" return "shorts_swipe_down_nudge_enabled"
case .onboarding: case .onboarding:
return "ios_show_onboarding" return "ios_show_onboarding"
case .ads, .airQualityIndex, .minutelyForecast, .shorts, .subscription, .subscriptionForPro: case .ads, .airQualityIndex, .minutelyForecast, .shorts, .subscription, .subscriptionForPro, .extendedDailyForecast, .extendedHourlyForecast:
return nil return nil
// don't use 'default', so that we didn't add new features here in the future. // don't use 'default', so that we didn't add new features here in the future.
} }
......
...@@ -30,6 +30,8 @@ protocol ForecastTimePeriodViewDelegate: AnyObject { ...@@ -30,6 +30,8 @@ protocol ForecastTimePeriodViewDelegate: AnyObject {
class ForecastTimePeriodView: UIView { class ForecastTimePeriodView: UIView {
//Private //Private
private let storeManager = StoreManager.shared
private let featureAvailability: FeatureAvailabilityManager = FeatureAvailabilityManager.shared
private let scrollView = UIScrollView() private let scrollView = UIScrollView()
private let stackView = UIStackView() private let stackView = UIStackView()
private let graphView = GraphView(graphInsets: .init(top: 0, left: 8, bottom: 0, right: 8)) private let graphView = GraphView(graphInsets: .init(top: 0, left: 8, bottom: 0, right: 8))
...@@ -63,12 +65,22 @@ class ForecastTimePeriodView: UIView { ...@@ -63,12 +65,22 @@ class ForecastTimePeriodView: UIView {
//Public //Public
public func set(daily:[DailyWeather]? = nil, hourly:[HourlyWeather]? = nil) { public func set(daily:[DailyWeather]? = nil, hourly:[HourlyWeather]? = nil) {
if let inputDaily = daily { if let inputDaily = daily {
if featureAvailability.isAvailable(feature: .extendedDailyForecast) {
self.daily = inputDaily self.daily = inputDaily
} }
else {
self.daily = [DailyWeather](inputDaily.prefix(7))
}
}
if let inputHourly = hourly { if let inputHourly = hourly {
if featureAvailability.isAvailable(feature: .extendedHourlyForecast) {
self.hourly = inputHourly self.hourly = inputHourly
} }
else {
self.hourly = [HourlyWeather](inputHourly.prefix(24))
}
}
} }
public func set(forecastType:ForecastType, buttonType: PeriodButtonProtocol.Type) { public func set(forecastType:ForecastType, buttonType: PeriodButtonProtocol.Type) {
......
...@@ -241,7 +241,7 @@ class TodayCellFactory: CellFactory { ...@@ -241,7 +241,7 @@ class TodayCellFactory: CellFactory {
rowsToHide.insert(.alert) rowsToHide.insert(.alert)
} }
if location?.health?.airQuality == nil { if location?.health?.airQuality == nil || !featureAvailabilityManager.isAvailable(feature: .airQualityIndex) {
rowsToHide.insert(.airQuality) rowsToHide.insert(.airQuality)
} }
......
...@@ -33,16 +33,19 @@ class ForecastViewModel: ViewModelProtocol { ...@@ -33,16 +33,19 @@ class ForecastViewModel: ViewModelProtocol {
//Private //Private
private var locationManager: LocationManager private var locationManager: LocationManager
private let storeManager: StoreManager
deinit { deinit {
Settings.shared.delegate.remove(delegate: self) Settings.shared.delegate.remove(delegate: self)
self.locationManager.remove(delegate: self) self.locationManager.remove(delegate: self)
} }
public init(locationManager: LocationManager) { public init(locationManager: LocationManager, storeManager: StoreManager = StoreManager.shared) {
self.locationManager = locationManager self.locationManager = locationManager
self.storeManager = storeManager
locationManager.add(delegate: self) locationManager.add(delegate: self)
Settings.shared.delegate.add(delegate: self) Settings.shared.delegate.add(delegate: self)
self.storeManager.add(observer: self)
} }
public func updateWeather() { public func updateWeather() {
...@@ -96,3 +99,11 @@ extension ForecastViewModel: SettingsDelegate { ...@@ -96,3 +99,11 @@ extension ForecastViewModel: SettingsDelegate {
} }
} }
} }
extension ForecastViewModel: StoreManagerObserver {
func storeManagerUpdatedStatus(_ storeManager: StoreManager) {
onMain {
self.delegate?.viewModelDidChange(model: self)
}
}
}
...@@ -14,6 +14,8 @@ public enum AppFeature: String, Codable, CaseIterable { ...@@ -14,6 +14,8 @@ public enum AppFeature: String, Codable, CaseIterable {
case nwsAlertsViaMoEngage case nwsAlertsViaMoEngage
case onboarding case onboarding
case minutelyForecast case minutelyForecast
case extendedHourlyForecast
case extendedDailyForecast
case shorts case shorts
case shortsLastNudge case shortsLastNudge
/// Any kind of subscription /// Any kind of subscription
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment