mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 09:20:08 +00:00
Add widget "application start required" placeholder
This commit is contained in:
parent
9334e164b9
commit
e083dd7eff
@ -5497,3 +5497,5 @@ Any member of this group will be able to see messages in the channel.";
|
|||||||
|
|
||||||
"Channel.AboutItem" = "about";
|
"Channel.AboutItem" = "about";
|
||||||
"PeerInfo.GroupAboutItem" = "about";
|
"PeerInfo.GroupAboutItem" = "about";
|
||||||
|
|
||||||
|
"Widget.ApplicationStartRequired" = "Open the app to use the widget";
|
||||||
|
|||||||
@ -15,7 +15,7 @@ class TodayViewController: UIViewController, NCWidgetProviding {
|
|||||||
private var buildConfig: BuildConfig?
|
private var buildConfig: BuildConfig?
|
||||||
|
|
||||||
private var primaryColor: UIColor = .black
|
private var primaryColor: UIColor = .black
|
||||||
private var appLockedLabel: UILabel?
|
private var placeholderLabel: UILabel?
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@ -42,23 +42,11 @@ class TodayViewController: UIViewController, NCWidgetProviding {
|
|||||||
if let data = try? Data(contentsOf: URL(fileURLWithPath: widgetPresentationDataPath(rootPath: rootPath))), let value = try? JSONDecoder().decode(WidgetPresentationData.self, from: data) {
|
if let data = try? Data(contentsOf: URL(fileURLWithPath: widgetPresentationDataPath(rootPath: rootPath))), let value = try? JSONDecoder().decode(WidgetPresentationData.self, from: data) {
|
||||||
presentationData = value
|
presentationData = value
|
||||||
} else {
|
} else {
|
||||||
presentationData = WidgetPresentationData(applicationLockedString: "Unlock the app to use widget")
|
presentationData = WidgetPresentationData(applicationLockedString: "Unlock the app to use the widget", applicationStartRequiredString: "Open the app to use the widget")
|
||||||
}
|
}
|
||||||
|
|
||||||
let fontSize = UIFont.preferredFont(forTextStyle: .body).pointSize
|
|
||||||
|
|
||||||
if let data = try? Data(contentsOf: URL(fileURLWithPath: appLockStatePath(rootPath: rootPath))), let state = try? JSONDecoder().decode(LockState.self, from: data), isAppLocked(state: state) {
|
if let data = try? Data(contentsOf: URL(fileURLWithPath: appLockStatePath(rootPath: rootPath))), let state = try? JSONDecoder().decode(LockState.self, from: data), isAppLocked(state: state) {
|
||||||
let appLockedLabel = UILabel()
|
self.setPlaceholderText(presentationData.applicationLockedString)
|
||||||
if #available(iOSApplicationExtension 13.0, *) {
|
|
||||||
appLockedLabel.textColor = UIColor.label
|
|
||||||
} else {
|
|
||||||
appLockedLabel.textColor = self.primaryColor
|
|
||||||
}
|
|
||||||
appLockedLabel.font = UIFont.systemFont(ofSize: fontSize)
|
|
||||||
appLockedLabel.text = presentationData.applicationLockedString
|
|
||||||
appLockedLabel.sizeToFit()
|
|
||||||
self.appLockedLabel = appLockedLabel
|
|
||||||
self.view.addSubview(appLockedLabel)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,10 +58,25 @@ class TodayViewController: UIViewController, NCWidgetProviding {
|
|||||||
let dataPath = rootPath + "/widget-data"
|
let dataPath = rootPath + "/widget-data"
|
||||||
|
|
||||||
if let data = try? Data(contentsOf: URL(fileURLWithPath: dataPath)), let widgetData = try? JSONDecoder().decode(WidgetData.self, from: data) {
|
if let data = try? Data(contentsOf: URL(fileURLWithPath: dataPath)), let widgetData = try? JSONDecoder().decode(WidgetData.self, from: data) {
|
||||||
self.setWidgetData(widgetData: widgetData)
|
self.setWidgetData(widgetData: widgetData, presentationData: presentationData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func setPlaceholderText(_ text: String) {
|
||||||
|
let fontSize = UIFont.preferredFont(forTextStyle: .body).pointSize
|
||||||
|
let placeholderLabel = UILabel()
|
||||||
|
if #available(iOSApplicationExtension 13.0, *) {
|
||||||
|
placeholderLabel.textColor = UIColor.label
|
||||||
|
} else {
|
||||||
|
placeholderLabel.textColor = self.primaryColor
|
||||||
|
}
|
||||||
|
placeholderLabel.font = UIFont.systemFont(ofSize: fontSize)
|
||||||
|
placeholderLabel.text = text
|
||||||
|
placeholderLabel.sizeToFit()
|
||||||
|
self.placeholderLabel = placeholderLabel
|
||||||
|
self.view.addSubview(placeholderLabel)
|
||||||
|
}
|
||||||
|
|
||||||
func widgetPerformUpdate(completionHandler: (@escaping (NCUpdateResult) -> Void)) {
|
func widgetPerformUpdate(completionHandler: (@escaping (NCUpdateResult) -> Void)) {
|
||||||
completionHandler(.newData)
|
completionHandler(.newData)
|
||||||
}
|
}
|
||||||
@ -85,7 +88,7 @@ class TodayViewController: UIViewController, NCWidgetProviding {
|
|||||||
|
|
||||||
private var widgetData: WidgetData?
|
private var widgetData: WidgetData?
|
||||||
|
|
||||||
private func setWidgetData(widgetData: WidgetData) {
|
private func setWidgetData(widgetData: WidgetData, presentationData: WidgetPresentationData) {
|
||||||
self.widgetData = widgetData
|
self.widgetData = widgetData
|
||||||
self.peerViews.forEach {
|
self.peerViews.forEach {
|
||||||
$0.removeFromSuperview()
|
$0.removeFromSuperview()
|
||||||
@ -108,6 +111,13 @@ class TodayViewController: UIViewController, NCWidgetProviding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.peerViews.isEmpty {
|
||||||
|
self.setPlaceholderText(presentationData.applicationStartRequiredString)
|
||||||
|
} else {
|
||||||
|
self.placeholderLabel?.removeFromSuperview()
|
||||||
|
self.placeholderLabel = nil
|
||||||
|
}
|
||||||
|
|
||||||
if let size = self.validLayout {
|
if let size = self.validLayout {
|
||||||
self.updateLayout(size: size)
|
self.updateLayout(size: size)
|
||||||
}
|
}
|
||||||
@ -126,8 +136,8 @@ class TodayViewController: UIViewController, NCWidgetProviding {
|
|||||||
private func updateLayout(size: CGSize) {
|
private func updateLayout(size: CGSize) {
|
||||||
self.validLayout = size
|
self.validLayout = size
|
||||||
|
|
||||||
if let appLockedLabel = self.appLockedLabel {
|
if let placeholderLabel = self.placeholderLabel {
|
||||||
appLockedLabel.frame = CGRect(origin: CGPoint(x: floor((size.width - appLockedLabel.bounds.width) / 2.0), y: floor((size.height - appLockedLabel.bounds.height) / 2.0)), size: appLockedLabel.bounds.size)
|
placeholderLabel.frame = CGRect(origin: CGPoint(x: floor((size.width - placeholderLabel.bounds.width) / 2.0), y: floor((size.height - placeholderLabel.bounds.height) / 2.0)), size: placeholderLabel.bounds.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
let peerSize = CGSize(width: 70.0, height: 100.0)
|
let peerSize = CGSize(width: 70.0, height: 100.0)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -62,7 +62,7 @@ final class WidgetDataContext {
|
|||||||
|
|
||||||
self.widgetPresentationDataDisposable = (presentationData
|
self.widgetPresentationDataDisposable = (presentationData
|
||||||
|> map { presentationData -> WidgetPresentationData in
|
|> map { presentationData -> WidgetPresentationData in
|
||||||
return WidgetPresentationData(applicationLockedString: presentationData.strings.Widget_ApplicationLocked)
|
return WidgetPresentationData(applicationLockedString: presentationData.strings.Widget_ApplicationLocked, applicationStartRequiredString: presentationData.strings.Widget_ApplicationStartRequired)
|
||||||
}
|
}
|
||||||
|> distinctUntilChanged).start(next: { value in
|
|> distinctUntilChanged).start(next: { value in
|
||||||
let path = widgetPresentationDataPath(rootPath: basePath)
|
let path = widgetPresentationDataPath(rootPath: basePath)
|
||||||
|
|||||||
@ -32,9 +32,11 @@ public struct WidgetDataPeers: Codable, Equatable {
|
|||||||
|
|
||||||
public struct WidgetPresentationData: Codable, Equatable {
|
public struct WidgetPresentationData: Codable, Equatable {
|
||||||
public var applicationLockedString: String
|
public var applicationLockedString: String
|
||||||
|
public var applicationStartRequiredString: String
|
||||||
|
|
||||||
public init(applicationLockedString: String) {
|
public init(applicationLockedString: String, applicationStartRequiredString: String) {
|
||||||
self.applicationLockedString = applicationLockedString
|
self.applicationLockedString = applicationLockedString
|
||||||
|
self.applicationStartRequiredString = applicationStartRequiredString
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user