KMVerificationMessageViewController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. //
  2. // KMVerificationMessageViewController.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by 王帅 on 2018/5/9.
  6. //
  7. #import "KMVerificationMessageViewController.h"
  8. #import <PDF_Reader_Pro-Swift.h>
  9. #import "VerificationManager.h"
  10. #import "AIInfoManager.h"
  11. #import "KMVerificationWindowController.h"
  12. #import "KMUnlockAlertViewController.h"
  13. #define kbottomGap 0
  14. @interface KMVerificationMessageViewController ()<
  15. NSPopoverDelegate>
  16. @property (nonatomic, assign) IBOutlet NSTextField *label;
  17. @property (nonatomic, assign) IBOutlet NSButton *button;
  18. @property (nonatomic, assign) IBOutlet NSButton *secondTrialBtn;
  19. @property (assign) IBOutlet NSView *labelContentView;
  20. @property (assign) IBOutlet NSImageView *bgImg;
  21. @property (assign) IBOutlet NSView *aiContendView;
  22. @property (assign) IBOutlet NSImageView *aiIconImg;
  23. @property (assign) IBOutlet NSTextField *aiLabel;
  24. @property (weak) IBOutlet NSButton *userButton;
  25. @property (assign) IBOutlet NSView *signUpView;
  26. @property (assign) IBOutlet NSImageView *signUpImg;
  27. @property (assign) IBOutlet NSTextField *signUpLabel;
  28. @property (weak) IBOutlet NSButton *officeButton;
  29. @property (assign) IBOutlet NSImageView *officeImg;
  30. @property (nonatomic, retain) NSTrackingArea *trackingArea;
  31. @property (nonatomic, retain) NSPopover *popover;
  32. @property (nonatomic, assign) BOOL isPopoverShow;
  33. @property (nonatomic, assign) BOOL checkValue;
  34. @property (nonatomic, assign) BOOL stopPopOverHide;
  35. @property (nonatomic, retain) KMUnlockAlertViewController *testVC;
  36. @property (nonatomic, retain) NSMenu *userMenu;
  37. @end
  38. @implementation KMVerificationMessageViewController
  39. #pragma mark Init Methods
  40. - (instancetype)init {
  41. if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
  42. #if VERSION_DMG
  43. [[NSNotificationCenter defaultCenter] addObserver:self
  44. selector:@selector(deviceActivateStatusChangeNotification:)
  45. name:kDeviceActivateStatusChangeNotification
  46. object:nil];
  47. #else
  48. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
  51. #endif
  52. }
  53. return self;
  54. }
  55. - (void)dealloc {
  56. [[NSNotificationCenter defaultCenter] removeObserver:self];
  57. if (self.trackingArea) {
  58. [self.button removeTrackingArea:self.trackingArea];
  59. }
  60. }
  61. #pragma mark Setter Methods
  62. - (void)loadView {
  63. [super loadView];
  64. // Do view setup here.
  65. self.button.wantsLayer = YES;
  66. self.button.layer.masksToBounds = YES;
  67. self.button.layer.cornerRadius = 4.0;
  68. self.button.font = [NSFont SFProTextSemiboldFont:11];
  69. self.button.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  70. [self.button setAlignment:NSTextAlignmentCenter];
  71. self.secondTrialBtn.wantsLayer = YES;
  72. self.secondTrialBtn.layer.masksToBounds = YES;
  73. self.secondTrialBtn.layer.cornerRadius = 4.0;
  74. self.secondTrialBtn.font = [NSFont SFProTextSemiboldFont:11];
  75. self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  76. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  77. NSString *tTips = NSLocalizedString(@"Upgrade to Pro", nil);
  78. #if VERSION_DMG
  79. tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Upgrade to Permanent License with one time purchase", nil), NSLocalizedString(@"Complete the purchase in your web browser to get a license", nil)];
  80. #else
  81. tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil), NSLocalizedString(@"Choose your favorite payment and enjoy flexible upgrades.", nil)];
  82. #endif
  83. self.button.toolTip = tTips;
  84. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  85. [self.button setTitleColor:[NSColor whiteColor]];
  86. [self.button setAlignment:NSTextAlignmentCenter];
  87. self.secondTrialBtn.toolTip = tTips;
  88. self.secondTrialBtn.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  89. [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
  90. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  91. self.secondTrialBtn.hidden = YES;
  92. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  93. self.bgImg.wantsLayer = YES;
  94. self.bgImg.image = [NSImage imageNamed:@"Upgarde_bg_icon"];
  95. self.bgImg.layer.masksToBounds = YES;
  96. self.bgImg.layer.cornerRadius = 4.;
  97. self.bgImg.hidden = YES;
  98. self.aiLabel.font = [NSFont SFProTextSemiboldFont:11];
  99. self.aiLabel.textColor = [NSColor whiteColor];
  100. [self reloadData];
  101. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
  102. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessNotification:) name:@"MemberCenterLoginSuccess" object:nil];
  103. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccessNotification:) name:@"MemberCenterLogoutSuccess" object:nil];
  104. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandPersonalCenterNotification:) name:@"ExpandPersonalCenter" object:nil];
  105. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeMenu:) name:@"CloseMenuNotification" object:nil];
  106. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(subscriptionLoadedNotification:) name:KMIAPSubscriptionLoadedNotification object:nil];
  107. }
  108. - (void)reloadData {
  109. self.label.textColor = [NSColor blackColor];
  110. self.label.hidden = NO;
  111. self.secondTrialBtn.hidden = YES;
  112. if (self.frameUpdateHandle) {
  113. self.frameUpdateHandle(self.view.frame);
  114. }
  115. CGFloat totalWidth = 8;
  116. self.button.hidden = NO;
  117. self.officeButton.hidden = NO;
  118. self.bgImg.hidden = NO;
  119. self.officeImg.hidden = NO;
  120. self.label.hidden = YES;
  121. self.secondTrialBtn.hidden = YES;
  122. self.labelContentView.hidden = YES;
  123. self.aiContendView.hidden = YES;
  124. self.userButton.hidden = YES;
  125. self.signUpView.hidden = YES;
  126. self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
  127. self.signUpLabel.font = [NSFont SFProTextSemiboldFont:11];
  128. [self.signUpLabel sizeToFit];
  129. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  130. signUpWidth += 4;
  131. signUpWidth += 8;
  132. signUpWidth += 8;
  133. signUpWidth += 12;
  134. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
  135. CGRect signUplabelRect = self.signUpLabel.frame;
  136. signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  137. self.signUpLabel.frame = signUplabelRect;
  138. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  139. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  140. [self.button setTitleColor:[NSColor whiteColor]];
  141. self.officeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  142. self.officeButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF To Office", nil)];
  143. [self.officeButton setTitleColor:[NSColor whiteColor]];
  144. self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free Use 1-Year AI Tools", @"MemberCenterLocalizable", nil);
  145. [self.aiLabel sizeToFit];
  146. CGFloat aiWidth = self.aiLabel.frame.size.width;
  147. aiWidth += 4;
  148. aiWidth += 16;
  149. aiWidth += 16;
  150. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  151. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  152. CGRect ailabelRect = self.aiLabel.frame;
  153. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  154. self.aiLabel.frame = ailabelRect;
  155. // totalWidth+=aiWidth;
  156. // totalWidth+=4;
  157. // self.aiContendView.hidden = NO;
  158. CGFloat userImageWidth = 24;
  159. if ([KMMemberInfo shared].isLogin) {
  160. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  161. } else {
  162. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  163. }
  164. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  165. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  166. if (fabs(buttonWidth-btnRect.size.width)>50) {
  167. buttonWidth = btnRect.size.width + 10;
  168. }
  169. CGFloat officeWidth = CGRectGetMaxX(self.officeButton.frame);
  170. NSRect officeRect = [self.officeButton.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.officeButton.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  171. if (fabs(officeWidth-officeRect.size.width)>50) {
  172. officeWidth = officeRect.size.width + 10;
  173. }
  174. #if VERSION_DMG
  175. self.button.hidden = YES;
  176. self.officeButton.hidden = YES;
  177. self.bgImg.hidden = YES;
  178. self.officeImg.hidden = YES;
  179. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  180. self.aiContendView.hidden = NO;
  181. totalWidth+=aiWidth;
  182. totalWidth+=4;
  183. }
  184. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  185. if (type == KMUserScenarioTypeDmg_type1 ||
  186. type == KMUserScenarioTypeDmg_type2 ||
  187. type == KMUserScenarioTypeDmg_type3 ||
  188. type == KMUserScenarioTypeDmg_type5 ||
  189. type == KMUserScenarioTypeDmg_type6 ||
  190. type == KMUserScenarioTypeDmg_type7 ||
  191. type == KMUserScenarioTypeDmg_type28 ||
  192. type == KMUserScenarioTypeDmg_type29 ||
  193. type == KMUserScenarioTypeDmg_type30 ||
  194. type == KMUserScenarioTypeDmg_type43 ||
  195. type == KMUserScenarioTypeDmg_type44 ||
  196. type == KMUserScenarioTypeDmg_type45) {
  197. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  198. } else if (type == KMUserScenarioTypeDmg_type4 ||
  199. type == KMUserScenarioTypeDmg_type19 ||
  200. type == KMUserScenarioTypeDmg_type34) {
  201. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  202. } else if (type == KMUserScenarioTypeDmg_type11 ||
  203. type == KMUserScenarioTypeDmg_type22 ||
  204. type == KMUserScenarioTypeDmg_type37 ) {
  205. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  206. } else if (type == KMUserScenarioTypeDmg_type18 ||
  207. type == KMUserScenarioTypeDmg_type33 ||
  208. type == KMUserScenarioTypeDmg_type48) {
  209. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  210. }
  211. if (type == KMUserScenarioTypeDmg_type2 ||
  212. type == KMUserScenarioTypeDmg_type19 ||
  213. type == KMUserScenarioTypeDmg_type22 ||
  214. type == KMUserScenarioTypeDmg_type33 ||
  215. type == KMUserScenarioTypeDmg_type30 ||
  216. type == KMUserScenarioTypeDmg_type20 ||
  217. type == KMUserScenarioTypeDmg_type31 ||
  218. type == KMUserScenarioTypeDmg_type21 ||
  219. type == KMUserScenarioTypeDmg_type32) {
  220. [self.officeButton setTitleColor:[NSColor whiteColor]];
  221. self.officeButton.hidden = YES;
  222. self.officeImg.hidden = YES;
  223. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  224. CGRect officeRect = self.officeButton.frame;
  225. self.officeImg.frame = officeRect;
  226. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  227. totalWidth+=4;
  228. }
  229. if (type == KMUserScenarioTypeDmg_type1 ||
  230. type == KMUserScenarioTypeDmg_type2 ||
  231. type == KMUserScenarioTypeDmg_type3 ||
  232. type == KMUserScenarioTypeDmg_type4 ||
  233. type == KMUserScenarioTypeDmg_type5 ||
  234. type == KMUserScenarioTypeDmg_type6 ||
  235. type == KMUserScenarioTypeDmg_type7 ||
  236. type == KMUserScenarioTypeDmg_type11 ||
  237. type == KMUserScenarioTypeDmg_type18 ||
  238. type == KMUserScenarioTypeDmg_type19 ||
  239. type == KMUserScenarioTypeDmg_type22 ||
  240. type == KMUserScenarioTypeDmg_type28 ||
  241. type == KMUserScenarioTypeDmg_type29 ||
  242. type == KMUserScenarioTypeDmg_type30 ||
  243. type == KMUserScenarioTypeDmg_type33 ||
  244. type == KMUserScenarioTypeDmg_type34 ||
  245. type == KMUserScenarioTypeDmg_type37 ||
  246. type == KMUserScenarioTypeDmg_type43 ||
  247. type == KMUserScenarioTypeDmg_type44 ||
  248. type == KMUserScenarioTypeDmg_type45 ||
  249. type == KMUserScenarioTypeDmg_type48) {
  250. [self.button setTitleColor:[NSColor whiteColor]];
  251. self.bgImg.hidden = NO;
  252. self.button.hidden = NO;
  253. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  254. CGRect rect = self.button.frame;
  255. self.bgImg.frame = rect;
  256. totalWidth+=CGRectGetWidth(self.button.bounds);
  257. totalWidth+=4;
  258. }
  259. #else
  260. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  261. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
  262. self.aiContendView.hidden = NO;
  263. totalWidth+=aiWidth;
  264. totalWidth+=4;
  265. }
  266. }
  267. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  268. if (type == KMUserScenarioTypeLite_type1 ||
  269. type == KMUserScenarioTypeLite_type3 ||
  270. type == KMUserScenarioTypeLite_type5 ||
  271. type == KMUserScenarioTypeLite_type7 ||
  272. type == KMUserScenarioTypeLite_type9 ||
  273. type == KMUserScenarioTypeLite_type11 ||
  274. type == KMUserScenarioTypePro_type1 ||
  275. type == KMUserScenarioTypePro_type3 ||
  276. type == KMUserScenarioTypePro_type4) {
  277. if (type == KMUserScenarioTypeLite_type1) { //免费用户
  278. #if !VERSION_DMG
  279. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  280. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  281. } else {
  282. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  283. }
  284. #else
  285. #endif
  286. } else if (type == KMUserScenarioTypeLite_type3 ) {
  287. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  288. } else if (type == KMUserScenarioTypeLite_type5) {
  289. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  290. } else if (type == KMUserScenarioTypeLite_type7) {
  291. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  292. } else if (type == KMUserScenarioTypeLite_type9) {
  293. if([KMMemberInfo shared].vip_status == 2) {
  294. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  295. } else if ([KMMemberInfo shared].vip_status == 4) {
  296. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  297. } else {
  298. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  299. }
  300. } else if (type == KMUserScenarioTypeLite_type11) {
  301. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  302. }
  303. #if !VERSION_FREE
  304. // VerificationManager.default().needUpgradeLicense
  305. if ([[VerificationManager defaultManager] needUpgradeLicense]) {
  306. [self.officeButton setTitleColor:[NSColor whiteColor]];
  307. self.officeButton.hidden = YES;
  308. self.officeImg.hidden = YES;
  309. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  310. CGRect officeRect = self.officeButton.frame;
  311. self.officeImg.frame = officeRect;
  312. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  313. totalWidth+=4;
  314. }
  315. #endif
  316. if (type == KMUserScenarioTypeLite_type1 ||
  317. type == KMUserScenarioTypeLite_type3 ||
  318. type == KMUserScenarioTypeLite_type7 ||
  319. type == KMUserScenarioTypeLite_type11) {
  320. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  321. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  322. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  323. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  324. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  325. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  326. __weak typeof(self)weakSelf = self;
  327. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  328. weakSelf.bgImg.image = image;
  329. }];
  330. }
  331. }
  332. }
  333. [self.button setTitleColor:[NSColor whiteColor]];
  334. self.bgImg.hidden = NO;
  335. self.button.hidden = NO;
  336. BOOL isOldSubscribed = NO;
  337. #if VERSION_FREE
  338. #if !VERSION_DMG
  339. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  340. #endif
  341. #endif
  342. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  343. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  344. if(type == KMUserScenarioTypeLite_type9 ||
  345. type == KMUserScenarioTypeLite_type10 ||
  346. type == KMUserScenarioTypeLite_type11) {
  347. if([KMMemberInfo shared].isLogin == NO) { //未登录
  348. self.button.hidden = YES;
  349. self.bgImg.hidden = YES;
  350. } else {
  351. if(isOldSubscribed) { //老版本付费功能是订阅包
  352. self.button.hidden = YES;
  353. self.bgImg.hidden = YES;
  354. } else {
  355. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  356. self.button.hidden = YES;
  357. self.bgImg.hidden = YES;
  358. }
  359. }
  360. }
  361. }
  362. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  363. CGRect rect = self.button.frame;
  364. self.bgImg.frame = rect;
  365. totalWidth+=CGRectGetWidth(self.button.bounds);
  366. totalWidth+=4;
  367. } else if (type == KMUserScenarioTypeLite_type12 ||
  368. type == KMUserScenarioTypeLite_type13 ||
  369. type == KMUserScenarioTypeLite_type2 ||
  370. type == KMUserScenarioTypeLite_type4 ||
  371. type == KMUserScenarioTypeLite_type6 ||
  372. type == KMUserScenarioTypeLite_type8 ||
  373. type == KMUserScenarioTypePro_type2 ||
  374. type == KMUserScenarioTypePro_type5) {
  375. self.button.hidden = YES;
  376. self.bgImg.hidden = YES;
  377. }
  378. #endif
  379. if ([KMMemberInfo shared].isLogin) {
  380. self.userButton.hidden = NO;
  381. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  382. totalWidth += userImageWidth;
  383. totalWidth += 8;
  384. } else {
  385. self.signUpView.hidden = NO;
  386. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  387. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  388. }
  389. self.view.frame = CGRectMake(MAX(0, CGRectGetWidth(self.view.superview.frame)-totalWidth - 8), (CGRectGetHeight(self.view.superview.frame)-CGRectGetHeight(self.view.frame))/2., totalWidth, self.view.frame.size.height);
  390. }
  391. #pragma mark - Button Actions
  392. - (IBAction)secondTrialAction:(NSButton *)sender {
  393. if ([VerificationManager manager].secondTrialEnabled) {
  394. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  395. [vc showWindow:nil];
  396. } else {
  397. [[KMProductCompareWC shared] setOrientation:NO];
  398. [[KMProductCompareWC shared] showWindow:nil];
  399. }
  400. }
  401. - (IBAction)buttonAction:(id)sender {
  402. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  403. if (type == KMUserScenarioTypeDmg_type4 ||
  404. type == KMUserScenarioTypeDmg_type19 ||
  405. type == KMUserScenarioTypeDmg_type34) {
  406. [[KMProductCompareWC shared] setOrientation:YES];
  407. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  408. [[KMProductCompareWC shared] showWindow:nil];
  409. } else {
  410. [[KMMemberInfo shared] advancedFunctionUsage];
  411. }
  412. }
  413. - (IBAction)officeButtonAction:(id)sender {
  414. }
  415. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  416. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  417. NSString *temp = nil;
  418. for (NSUInteger i = 0; i <string.length; i++) {
  419. temp = [string substringWithRange:NSMakeRange(i, 1)];
  420. if ([self isPureInt:temp]) {
  421. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  422. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  423. }
  424. }
  425. return attributedString;
  426. }
  427. - (BOOL)isPureInt:(NSString *)string {
  428. NSScanner *scan = [NSScanner scannerWithString:string];
  429. int value;
  430. return [scan scanInt:&value] && [scan isAtEnd];
  431. }
  432. - (IBAction)AIButtonAction:(NSButton *)sender {
  433. __block typeof(self) blockSelf = self;
  434. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  435. // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  436. //
  437. // }];
  438. // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  439. // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  440. //#if VERSION_DMG
  441. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  442. // [embeddedWC showWindow:nil];
  443. // [[embeddedWC window] center];
  444. //#else
  445. //
  446. // [[AIPurchaseWindowController currentWC] showWindow:nil];
  447. //#endif
  448. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  449. // };
  450. // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  451. // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  452. // verifyVC.callback = ^{
  453. //
  454. // };
  455. // [verifyVC showWindow:nil];
  456. // };
  457. //
  458. // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  459. // if (!blockSelf.guideWindowVC) {
  460. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  461. // blockSelf.guideWindowVC = guideWindowVC;
  462. // }
  463. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  464. // [blockSelf.guideWindowVC showWindow:nil];
  465. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  466. // [blockSelf.guideWindowVC.window orderFront:nil];
  467. // };
  468. //
  469. // NSPopover *popover = [[NSPopover alloc] init];
  470. // popover.contentViewController = controller;
  471. // popover.animates = YES;
  472. // popover.behavior = NSPopoverBehaviorTransient;
  473. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  474. [[KMFreeGetAIWC shared] showWindow:nil];
  475. }
  476. - (IBAction)userButtonAction:(NSButton *)sender {
  477. if ([KMMemberInfo shared].isLogin) {
  478. [self personalCenterAction:sender];
  479. } else {
  480. [KMLoginWindowsController.shared showWindow:nil];
  481. }
  482. }
  483. - (IBAction)personalCenterAction:(NSButton *)sender {
  484. // 用户头像点击事件
  485. self.userMenu = [[NSMenu alloc] init];
  486. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  487. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  488. item.target = self;
  489. item.representedObject = userInfo;
  490. item.view = userInfo.view;
  491. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  492. }
  493. - (IBAction)signUpAction:(NSButton *)sender {
  494. [KMLoginWindowsController.shared showWindow:nil];
  495. }
  496. #pragma mark - NSNotification Methods
  497. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  498. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  499. [self reloadData];
  500. });
  501. }
  502. - (void)IAPResultReceived:(NSNotification *)notification {
  503. dispatch_async(dispatch_get_main_queue(), ^{
  504. [self reloadData];
  505. });
  506. }
  507. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  508. dispatch_async(dispatch_get_main_queue(), ^{
  509. [self reloadData];
  510. });
  511. }
  512. - (void)IAPRestoreFinish:(NSNotification *)notification {
  513. dispatch_async(dispatch_get_main_queue(), ^{
  514. [self reloadData];
  515. });
  516. }
  517. #pragma mark - Event
  518. - (void)mouseEntered:(NSEvent *)event {
  519. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  520. ActivityStatusTrial == [VerificationManager manager].status) {
  521. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  522. if (!self.popover.isShown) {
  523. [self buttonAction:self.button];
  524. }
  525. }
  526. }
  527. - (void)mouseExited:(NSEvent *)event {
  528. [super mouseExited:event];
  529. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  530. }
  531. - (void)popoverDidClose:(NSNotification *)notification {
  532. self.stopPopOverHide = NO;
  533. }
  534. - (void)popoverShowNoti:(NSNotification *)noti {
  535. if (self.popover) {
  536. [self.popover close];
  537. self.stopPopOverHide = NO;
  538. }
  539. }
  540. - (void)loginSuccessNotification:(NSNotification *)noti {
  541. _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  542. [self reloadData];
  543. }
  544. - (void)logoutSuccessNotification:(NSNotification *)noti {
  545. _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  546. [self reloadData];
  547. }
  548. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  549. if (self.userMenu != nil) {
  550. [self personalCenterAction:_userButton];
  551. }
  552. }
  553. - (void)closeMenu:(NSNotification *)noti {
  554. if (self.userMenu != nil) {
  555. [self.userMenu cancelTracking];
  556. self.userMenu = nil;
  557. }
  558. }
  559. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  560. [self reloadData];
  561. }
  562. - (void)popOverCloseAction {
  563. if (self.stopPopOverHide == NO) {
  564. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  565. ActivityStatusTrial == [VerificationManager manager].status) {
  566. if (self.popover.isShown) {
  567. [self.popover close];
  568. self.stopPopOverHide = NO;
  569. }
  570. }
  571. }
  572. }
  573. @end