-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement lock screen widgets UI #20312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
staskus
merged 5 commits into
wordpress-mobile:feature/19411-add-lock-screen-stats-widgets
from
tzef:feature/beemotrial/lockscree-widgets-ui
Mar 16, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b67ea2a
Extract statsUrl from private to extension for reusable with lock scrβ¦
tzef 5d4fd19
Implement single stat view for today views widget
tzef b1b8e49
Update LockScreenStatsWidgetsView body to get the view from view provβ¦
tzef 4b9566f
Add mapper test to verify the viewModel converting from widget data cβ¦
tzef 831ac90
Fix getStatsURL typo
tzef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
WordPress/WordPressStatsWidgets/Extensions/HomeWidgetData+StatsURL.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import Foundation | ||
|
|
||
| extension HomeWidgetTodayData { | ||
| static let statsUrl = "https://wordpress.com/stats/day/" | ||
|
|
||
| var statsURL: URL? { | ||
| URL(string: Self.statsUrl + "\(siteID)?source=widget") | ||
| } | ||
| } | ||
|
|
||
|
|
||
| extension HomeWidgetAllTimeData { | ||
| static let statsUrl = "https://wordpress.com/stats/insights/" | ||
|
|
||
| var statsURL: URL? { | ||
| URL(string: Self.statsUrl + "\(siteID)?source=widget") | ||
| } | ||
| } | ||
|
|
||
|
|
||
| extension HomeWidgetThisWeekData { | ||
| static let statsUrl = "https://wordpress.com/stats/week/" | ||
|
|
||
| var statsURL: URL? { | ||
| URL(string: Self.statsUrl + "\(siteID)?source=widget") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
WordPress/WordPressStatsWidgets/LockScreenWidgets/Models/LockScreenSingleStatViewModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import Foundation | ||
|
|
||
| struct LockScreenSingleStatViewModel { | ||
| let siteName: String | ||
| let title: String | ||
| let value: String | ||
| let dateRange: String | ||
| let updatedTime: Date | ||
| } |
45 changes: 45 additions & 0 deletions
45
...ress/WordPressStatsWidgets/LockScreenWidgets/Models/LockScreenWidgetViewModelMapper.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import Foundation | ||
|
|
||
| struct LockScreenWidgetViewModelMapper { | ||
| let data: HomeWidgetData | ||
|
|
||
| func getLockScreenSingleStatViewModel(title: String, dateRange: String) -> LockScreenSingleStatViewModel { | ||
| LockScreenSingleStatViewModel( | ||
| siteName: getSiteName(), | ||
| title: title, | ||
| value: getViews(), | ||
| dateRange: dateRange, | ||
| updatedTime: data.date | ||
| ) | ||
| } | ||
|
|
||
| // TODO: Add `LockScreenStatsWidgetData` in creating lock screen widget provider and entry PR | ||
| // define statsURL, views, date, siteName | ||
| // HomeWidgetTodayData, HomeWidgetAllTimeData, HomeWidgetThisWeekData conform to it | ||
| // to reduce the type converting | ||
| func getStatsURL() -> URL? { | ||
| if let todayData = data as? HomeWidgetTodayData { | ||
| return todayData.statsURL | ||
| } else if let allTimeData = data as? HomeWidgetAllTimeData { | ||
| return allTimeData.statsURL | ||
| } else if let thisWeekData = data as? HomeWidgetThisWeekData { | ||
| return thisWeekData.statsURL | ||
| } else { | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| func getSiteName() -> String { | ||
| data.siteName | ||
| } | ||
|
|
||
| func getViews() -> String { | ||
| if let todayData = data as? HomeWidgetTodayData { | ||
|
staskus marked this conversation as resolved.
|
||
| return todayData.stats.views.abbreviatedString() | ||
| } else if let allTimeData = data as? HomeWidgetAllTimeData { | ||
| return allTimeData.stats.views.abbreviatedString() | ||
| } else { | ||
| return "" | ||
| } | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
...sStatsWidgets/LockScreenWidgets/ViewProvider/LockScreenSingleStatWidgetViewProvider.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import SwiftUI | ||
|
|
||
| @available(iOS 16.0, *) | ||
| struct LockScreenSingleStatWidgetViewProvider: LockScreenStatsWidgetsViewProvider { | ||
| typealias SiteSelectedView = LockScreenSingleStatView | ||
|
|
||
| func buildSiteSelectedView(_ data: HomeWidgetData) -> LockScreenSingleStatView { | ||
| let mapper = LockScreenWidgetViewModelMapper(data: data) | ||
| let viewModel = mapper.getLockScreenSingleStatViewModel( | ||
| title: LocalizableStrings.viewsTitle, | ||
| dateRange: LocalizableStrings.todayWidgetTitle | ||
| ) | ||
| return LockScreenSingleStatView(viewModel: viewModel) | ||
| } | ||
|
|
||
| func statsURL(_ data: HomeWidgetData) -> URL? { | ||
| let mapper = LockScreenWidgetViewModelMapper(data: data) | ||
| return mapper.getStatsURL() | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.