KMVerificationActivateViewController.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // KMVerificationActivateViewController.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by 王帅 on 2018/5/8.
  6. //
  7. #import "KMVerificationActivateViewController.h"
  8. #import <PDF_Reader_Pro-Swift.h>
  9. @interface KMVerificationActivateViewController ()
  10. @property (nonatomic,assign) IBOutlet NSTextField *label;
  11. @property (nonatomic,assign) IBOutlet NSTextField *sublabel;
  12. @property (nonatomic,assign) IBOutlet NSView *textFieldView;
  13. @property (nonatomic,assign) IBOutlet NSTextField *textField;
  14. @property (nonatomic,assign) IBOutlet NSTextField *textLabel;
  15. @property (nonatomic,assign) IBOutlet NSButton *clickHereButton;
  16. @property (strong) IBOutlet NSLayoutConstraint *clickBGViewTopConst;
  17. @property (nonatomic,assign) IBOutlet KMCustomButton *backButton;
  18. @property (nonatomic,assign) IBOutlet KMCustomButton *continueButton;
  19. @property (strong) IBOutlet NSTextField *errorInfoLabel;
  20. @property (nonatomic, retain) CALayer *continueButtonLayer;
  21. @end
  22. @implementation KMVerificationActivateViewController
  23. #pragma mark Init Methods
  24. - (instancetype)init {
  25. if (self = [super initWithNibName:@"KMVerificationActivateViewController" bundle:nil]) {
  26. }
  27. return self;
  28. }
  29. - (void)dealloc {
  30. }
  31. #pragma mark View Methods
  32. - (void)loadView {
  33. [super loadView];
  34. // Do view setup here.
  35. self.textFieldView.wantsLayer = YES;
  36. self.textFieldView.layer.masksToBounds = YES;
  37. self.textFieldView.layer.cornerRadius = 1.0;
  38. self.textFieldView.layer.borderWidth = 1.0;
  39. self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
  40. self.backButton.wantsLayer = YES;
  41. self.backButton.layer.masksToBounds = YES;
  42. self.backButton.layer.cornerRadius = 1.0;
  43. self.continueButton.wantsLayer = YES;
  44. self.continueButton.layer.masksToBounds = YES;
  45. self.continueButton.layer.cornerRadius = 1.0;
  46. self.label.stringValue = NSLocalizedString(@"Please enter your license", nil);
  47. self.sublabel.stringValue = NSLocalizedString(@"If you have already purchased LynxPDF Editor for Mac, you should find your license in an email confirmation.", nil);
  48. self.textLabel.stringValue = NSLocalizedString(@"Can't find your license?", nil);
  49. [self.textField.cell setPlaceholderString:NSLocalizedString(@"License Number", nil)];
  50. NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Click here", nil)];
  51. NSRange range = NSMakeRange(0, attributedTitle.length);
  52. [attributedTitle addAttribute:NSFontAttributeName value:self.clickHereButton.font range:range];
  53. [attributedTitle addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Layout_H0] range:range];
  54. [attributedTitle addAttribute:NSUnderlineStyleAttributeName value:@(YES) range:range];
  55. self.clickHereButton.attributedTitle = attributedTitle;
  56. self.backButton.title = NSLocalizedString(@"Cancel", nil);
  57. self.continueButton.title = NSLocalizedString(@"Continue", nil);
  58. [self.backButton setTitleColor:[KMAppearance KMColor_Layout_H0]];
  59. [self.continueButton setTitleColor:[NSColor whiteColor]];
  60. self.continueButtonLayer = [CALayer layer];
  61. [self.continueButton.layer addSublayer:self.continueButtonLayer];
  62. self.continueButtonLayer.frame = CGRectMake(0, 0, CGRectGetWidth(_continueButton.bounds), CGRectGetHeight(_continueButton.bounds));
  63. self.continueButtonLayer.backgroundColor = [KMAppearance KMColor_Status_Sel].CGColor;
  64. self.continueButtonLayer.cornerRadius = 0;
  65. self.continueButtonLayer.hidden = YES;
  66. __block KMVerificationActivateViewController *blockSelf = self;
  67. self.continueButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  68. if (mouseEntered)
  69. blockSelf.continueButtonLayer.hidden = NO;
  70. else
  71. blockSelf.continueButtonLayer.hidden = YES;
  72. };
  73. self.backButton.mouseMoveCallback = nil;
  74. [self.label setTextColor:[KMAppearance KMColor_Layout_H0]];
  75. [self.sublabel setTextColor:[KMAppearance KM_242424_Color75]];
  76. [self.textLabel setTextColor:[KMAppearance KMColor_Layout_H0]];
  77. self.errorInfoLabel.hidden = YES;
  78. self.errorInfoLabel.font = [NSFont SFProTextRegularFont:12];
  79. self.errorInfoLabel.textColor = KMAppearance.KMColor_Status_Err;
  80. self.type = KMVerificationTypeActivate;
  81. }
  82. - (void)viewDidAppear {
  83. [super viewDidAppear];
  84. [self.textField becomeFirstResponder];
  85. }
  86. - (void)setType:(KMVerificationType)type {
  87. self.errorInfoLabel.hidden = YES;
  88. self.clickBGViewTopConst.constant = 16;
  89. if (type == KMVerificationTypeActivateAIInfo) {
  90. self.textLabel.hidden = YES;
  91. self.clickHereButton.hidden = YES;
  92. self.label.stringValue = NSLocalizedString(@"Please Enter AI License", nil);
  93. self.sublabel.stringValue = NSLocalizedString(@"For PDF Reader Pro Permanent/Premium License, please click LynxPDF Editor on the menubar, then tap \"Enter License\".", nil);
  94. [self.textField.cell setPlaceholderString:NSLocalizedString(@"AI-XXXX-XXXX-XXXX-XXXX", nil)];
  95. } else {
  96. self.textLabel.hidden = NO;
  97. self.clickHereButton.hidden = NO;
  98. self.label.stringValue = NSLocalizedString(@"Please enter your license", nil);
  99. self.sublabel.stringValue = NSLocalizedString(@"If you have already purchased LynxPDF Editor for Mac, you should find your license in an email confirmation.", nil);
  100. [self.textField.cell setPlaceholderString:NSLocalizedString(@"XXXX-XXXX-XXXX-XXXX", nil)];
  101. if ([VerificationManager manager].status == ActivityStatusVerifExpire) {
  102. self.errorInfoLabel.hidden = NO;
  103. self.clickBGViewTopConst.constant = 32;
  104. self.errorInfoLabel.stringValue = NSLocalizedString(@"The license has expired", "");
  105. }
  106. }
  107. }
  108. #pragma mark Button Actions
  109. - (IBAction)backButtonAction:(id)sender {
  110. if (self.callback) {
  111. self.callback(0, self.textField.stringValue);
  112. }
  113. }
  114. - (IBAction)continueButtonAction:(id)sender {
  115. NSString *lineString = self.textField.stringValue;
  116. lineString = [lineString stringByReplacingOccurrencesOfString:@" " withString:@""];
  117. if (lineString.length > 0) {
  118. self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
  119. } else {
  120. self.textFieldView.layer.borderColor = [NSColor redColor].CGColor;
  121. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  122. defaultButton:NSLocalizedString(@"Try Again", nil)
  123. alternateButton:nil
  124. otherButton:nil
  125. informativeTextWithFormat:NSLocalizedString(@"License number can not be empty.", nil), nil];
  126. [alert runModal];
  127. return;
  128. }
  129. if (self.callback) {
  130. self.callback(1, lineString);
  131. }
  132. }
  133. - (IBAction)clickHereButtonAction:(id)sender {
  134. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/license_retrieval"];
  135. [[NSWorkspace sharedWorkspace] openURL:url];
  136. }
  137. - (void)setEnabled:(BOOL)enabled {
  138. self.backButton.enabled = enabled;
  139. self.continueButton.enabled = enabled;
  140. self.textField.enabled = enabled;
  141. }
  142. #pragma mark NSTextFieldDelegate
  143. - (void)controlTextDidChange:(NSNotification *)notification {
  144. self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
  145. }
  146. @end