KMConvertComparePayViewController.m 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //
  2. // KMConvertFunctionPayViewController.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by 丁林圭 on 2019/5/23.
  6. //
  7. #import "KMConvertComparePayViewController.h"
  8. //#import "NSButton+TitleColor.h"
  9. #import "NSImage_SKExtensions.h"
  10. #import <PDF_Reader_Pro-Swift.h>
  11. @interface KMConvertComparePayViewController ()<NSPageControllerDelegate>
  12. @property (assign) IBOutlet NSView *contendView;
  13. @property (assign) IBOutlet NSTextField *titleLabel;
  14. @property (assign) IBOutlet NSTextField *contentLabel;
  15. @property (assign) IBOutlet KMBox *purchaseBox;
  16. @property (assign) IBOutlet NSTextField *priceLabel;
  17. @property (assign) IBOutlet NSTextField *priceDesLabel;
  18. @property (assign) IBOutlet KMButton *purchaseButton;
  19. @property (assign) IBOutlet HyperLinkButton *restoreBtn;
  20. @property (assign) IBOutlet HyperLinkButton *privacyButton;
  21. @property (assign) IBOutlet HyperLinkButton *termOfSerButton;
  22. @property (assign) IBOutlet NSTextView *purchaseContenxtTextView;
  23. @property (nonatomic,retain) NSArray *imageArray;
  24. @property (nonatomic,assign) NSInteger indexPage;
  25. @property (nonatomic,assign) NSInteger selectIndex;
  26. @end
  27. @implementation KMConvertComparePayViewController
  28. - (void)dealloc {
  29. _block = nil;
  30. [NSDistributedNotificationCenter.defaultCenter removeObserver:self];
  31. }
  32. - (instancetype)initWithSelectIndex:(NSInteger)selectIndex {
  33. if (self = [super initWithNibName:@"KMConvertComparePayViewController" bundle:nil]) {
  34. self.indexPage = selectIndex;
  35. }
  36. return self;
  37. }
  38. - (void)loadView {
  39. [super loadView];
  40. self.contendView.wantsLayer = YES;
  41. self.purchaseBox.wantsLayer = YES;
  42. self.purchaseBox.layer.masksToBounds = YES;
  43. self.purchaseBox.layer.cornerRadius = CGRectGetHeight(self.purchaseBox.frame)/2.;
  44. self.purchaseContenxtTextView.wantsLayer = YES;
  45. self.purchaseContenxtTextView.layer.backgroundColor = [NSColor clearColor].CGColor;
  46. self.purchaseContenxtTextView.backgroundColor = [NSColor clearColor];
  47. [self localizedLanguage];
  48. [self updateViewColor];
  49. [self reloadData];
  50. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  51. }
  52. - (void)localizedLanguage {
  53. self.titleLabel.font = [NSFont UbuntuBoldFontWithSize:20];
  54. self.contentLabel.font = [NSFont SFProTextRegularFont:14];
  55. self.priceLabel.font = [NSFont UbuntuBoldFontWithSize:20];
  56. self.priceDesLabel.font = [NSFont SFProTextSemiboldFont:13];
  57. self.restoreBtn.font = [NSFont SFProTextRegularFont:13];
  58. self.privacyButton.font = [NSFont SFProTextRegularFont:13];
  59. self.termOfSerButton.font = [NSFont SFProTextRegularFont:13];
  60. self.purchaseContenxtTextView.font = [NSFont SFProTextRegularFont:12];
  61. self.titleLabel.stringValue = NSLocalizedString(@"Purchase PDF to Office Pack", nil);
  62. self.contentLabel.stringValue = [NSString stringWithFormat:@"%@\n%@",NSLocalizedString(@"The premium version can only convert first 10 pages.", nil),NSLocalizedString(@"Purchase PDF to Office Pack to convert all pages in high quality.", nil)];
  63. self.restoreBtn.title = [NSString stringWithFormat:@"%@",NSLocalizedString(@"Restore", nil)];
  64. self.privacyButton.title = [NSString stringWithFormat:@"%@",NSLocalizedString(@"Privacy Policy", nil)];
  65. self.termOfSerButton.title = [NSString stringWithFormat:@"%@",NSLocalizedString(@"Terms of Service", nil)];
  66. self.restoreBtn.toolTip = [NSString stringWithFormat:@"%@",NSLocalizedString(@"Restore", nil)];
  67. self.privacyButton.toolTip = [NSString stringWithFormat:@"%@",NSLocalizedString(@"Privacy Policy", nil)];
  68. self.termOfSerButton.toolTip = [NSString stringWithFormat:@"%@",NSLocalizedString(@"Terms of Service", nil)];
  69. for (HyperLinkButton *button in @[self.restoreBtn, self.privacyButton, self.termOfSerButton]) {
  70. button.mouseMoveCallback = ^(BOOL mouseEntered) {
  71. if ([KMAppearance isDarkMode]) {
  72. if (mouseEntered) {
  73. [button setTitleColor:[KMAppearance KMColor_Layout_W70]];
  74. } else {
  75. [button setTitleColor:[KMAppearance KMColor_Layout_H2]];
  76. }
  77. } else {
  78. if (mouseEntered) {
  79. [button setTitleColor:[KMAppearance KMColor_Layout_H0]];
  80. } else {
  81. [button setTitleColor:[KMAppearance KMColor_Layout_H2]];
  82. }
  83. }
  84. };
  85. }
  86. self.purchaseButton.wantsLayer = YES;
  87. __weak typeof(self) weakSelf = self;
  88. self.purchaseButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  89. if (weakSelf.purchaseButton.enabled) {
  90. if (mouseEntered) {
  91. weakSelf.purchaseButton.layer.backgroundColor = [[NSColor blackColor] colorWithAlphaComponent:0.15].CGColor;
  92. } else {
  93. weakSelf.purchaseButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  94. }
  95. }
  96. };
  97. NSString * price = @"";
  98. if ([IAPProductsManager defaultManager].PDFToOfficeProduct.isOffers) {
  99. price = [IAPProductsManager defaultManager].PDFToOfficeProduct.offersPrice;
  100. } else {
  101. price = [IAPProductsManager defaultManager].PDFToOfficeProduct.price;
  102. }
  103. self.priceLabel.stringValue = price ? : @"";
  104. self.priceDesLabel.stringValue = NSLocalizedString(@"one-time purchase", nil);
  105. }
  106. - (void)updateViewColor {
  107. if ([KMAppearance isDarkMode]) {
  108. self.contendView.layer.backgroundColor = [NSColor colorWithRed:24/255. green:22/255. blue:31/255. alpha:1].CGColor;
  109. self.titleLabel.textColor = [KMAppearance KMColor_Layout_W0];
  110. self.contentLabel.textColor = [KMAppearance KMColor_Layout_W0];
  111. self.purchaseContenxtTextView.textColor = [[NSColor whiteColor] colorWithAlphaComponent:0.3];
  112. } else {
  113. self.contendView.layer.backgroundColor = [NSColor colorWithRed:247/255. green:245/255. blue:255/255. alpha:1].CGColor;
  114. self.titleLabel.textColor = [NSColor colorWithRed:14/255. green:17/255. blue:20/255. alpha:1];
  115. self.contentLabel.textColor = [KMAppearance KMColor_Layout_H0];
  116. self.purchaseContenxtTextView.textColor = [[NSColor blackColor] colorWithAlphaComponent:0.3];
  117. }
  118. self.priceLabel.textColor = [NSColor whiteColor];
  119. self.priceDesLabel.textColor = [[NSColor whiteColor] colorWithAlphaComponent:0.8];
  120. self.purchaseBox.fillColor = [NSColor colorWithRed:1 green:94/255. blue:44/255. alpha:1];
  121. [self.restoreBtn setTitleColor:[KMAppearance KMColor_Layout_H2]];
  122. [self.privacyButton setTitleColor:[KMAppearance KMColor_Layout_H2]];
  123. [self.termOfSerButton setTitleColor:[KMAppearance KMColor_Layout_H2]];
  124. }
  125. - (void)removeObserver {
  126. [NSDistributedNotificationCenter.defaultCenter removeObserver:self];
  127. }
  128. - (void)reloadData {
  129. #ifndef VERSION_DMG
  130. if ([IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  131. [self.purchaseButton setEnabled:NO];
  132. self.purchaseButton.layer.backgroundColor = [[NSColor whiteColor] colorWithAlphaComponent:0.4].CGColor;
  133. } else {
  134. [self.purchaseButton setEnabled:YES];
  135. }
  136. #endif
  137. }
  138. #pragma mark - IBAction
  139. - (IBAction)buttonItemClick_Subscribe1:(id)sender {
  140. KMConvertComparePayType type = KMConvertComparePayType_Refresh;
  141. #if VERSION_DMG
  142. type = KMConvertComparePayType_Refresh;
  143. #else
  144. type = KMConvertComparePayType_Restore;
  145. #endif
  146. if (self.block) {
  147. self.block(type);
  148. }
  149. }
  150. - (IBAction)buttonItemClick_Subscribe2:(id)sender {
  151. KMConvertComparePayType type = KMConvertComparePayType_STORE;
  152. #if VERSION_DMG
  153. type = KMConvertComparePayType_DMG;
  154. #else
  155. type = KMConvertComparePayType_STORE;
  156. #endif
  157. if (self.block) {
  158. self.block(type);
  159. }
  160. }
  161. - (IBAction)privacyButtonAction:(id)sender {
  162. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/privacy-policy"]];
  163. }
  164. - (IBAction)termOfSerButtonAction:(id)sender {
  165. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/terms_of_service"]];
  166. }
  167. - (void)themeChanged:(NSNotification *)notification {
  168. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  169. [self updateViewColor];
  170. });
  171. }
  172. @end