-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Momo Ozawa
committed
May 13, 2024
1 parent
d7cd172
commit c5eedce
Showing
8 changed files
with
487 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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 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
51 changes: 51 additions & 0 deletions
51
WordPress/Classes/Services/In-App Update/InAppUpdatePresenter.swift
This file contains 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,51 @@ | ||
import Foundation | ||
import WordPressFlux | ||
|
||
protocol InAppUpdatePresenterProtocol { | ||
func showNotice() | ||
func showBlockingUpdate(using appStoreInfo: AppStoreInfo) | ||
func openAppStore() | ||
} | ||
|
||
final class InAppUpdatePresenter: InAppUpdatePresenterProtocol { | ||
func showNotice() { | ||
let notice = Notice( | ||
title: Strings.Notice.title, | ||
message: Strings.Notice.message, | ||
feedbackType: .warning, | ||
style: InAppUpdateNoticeStyle(), | ||
actionTitle: Strings.Notice.update | ||
) { [weak self] _ in | ||
self?.openAppStore() | ||
} | ||
ActionDispatcher.dispatch(NoticeAction.post(notice)) | ||
// Todo: if the notice is dismissed, show notice again after a defined interval | ||
} | ||
|
||
func showBlockingUpdate(using appStoreInfo: AppStoreInfo) { | ||
guard let window = UIApplication.sharedIfAvailable()?.mainWindow, | ||
let topViewController = window.topmostPresentedViewController, | ||
!((topViewController as? UINavigationController)?.viewControllers.first is BlockingUpdateViewController) else { | ||
wpAssertionFailure("Failed to show blocking update view") | ||
return | ||
} | ||
let viewModel = BlockingUpdateViewModel(appStoreInfo: appStoreInfo) { [weak self] in | ||
self?.openAppStore() | ||
} | ||
let controller = BlockingUpdateViewController(viewModel: viewModel) | ||
let navigation = UINavigationController(rootViewController: controller) | ||
topViewController.present(navigation, animated: true) | ||
} | ||
|
||
func openAppStore() { | ||
// Todo | ||
} | ||
} | ||
|
||
private enum Strings { | ||
enum Notice { | ||
static let title = NSLocalizedString("inAppUpdate.notice.title", value: "App Update Available", comment: "Title for notice displayed when there's a newer version of the app available") | ||
static let message = NSLocalizedString("inAppUpdate.notice.message", value: "To use this app, download the latest version.", comment: "Message for notice displayed when there's a newer version of the app available") | ||
static let update = NSLocalizedString("inAppUpdate.notice.update", value: "Update", comment: "Button title for notice displayed when there's a newer version of the app available") | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.