Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions WordPress/Classes/Stores/StatsWidgetsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ 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)
WidgetCenter.shared.reloadTodayTimelines()
}

if let newAllTimeData = refreshStats(type: HomeWidgetAllTimeData.self) {
HomeWidgetAllTimeData.write(items: newAllTimeData)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.allTimeKind)
WidgetCenter.shared.reloadAllTimeTimelines()
}

if let newThisWeekData = refreshStats(type: HomeWidgetThisWeekData.self) {
HomeWidgetThisWeekData.write(items: newThisWeekData)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.thisWeekKind)
WidgetCenter.shared.reloadThisWeekTimelines()
}
}

Expand All @@ -43,20 +42,19 @@ class StatsWidgetsStore {
if !HomeWidgetTodayData.cacheDataExists() {
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)
WidgetCenter.shared.reloadTodayTimelines()
}

if !HomeWidgetThisWeekData.cacheDataExists() {
DDLogInfo("StatsWidgets: Writing initialization data into HomeWidgetThisWeekData.plist")
HomeWidgetThisWeekData.write(items: initializeHomeWidgetData(type: HomeWidgetThisWeekData.self))
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.thisWeekKind)
WidgetCenter.shared.reloadThisWeekTimelines()
}

if !HomeWidgetAllTimeData.cacheDataExists() {
DDLogInfo("StatsWidgets: Writing initialization data into HomeWidgetAllTimeData.plist")
HomeWidgetAllTimeData.write(items: initializeHomeWidgetData(type: HomeWidgetAllTimeData.self))
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.allTimeKind)
WidgetCenter.shared.reloadAllTimeTimelines()
}
}

Expand All @@ -82,10 +80,11 @@ class StatsWidgetsStore {
T.write(items: homeWidgetCache)
return
}
var widgetKind = ""
if widgetType == HomeWidgetTodayData.self, let stats = stats as? TodayWidgetStats {

widgetKind = AppConfiguration.Widget.Stats.todayKind
var widgetReload: (() -> ())?

if widgetType == HomeWidgetTodayData.self, let stats = stats as? TodayWidgetStats {
widgetReload = WidgetCenter.shared.reloadTodayTimelines

homeWidgetCache[siteID.intValue] = HomeWidgetTodayData(siteID: siteID.intValue,
siteName: blog.title ?? oldData.siteName,
Expand All @@ -96,7 +95,7 @@ class StatsWidgetsStore {


} else if widgetType == HomeWidgetAllTimeData.self, let stats = stats as? AllTimeWidgetStats {
widgetKind = AppConfiguration.Widget.Stats.allTimeKind
widgetReload = WidgetCenter.shared.reloadAllTimeTimelines

homeWidgetCache[siteID.intValue] = HomeWidgetAllTimeData(siteID: siteID.intValue,
siteName: blog.title ?? oldData.siteName,
Expand All @@ -106,6 +105,7 @@ class StatsWidgetsStore {
stats: stats) as? T

} else if widgetType == HomeWidgetThisWeekData.self, let stats = stats as? ThisWeekWidgetStats {
widgetReload = WidgetCenter.shared.reloadThisWeekTimelines

homeWidgetCache[siteID.intValue] = HomeWidgetThisWeekData(siteID: siteID.intValue,
siteName: blog.title ?? oldData.siteName,
Expand All @@ -116,10 +116,7 @@ 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)
}
widgetReload?()
}
}

Expand Down Expand Up @@ -250,7 +247,7 @@ extension StatsWidgetsStore {
let stats = ThisWeekWidgetStats(days: ThisWeekWidgetStats.daysFrom(summaryData: summaryData))
StoreContainer.shared.statsWidgets.storeHomeWidgetData(widgetType: HomeWidgetThisWeekData.self, stats: stats)
case .week:
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.thisWeekKind)
WidgetCenter.shared.reloadThisWeekTimelines()
default:
break
}
Expand Down Expand Up @@ -278,10 +275,9 @@ private extension StatsWidgetsStore {
HomeWidgetAllTimeData.delete()

userDefaults?.setValue(nil, forKey: AppConfiguration.Widget.Stats.userDefaultsSiteIdKey)
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)
WidgetCenter.shared.reloadTodayTimelines()
WidgetCenter.shared.reloadThisWeekTimelines()
WidgetCenter.shared.reloadAllTimeTimelines()
}

/// Observes WPSigninDidFinishNotification and wordpressLoginFinishedJetpackLogin notifications and initializes the widget.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Foundation
import WidgetKit

extension WidgetCenter {
func reloadTodayTimelines() {
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.todayKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.lockScreenTodayViewsKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.lockScreenTodayLikesCommentsKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.lockScreenTodayViewsVisitorsKind)
}

func reloadThisWeekTimelines() {
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.thisWeekKind)
}

