Skip to content

Commit

Permalink
iOS 16 Lock Screen Widgets: Today Views Widget (#20435)
Browse files Browse the repository at this point in the history
* Add new feature flag for lock screen widgets in Jetpack  (#20309)

* Add new feature flag for widget in lock screen

* Add new widget kind to widget configuration

* Add empty lock screen widget

* Add JETPACK_STATS_WIDGETS compilation condition

To prevent lock screen widgets from displaying on WordPress target

* Move LockScreenStatsWidgetsView to views folder group

* Revert compilation condition, change to isJetpack of AppCondiguration

* Implement lock screen widgets UI (#20312)

* Extract statsUrl from private to extension for reusable with lock screen widget

* Implement single stat view for today views widget

Add view provider for handling building view for site selected status
Add ViewModelMapper for converting viewModel from home widget data

* Update LockScreenStatsWidgetsView body to get the view from view provider

* Add mapper test to verify the viewModel converting from widget data correctly

Add mapper and viewModel to WordPress target because app extension is not able to run unitTest

* Fix getStatsURL typo

* Add localizable string for "Views Today" title (#20353)

* Add views in today localizable string for footer label

* Remove dateRange and footer, only title is enough for existing feature

* Fix home screen widget for WordPress target disappeared. (#20371)

The root cause is the WidgetBundleBuilder body doesn't allow control flow statements, move it to supportedFamilies with feature flag to keep all control logic in the same place

* Extract content logic to config from lock screen widget (#20317)

* Update title of view provider from hardcoded to pass from config

* Add lock screen stats widget config and implementation to include required information

* Pass config to LockScreenStatsWidget

Replaced the hardcoded data with config properties

* Add associated type view for other status and TODO comments

* Extract app configuration and feature flag check into config

* Create a standalone TimeLineProvider and TimelineEntry for the lock screen  (#20368)

* Add widget data and timeline entry for lock screen to separate concerns

* Add lock screen time line provider for lock screen stats widget entry

Update stats widgets service result type to consist of home widget and lock screen widget for reusable

* Update to use LockScreenSiteListProvider in LockScreenStatsWidget

Update associated type widget data to conform `LockScreenStatsWidgetData` more

Update model mapper and view provider to based on lock screen widget data

Remove unnecessary `disabled` status from `LockScreenStatsWidgetsView`

Remove unnecessary `widgetKind` parameter from `LockScreenStatsWidget`

Remove unused statsURL converter from the view model mapper

Add home widget data conform lock screen widget data extension to WordPress target for unitTest

* Extract widget load data to loader for sharing with lock screen time line provider

* Update widget reader to extract the cache read from getSnapshot

* Extract noData, noSite, loggedOut, disabled status checking logic to data reader with status callback

* Add unitTest for widget data reader

Extract cache reading to `HomeWidgetDataFileReader` for mocking the testing object

Extract app configuration is jetpack to parameter for mocking the config

* Remove multiple space lines

* Update multiple callback to Result and enum Error

* Implement view for logged-out, no-site, and no-data status (#20399)

* Add unconfigured view for lockscreen widget

* Add unconfigured view model to view provider and model mapper

* Add unconfigured view model unit test

* Add background to unconfigured view align with success status widget appearance

* Remove todo comments

* Add reload timelines for lock screen widget (#20405)

* Implement event tracking for the new lock screen widget  (#20422)

* Add event key to configuration and pass to trackers in lockscreen widget

Expand tracks for lockscreen stats entry

Add rectangular widgets count and widgets update of the new widget

* Add lockscreen_widget source to deeplink tracked

Update statsUrl to widgetUrl for separating the url from homescreen widgets

* Update unitTests

* Remove separate widget url, move widget source from widget data extension

Add widget source type, assign the type in widgetURL in the view

* Add widget url source test to verify the converting with DeepLinkSource

* Disable the feature flag (#20427)

---------

Co-authored-by: Beemo Lee <tzef8220@gmail.com>
  • Loading branch information
staskus and tzef authored Sep 4, 2023
1 parent a27f7b2 commit d45f864
Show file tree
Hide file tree
Showing 34 changed files with 1,171 additions and 124 deletions.
6 changes: 6 additions & 0 deletions WordPress/Classes/Stores/StatsWidgetsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class StatsWidgetsStore {
if let newTodayData = refreshStats(type: HomeWidgetTodayData.self) {
HomeWidgetTodayData.write(items: newTodayData)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.todayKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.lockScreenTodayViewsKind)
}

if let newAllTimeData = refreshStats(type: HomeWidgetAllTimeData.self) {
Expand All @@ -43,6 +44,7 @@ class StatsWidgetsStore {
DDLogInfo("StatsWidgets: Writing initialization data into HomeWidgetTodayData.plist")
HomeWidgetTodayData.write(items: initializeHomeWidgetData(type: HomeWidgetTodayData.self))
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.todayKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.lockScreenTodayViewsKind)
}

if !HomeWidgetThisWeekData.cacheDataExists() {
Expand Down Expand Up @@ -115,6 +117,9 @@ class StatsWidgetsStore {

T.write(items: homeWidgetCache)
WidgetCenter.shared.reloadTimelines(ofKind: widgetKind)
if widgetKind == AppConfiguration.Widget.Stats.todayKind {
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.lockScreenTodayViewsKind)
}
}
}

Expand Down Expand Up @@ -276,6 +281,7 @@ private extension StatsWidgetsStore {
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.todayKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.thisWeekKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.allTimeKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.lockScreenTodayViewsKind)
}

/// Observes WPSigninDidFinishNotification and wordpressLoginFinishedJetpackLogin notifications and initializes the widget.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import Foundation
@objc static let userDefaultsSiteIdKey = "WordPressHomeWidgetsSiteId"
@objc static let userDefaultsLoggedInKey = "WordPressHomeWidgetsLoggedIn"
@objc static let userDefaultsJetpackFeaturesDisabledKey = "WordPressJPFeaturesDisabledKey"
@objc static let lockScreenTodayViewsKind = "WordPressLockScreenWidgetTodayViews"
@objc static let todayKind = "WordPressHomeWidgetToday"
@objc static let allTimeKind = "WordPressHomeWidgetAllTime"
@objc static let thisWeekKind = "WordPressHomeWidgetThisWeek"
@objc static let lockScreenTodayViewsProperties = "WordPressLockScreenWidgetTodayViewsProperties"
@objc static let todayProperties = "WordPressHomeWidgetTodayProperties"
@objc static let allTimeProperties = "WordPressHomeWidgetAllTimeProperties"
@objc static let thisWeekProperties = "WordPressHomeWidgetThisWeekProperties"
Expand Down
7 changes: 7 additions & 0 deletions WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum FeatureFlag: Int, CaseIterable {
case homepageSettings
case unifiedPrologueCarousel
case todayWidget
case lockScreenWidget
case milestoneNotifications
case bloggingReminders
case siteIconCreator
Expand Down Expand Up @@ -68,6 +69,8 @@ enum FeatureFlag: Int, CaseIterable {
return true
case .todayWidget:
return true
case .lockScreenWidget:
return false
case .milestoneNotifications:
return true
case .bloggingReminders:
Expand Down Expand Up @@ -178,6 +181,8 @@ extension FeatureFlag {
return "Unified Prologue Carousel"
case .todayWidget:
return "iOS 14 Today Widget"
case .lockScreenWidget:
return "iOS 16 Widget in Lock Screen"
case .milestoneNotifications:
return "Milestone notifications"
case .bloggingReminders:
Expand Down Expand Up @@ -262,6 +267,8 @@ extension FeatureFlag: OverridableFlag {
return false
case .todayWidget:
return false
case .lockScreenWidget:
return false
case .weeklyRoundup:
return false
case .weeklyRoundupStaticNotification:
Expand Down
3 changes: 3 additions & 0 deletions WordPress/Classes/Utility/Universal Links/Route.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ enum DeepLinkSource: Equatable {
case banner
case email(campaign: String)
case widget
case lockScreenWidget
case inApp(presenter: UIViewController?)

init?(sourceName: String) {
Expand All @@ -102,6 +103,8 @@ enum DeepLinkSource: Equatable {
// add others in the future if necessary.
case "widget":
self = .widget
case "lockscreen_widget":
self = .lockScreenWidget
default:
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ extension DeepLinkSource {
return "email"
case .widget:
return "widget"
case .lockScreenWidget:
return "lockscreen_widget"
case .inApp:
return "internal"
}
Expand Down
2 changes: 2 additions & 0 deletions WordPress/Jetpack/WidgetConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import Foundation
@objc static let userDefaultsSiteIdKey = "JetpackHomeWidgetsSiteId"
@objc static let userDefaultsLoggedInKey = "JetpackHomeWidgetsLoggedIn"
@objc static let userDefaultsJetpackFeaturesDisabledKey = "JetpackJPFeaturesDisabledKey"
@objc static let lockScreenTodayViewsKind = "JetpackLockScreenWidgetTodayViews"
@objc static let todayKind = "JetpackHomeWidgetToday"
@objc static let allTimeKind = "JetpackHomeWidgetAllTime"
@objc static let thisWeekKind = "JetpackHomeWidgetThisWeek"
@objc static let lockScreenTodayViewsProperties = "JetpackLockScreenWidgetTodayViewsProperties"
@objc static let todayProperties = "JetpackHomeWidgetTodayProperties"
@objc static let allTimeProperties = "JetpackHomeWidgetAllTimeProperties"
@objc static let thisWeekProperties = "JetpackHomeWidgetThisWeekProperties"
Expand Down
Loading

0 comments on commit d45f864

Please sign in to comment.