-
Notifications
You must be signed in to change notification settings - Fork 2
feat: redesign headlines widget v61 + OS widget #546
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
Open
jvsena42
wants to merge
12
commits into
feat/price-widget-v61
Choose a base branch
from
feat/headlines-v61
base: feat/price-widget-v61
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d60c84c
feat: migrate news widget to design v61 and port OS widget
jvsena42 ab5b8d5
fix: push source text to bottom
jvsena42 66f82ff
refactor: extract articles url to a shared files
jvsena42 78b4dcd
feat: open browser on widget click
jvsena42 12fe6e6
doc: changelog entry
jvsena42 667e544
fix: small and medium sizes displaying different random url
jvsena42 40b0ad7
chore: remove schedule file
jvsena42 2e3f81c
fix: replace onAppear with task
jvsena42 a25a221
fix: use stable dafe format identifier
jvsena42 779e215
fix: solve conflicts and apply downstream changes
jvsena42 ddfd42b
fix: display checkmark for title
jvsena42 955e293
Merge remote-tracking branch 'origin/feat/price-widget-v61' into feat…
jvsena42 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
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
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
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
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,40 @@ | ||
| import Foundation | ||
|
|
||
| /// Persistable representation of a news article shared between the main app and the widget extension via App Group. | ||
| struct CachedNewsArticle: Codable, Equatable { | ||
| let title: String | ||
| let publisher: String | ||
| let link: String | ||
| let publishedDate: String | ||
| let publishedEpoch: Int | ||
| } | ||
|
|
||
| /// Cache reader/writer used by both the main app and the widget extension. | ||
| enum NewsWidgetCache { | ||
| static let appGroupSuiteName = "group.bitkit" | ||
| private static let topArticlesKey = "news_widget_top_articles_v1" | ||
| private static let legacyStandardKey = "news_widget_cache" | ||
|
|
||
| private static func defaults() -> UserDefaults { | ||
| UserDefaults(suiteName: appGroupSuiteName) ?? .standard | ||
| } | ||
|
|
||
| static func saveTop(_ articles: [CachedNewsArticle]) { | ||
| guard let encoded = try? JSONEncoder().encode(articles) else { return } | ||
| defaults().set(encoded, forKey: topArticlesKey) | ||
| } | ||
|
|
||
| static func loadTop() -> [CachedNewsArticle] { | ||
| guard let data = defaults().data(forKey: topArticlesKey), | ||
| let decoded = try? JSONDecoder().decode([CachedNewsArticle].self, from: data) | ||
| else { | ||
| return [] | ||
| } | ||
| return decoded | ||
| } | ||
|
|
||
| /// One-time cleanup of the pre-App-Group single-`WidgetData` cache. | ||
| static func legacyDropStandardSuiteCache() { | ||
| UserDefaults.standard.removeObject(forKey: legacyStandardKey) | ||
| } | ||
| } |
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,14 @@ | ||
| import Foundation | ||
|
|
||
| /// Options for configuring the in-app and home-screen news widgets (shared via App Group). | ||
| struct NewsWidgetOptions: Codable, Equatable { | ||
| var showDate: Bool = true | ||
| var showTitle: Bool = true | ||
| var showSource: Bool = true | ||
|
|
||
| init(showDate: Bool = true, showTitle: Bool = true, showSource: Bool = true) { | ||
| self.showDate = showDate | ||
| self.showTitle = showTitle | ||
| self.showSource = showSource | ||
| } | ||
| } |
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
36 changes: 36 additions & 0 deletions
36
Bitkit/Services/Widgets/NewsHomeScreenWidgetOptionsStore.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,36 @@ | ||
| import Foundation | ||
| import WidgetKit | ||
|
|
||
| /// Mirrors in-app news widget options into the App Group so the WidgetKit extension can read them, | ||
| /// and centralizes the WidgetKit reload trigger for the news home-screen widget. | ||
| enum NewsHomeScreenWidgetOptionsStore { | ||
| /// WidgetKit `kind` for the home-screen news widget (must match `BitkitNewsWidget`). | ||
| static let newsHomeScreenWidgetKind = "BitkitNewsWidget" | ||
|
|
||
| private static let suiteName = "group.bitkit" | ||
| private static let key = "home_screen_news_widget_options_v1" | ||
|
|
||
| static func save(_ options: NewsWidgetOptions) { | ||
| guard let defaults = UserDefaults(suiteName: suiteName), | ||
| let data = try? JSONEncoder().encode(options) | ||
| else { return } | ||
| defaults.set(data, forKey: key) | ||
| } | ||
|
|
||
| static func load() -> NewsWidgetOptions { | ||
| guard let defaults = UserDefaults(suiteName: suiteName), | ||
| let data = defaults.data(forKey: key), | ||
| let options = try? JSONDecoder().decode(NewsWidgetOptions.self, from: data) | ||
| else { | ||
| return NewsWidgetOptions() | ||
| } | ||
| return options | ||
| } | ||
|
|
||
| /// Call after updating options or cache so the home-screen widget timeline refreshes. | ||
| /// No-op when running inside the widget extension itself (`appex`). | ||
| static func reloadHomeScreenWidgetIfNeeded() { | ||
| guard Bundle.main.bundleURL.pathExtension != "appex" else { return } | ||
| WidgetCenter.shared.reloadTimelines(ofKind: newsHomeScreenWidgetKind) | ||
| } | ||
| } |
Oops, something went wrong.
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.