forked from signalapp/Signal-iOS
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from loki-project/session-restore
Session restore
- Loading branch information
Showing
27 changed files
with
396 additions
and
70 deletions.
There are no files selected for viewing
Submodule Pods
updated
from 80b9ef to 3a470c
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
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,84 @@ | ||
|
||
@objc(LKSessionRestorationView) | ||
final class SessionRestorationView : UIView { | ||
private let thread: TSThread | ||
@objc public var onRestore: (() -> Void)? | ||
@objc public var onDismiss: (() -> Void)? | ||
|
||
// MARK: Lifecycle | ||
@objc init(thread: TSThread) { | ||
self.thread = thread; | ||
super.init(frame: CGRect.zero) | ||
initialize() | ||
} | ||
|
||
required init?(coder: NSCoder) { fatalError("Using SessionRestorationView.init(coder:) isn't allowed. Use SessionRestorationView.init(thread:) instead.") } | ||
override init(frame: CGRect) { fatalError("Using SessionRestorationView.init(frame:) isn't allowed. Use SessionRestorationView.init(thread:) instead.") } | ||
|
||
private func initialize() { | ||
// Set up background | ||
backgroundColor = Colors.modalBackground | ||
layer.cornerRadius = Values.modalCornerRadius | ||
layer.masksToBounds = false | ||
layer.borderColor = Colors.modalBorder.cgColor | ||
layer.borderWidth = Values.borderThickness | ||
layer.shadowColor = UIColor.black.cgColor | ||
layer.shadowRadius = 8 | ||
layer.shadowOpacity = 0.64 | ||
// Set up title label | ||
let titleLabel = UILabel() | ||
titleLabel.textColor = Colors.text | ||
titleLabel.font = .boldSystemFont(ofSize: Values.mediumFontSize) | ||
titleLabel.text = NSLocalizedString("Session Out of Sync", comment: "") | ||
titleLabel.numberOfLines = 0 | ||
titleLabel.lineBreakMode = .byWordWrapping | ||
titleLabel.textAlignment = .center | ||
// Set up explanation label | ||
let explanationLabel = UILabel() | ||
explanationLabel.textColor = Colors.text | ||
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize) | ||
explanationLabel.text = NSLocalizedString("Would you like to restore your session?", comment: "") | ||
explanationLabel.numberOfLines = 0 | ||
explanationLabel.textAlignment = .center | ||
explanationLabel.lineBreakMode = .byWordWrapping | ||
// Set up restore button | ||
let restoreButton = UIButton() | ||
restoreButton.set(.height, to: Values.mediumButtonHeight) | ||
restoreButton.layer.cornerRadius = Values.modalButtonCornerRadius | ||
restoreButton.backgroundColor = Colors.accent | ||
restoreButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize) | ||
restoreButton.setTitleColor(Colors.text, for: UIControl.State.normal) | ||
restoreButton.setTitle(NSLocalizedString("Restore", comment: ""), for: UIControl.State.normal) | ||
restoreButton.addTarget(self, action: #selector(restore), for: UIControl.Event.touchUpInside) | ||
// Set up dismiss button | ||
let dismissButton = UIButton() | ||
dismissButton.set(.height, to: Values.mediumButtonHeight) | ||
dismissButton.layer.cornerRadius = Values.modalButtonCornerRadius | ||
dismissButton.backgroundColor = Colors.buttonBackground | ||
dismissButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize) | ||
dismissButton.setTitleColor(Colors.text, for: UIControl.State.normal) | ||
dismissButton.setTitle(NSLocalizedString("Dismiss", comment: ""), for: UIControl.State.normal) | ||
dismissButton.addTarget(self, action: #selector(dismiss), for: UIControl.Event.touchUpInside) | ||
// Set up button stack view | ||
let buttonStackView = UIStackView(arrangedSubviews: [ dismissButton, restoreButton ]) | ||
buttonStackView.axis = .horizontal | ||
buttonStackView.spacing = Values.mediumSpacing | ||
buttonStackView.distribution = .fillEqually | ||
// Set up main stack view | ||
let mainStackView = UIStackView(arrangedSubviews: [ titleLabel, explanationLabel, buttonStackView ]) | ||
mainStackView.axis = .vertical | ||
mainStackView.spacing = Values.smallSpacing | ||
addSubview(mainStackView) | ||
mainStackView.pin(to: self, withInset: Values.mediumSpacing) | ||
// Update explanation label if possible | ||
if let contactID = thread.contactIdentifier() { | ||
let displayName = DisplayNameUtilities.getPrivateChatDisplayName(for: contactID) ?? contactID | ||
explanationLabel.text = String(format: NSLocalizedString("Would you like to restore your session with %@?", comment: ""), displayName) | ||
} | ||
} | ||
|
||
// MARK: Interaction | ||
@objc private func restore() { onRestore?() } | ||
|
||
@objc private func dismiss() { onDismiss?() } | ||
} |
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.