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 {
case .shorts:
availabilityCheckers[feature] = usOnly && isPhone
case .airQualityIndex:
break
availabilityCheckers[feature] = premium
case .attPrompt:
break // config only
case .nwsAlertsViaMoEngage:
......@@ -245,6 +245,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
break // configOnly
case .subscriptionForPro:
availabilityCheckers[feature] = premium
case .extendedDailyForecast:
availabilityCheckers[feature] = premium
case .extendedHourlyForecast:
availabilityCheckers[feature] = premium
}
}
......
......@@ -195,7 +195,7 @@ fileprivate extension AppFeature {
return "shorts_swipe_down_nudge_enabled"
case .onboarding:
return "ios_show_onboarding"
case .ads, .airQualityIndex, .minutelyForecast, .shorts, .subscription, .subscriptionForPro:
case .ads, .airQualityIndex, .minutelyForecast, .shorts, .subscription, .subscriptionForPro, .extendedDailyForecast, .extendedHourlyForecast:
return nil
// don't use 'default', so that we didn't add new features here in the future.
}
......
......@@ -30,6 +30,8 @@ protocol ForecastTimePeriodViewDelegate: AnyObject {
class ForecastTimePeriodView: UIView {
//Private
private let storeManager = StoreManager.shared
private let featureAvailability: FeatureAvailabilityManager = FeatureAvailabilityManager.shared
private let scrollView = UIScrollView()
private let stackView = UIStackView()
private let graphView = GraphView(graphInsets: .init(top: 0, left: 8, bottom: 0, right: 8))
......@@ -63,11 +65,21 @@ class ForecastTimePeriodView: UIView {
//Public
public func set(daily:[DailyWeather]? = nil, hourly:[HourlyWeather]? = nil) {
if let inputDaily = daily {
self.daily = inputDaily
if featureAvailability.isAvailable(feature: .extendedDailyForecast) {
self.daily = inputDaily
}
else {
self.daily = [DailyWeather](inputDaily.prefix(7))
}
}
if let inputHourly = hourly {
self.hourly = inputHourly
if featureAvailability.isAvailable(feature: .extendedHourlyForecast) {
self.hourly = inputHourly
}
else {
self.hourly = [HourlyWeather](inputHourly.prefix(24))
}
}
}
......
......@@ -241,7 +241,7 @@ class TodayCellFactory: CellFactory {
rowsToHide.insert(.alert)
}
if location?.health?.airQuality == nil {
if location?.health?.airQuality == nil || !featureAvailabilityManager.isAvailable(feature: .airQualityIndex) {
rowsToHide.insert(.airQuality)
}
......
......@@ -33,16 +33,19 @@ class ForecastViewModel: ViewModelProtocol {
//Private
private var locationManager: LocationManager
private let storeManager: StoreManager
deinit {
Settings.shared.delegate.remove(delegate: self)
self.locationManager.remove(delegate: self)
}
public init(locationManager: LocationManager) {
public init(locationManager: LocationManager, storeManager: StoreManager = StoreManager.shared) {
self.locationManager = locationManager
self.storeManager = storeManager
locationManager.add(delegate: self)
Settings.shared.delegate.add(delegate: self)
self.storeManager.add(observer: self)
}
public func updateWeather() {
......@@ -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 {
case nwsAlertsViaMoEngage
case onboarding
case minutelyForecast
case extendedHourlyForecast
case extendedDailyForecast
case shorts
case shortsLastNudge
/// 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