KMVerificationActivateViewController.m 6.6 KB

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