func reloadAllTimeTimelines() {
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.allTimeKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.lockScreenAllTimeViewsKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.lockScreenAllTimeViewsVisitorsKind)
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.lockScreenAllTimePostsBestViewsKind)
}
}
14 changes: 14 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@
0148CC2B2859C87000CF5D96 /* BlogServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0148CC2A2859C87000CF5D96 /* BlogServiceMock.swift */; };
014ACD142A1E5034008A706C /* WebKitViewController+SandboxStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014ACD132A1E5033008A706C /* WebKitViewController+SandboxStore.swift */; };
014ACD152A1E5034008A706C /* WebKitViewController+SandboxStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014ACD132A1E5033008A706C /* WebKitViewController+SandboxStore.swift */; };
01545D102AA9E6770015DD3A /* WidgetCenter+JetpackWidgets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01545D0F2AA9E6770015DD3A /* WidgetCenter+JetpackWidgets.swift */; };
01545D112AA9E6770015DD3A /* WidgetCenter+JetpackWidgets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01545D0F2AA9E6770015DD3A /* WidgetCenter+JetpackWidgets.swift */; };
015BA4EB29A788A300920F4B /* StatsTotalInsightsCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015BA4EA29A788A300920F4B /* StatsTotalInsightsCellTests.swift */; };
018635842A8109DE00915532 /* SupportChatBotViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 018635832A8109DE00915532 /* SupportChatBotViewController.swift */; };
018635852A8109DE00915532 /* SupportChatBotViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 018635832A8109DE00915532 /* SupportChatBotViewController.swift */; };
Expand Down Expand Up @@ -5941,6 +5943,7 @@
0148CC282859127F00CF5D96 /* StatsWidgetsStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsWidgetsStoreTests.swift; sourceTree = "<group>"; };
0148CC2A2859C87000CF5D96 /* BlogServiceMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlogServiceMock.swift; sourceTree = "<group>"; };
014ACD132A1E5033008A706C /* WebKitViewController+SandboxStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WebKitViewController+SandboxStore.swift"; sourceTree = "<group>"; };
01545D0F2AA9E6770015DD3A /* WidgetCenter+JetpackWidgets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WidgetCenter+JetpackWidgets.swift"; sourceTree = "<group>"; };
015BA4EA29A788A300920F4B /* StatsTotalInsightsCellTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsTotalInsightsCellTests.swift; sourceTree = "<group>"; };
018635832A8109DE00915532 /* SupportChatBotViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportChatBotViewController.swift; sourceTree = "<group>"; };
018635862A8109F900915532 /* SupportChatBotViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportChatBotViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9891,6 +9894,14 @@
path = Support;
sourceTree = "<group>";
};
01545D0E2AA9E65C0015DD3A /* Widgets */ = {
isa = PBXGroup;
children = (
01545D0F2AA9E6770015DD3A /* WidgetCenter+JetpackWidgets.swift */,
);
path = Widgets;
sourceTree = "<group>";
};
018635822A81098300915532 /* SupportChatBot */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -13654,6 +13665,7 @@
987E79C9261F8857000192B7 /* User Profile Sheet */,
031662E60FFB14C60045D052 /* Views */,
3F662C4824DC9F8300CAEA95 /* WhatsNew */,
01545D0E2AA9E65C0015DD3A /* Widgets */,
D86572182186C36E0023A99C /* Wizards */,
);
path = ViewRelated;
Expand Down Expand Up @@ -21532,6 +21544,7 @@
982DDF94263238A6002B3904 /* LikeUserPreferredBlog+CoreDataClass.swift in Sources */,
F5844B6B235EAF3D007C6557 /* PartScreenPresentationController.swift in Sources */,
E6805D311DCD399600168E4F /* WPRichTextImage.swift in Sources */,
01545D102AA9E6770015DD3A /* WidgetCenter+JetpackWidgets.swift in Sources */,
7E4123C120F4097B00DF8486 /* FormattableContentRange.swift in Sources */,
08D978581CD2AF7D0054F19A /* MenuItemSourceHeaderView.m in Sources */,
011F52C82A16551A00B04114 /* FreeToPaidPlansCoordinator.swift in Sources */,
Expand Down Expand Up @@ -25363,6 +25376,7 @@
FABB248E2602FC2C00C8785C /* AztecAttachmentDelegate.swift in Sources */,
803DE81428FFAE36007D4E9C /* RemoteConfigStore.swift in Sources */,
086C117D2A2F6451004A3821 /* CompliancePopover.swift in Sources */,
01545D112AA9E6770015DD3A /* WidgetCenter+JetpackWidgets.swift in Sources */,
FA98A2512833F1DC003B9233 /* QuickStartChecklistConfigurable.swift in Sources */,
931F312D2714302A0075433B /* PublicizeServicesState.swift in Sources */,
FABB24902602FC2C00C8785C /* StatsPeriodAsyncOperation.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct LockScreenAllTimePostsBestViewsStatWidgetConfig: LockScreenStatsWidgetCon

var viewProvider: ViewProvider<HomeWidgetAllTimeData> {
LockScreenMultiStatWidgetViewProvider<HomeWidgetAllTimeData>(
widgetKind: .today,
widgetKind: .allTime,
topTitle: LocalizableStrings.postsTitle,
topValue: \.stats.posts,
bottomTitle: LocalizableStrings.bestViewsShortTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct LockScreenAllTimeViewsVisitorsStatWidgetConfig: LockScreenStatsWidgetConf

var viewProvider: ViewProvider<HomeWidgetAllTimeData> {
LockScreenMultiStatWidgetViewProvider<HomeWidgetAllTimeData>(
widgetKind: .today,
widgetKind: .allTime,
topTitle: LocalizableStrings.viewsTitle,
topValue: \.stats.views,
bottomTitle: LocalizableStrings.visitorsTitle,
Expand Down