mirror of https://github.com/oxen-io/session-ios
commit
8209fa1383
@ -1 +1 @@
|
|||||||
Subproject commit 80b9ef94d107a4c2794164537da30eb4482af49a
|
Subproject commit 3a470c921a599097807df0cdbff4b2f238c91f37
|
@ -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?() }
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
#import "LKFriendRequestMessage.h"
|
||||||
|
|
||||||
|
NS_SWIFT_NAME(SessionRestoreMessage)
|
||||||
|
@interface LKSessionRestoreMessage : LKFriendRequestMessage
|
||||||
|
|
||||||
|
- (instancetype)initWithThread:(TSThread *)thread;
|
||||||
|
|
||||||
|
@end
|
@ -0,0 +1,23 @@
|
|||||||
|
#import "LKSessionRestoreMessage.h"
|
||||||
|
#import <SignalCoreKit/NSDate+OWS.h>
|
||||||
|
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||||
|
|
||||||
|
@implementation LKSessionRestoreMessage
|
||||||
|
|
||||||
|
#pragma mark Initialization
|
||||||
|
- (instancetype)initWithThread:(TSThread *)thread {
|
||||||
|
return [self initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"" attachmentIds:[NSMutableArray<NSString *> new]
|
||||||
|
expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark Building
|
||||||
|
- (nullable SSKProtoDataMessageBuilder *)dataMessageBuilder
|
||||||
|
{
|
||||||
|
SSKProtoDataMessageBuilder *builder = super.dataMessageBuilder;
|
||||||
|
if (builder == nil) { return nil; }
|
||||||
|
[builder setFlags:SSKProtoDataMessageFlagsSessionRestore];
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
Loading…
Reference in New Issue