KMVerificationActivateViewController.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. }
  76. - (void)viewDidAppear {
  77. [super viewDidAppear];
  78. [self.textField becomeFirstResponder];
  79. }
  80. #pragma mark Button Actions
  81. - (IBAction)backButtonAction:(id)sender {
  82. if (self.callback) {
  83. self.callback(0, self.textField.stringValue);
  84. }
  85. }
  86. - (IBAction)continueButtonAction:(id)sender {
  87. NSString *lineString = self.textField.stringValue;
  88. lineString = [lineString stringByReplacingOccurrencesOfString:@" " withString:@""];
  89. if (lineString.length > 0) {
  90. self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
  91. } else {
  92. self.textFieldView.layer.borderColor = [NSColor redColor].CGColor;
  93. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  94. defaultButton:NSLocalizedString(@"Try Again", nil)
  95. alternateButton:nil
  96. otherButton:nil
  97. informativeTextWithFormat:NSLocalizedString(@"License number can not be empty.", nil), nil];
  98. [alert runModal];
  99. return;
  100. }
  101. if (self.callback) {
  102. self.callback(1, lineString);
  103. }
  104. }
  105. - (IBAction)clickHereButtonAction:(id)sender {
  106. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/license_retrieval"];
  107. [[NSWorkspace sharedWorkspace] openURL:url];
  108. }
  109. - (void)setEnabled:(BOOL)enabled {
  110. self.backButton.enabled = enabled;
  111. self.continueButton.enabled = enabled;
  112. self.textField.enabled = enabled;
  113. }
  114. #pragma mark NSTextFieldDelegate
  115. - (void)controlTextDidChange:(NSNotification *)notification {
  116. self.textFieldView.layer.borderColor = [NSColor lightGrayColor].CGColor;
  117. }
  118. @end