KMVerificationMessageViewController.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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(KMMemberInfo.shared.isLogin == NO) {
  280. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  281. } else {
  282. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  283. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  284. } else {
  285. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  286. }
  287. }
  288. #else
  289. #endif
  290. } else if (type == KMUserScenarioTypeLite_type3 ) {
  291. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  292. } else if (type == KMUserScenarioTypeLite_type5) {
  293. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  294. } else if (type == KMUserScenarioTypeLite_type7) {
  295. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  296. } else if (type == KMUserScenarioTypeLite_type9) {
  297. if([KMMemberInfo shared].vip_status == 2) {
  298. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  299. } else if ([KMMemberInfo shared].vip_status == 4) {
  300. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  301. } else {
  302. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  303. }
  304. } else if (type == KMUserScenarioTypeLite_type11) {
  305. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  306. }
  307. #if !VERSION_FREE
  308. BOOL isNoSupportMemberUpgrade = YES;
  309. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  310. isNoSupportMemberUpgrade = NO;
  311. }
  312. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  313. [self.officeButton setTitleColor:[NSColor whiteColor]];
  314. self.officeButton.hidden = NO;
  315. self.officeImg.hidden = NO;
  316. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  317. CGRect officeRect = self.officeButton.frame;
  318. self.officeImg.frame = officeRect;
  319. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  320. totalWidth+=4;
  321. } else {
  322. self.officeButton.hidden = YES;
  323. self.officeImg.hidden = YES;
  324. }
  325. #else
  326. self.officeButton.hidden = YES;
  327. self.officeImg.hidden = YES;
  328. #endif
  329. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  330. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  331. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  332. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  333. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  334. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  335. __weak typeof(self)weakSelf = self;
  336. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  337. if (image != nil) {
  338. weakSelf.bgImg.image = image;
  339. }
  340. }];
  341. }
  342. }
  343. [self.button setTitleColor:[NSColor whiteColor]];
  344. self.bgImg.hidden = NO;
  345. self.button.hidden = NO;
  346. BOOL isOldSubscribed = NO;
  347. #if VERSION_FREE
  348. #if !VERSION_DMG
  349. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  350. #endif
  351. #endif
  352. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  353. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  354. if(type == KMUserScenarioTypeLite_type9 ||
  355. type == KMUserScenarioTypeLite_type10 ||
  356. type == KMUserScenarioTypeLite_type11) {
  357. if([KMMemberInfo shared].isLogin == NO) { //未登录
  358. self.button.hidden = YES;
  359. self.bgImg.hidden = YES;
  360. } else {
  361. if(isOldSubscribed) { //老版本付费功能是订阅包
  362. self.button.hidden = YES;
  363. self.bgImg.hidden = YES;
  364. } else {
  365. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  366. self.button.hidden = YES;
  367. self.bgImg.hidden = YES;
  368. }
  369. }
  370. }
  371. }
  372. buttonWidth = CGRectGetMaxX(self.button.frame);
  373. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  374. if (fabs(buttonWidth-btnRect.size.width)>50) {
  375. buttonWidth = btnRect.size.width + 10;
  376. }
  377. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  378. CGRect rect = self.button.frame;
  379. self.bgImg.frame = rect;
  380. totalWidth+=CGRectGetWidth(self.button.bounds);
  381. totalWidth+=4;
  382. } else if (type == KMUserScenarioTypeLite_type12 ||
  383. type == KMUserScenarioTypeLite_type13 ||
  384. type == KMUserScenarioTypeLite_type2 ||
  385. type == KMUserScenarioTypeLite_type4 ||
  386. type == KMUserScenarioTypeLite_type6 ||
  387. type == KMUserScenarioTypeLite_type8 ||
  388. type == KMUserScenarioTypePro_type2 ||
  389. type == KMUserScenarioTypePro_type5) {
  390. self.button.hidden = YES;
  391. self.bgImg.hidden = YES;
  392. #if !VERSION_FREE
  393. BOOL isNoSupportMemberUpgrade = YES;
  394. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  395. isNoSupportMemberUpgrade = NO;
  396. }
  397. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  398. [self.officeButton setTitleColor:[NSColor whiteColor]];
  399. self.officeButton.hidden = NO;
  400. self.officeImg.hidden = NO;
  401. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  402. CGRect officeRect = self.officeButton.frame;
  403. self.officeImg.frame = officeRect;
  404. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  405. totalWidth+=4;
  406. } else {
  407. self.officeButton.hidden = YES;
  408. self.officeImg.hidden = YES;
  409. }
  410. #else
  411. self.officeButton.hidden = YES;
  412. self.officeImg.hidden = YES;
  413. #endif
  414. }
  415. #endif
  416. if ([KMMemberInfo shared].isLogin) {
  417. self.userButton.hidden = NO;
  418. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  419. totalWidth += userImageWidth;
  420. totalWidth += 8;
  421. } else {
  422. self.signUpView.hidden = NO;
  423. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  424. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  425. }
  426. 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);
  427. }
  428. #pragma mark - Button Actions
  429. - (IBAction)secondTrialAction:(NSButton *)sender {
  430. if ([VerificationManager manager].secondTrialEnabled) {
  431. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  432. [vc showWindow:nil];
  433. } else {
  434. [[KMProductCompareWC shared] setOrientation:NO];
  435. [[KMProductCompareWC shared] showWindow:nil];
  436. }
  437. }
  438. - (IBAction)buttonAction:(id)sender {
  439. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  440. if (type == KMUserScenarioTypeDmg_type4 ||
  441. type == KMUserScenarioTypeDmg_type19 ||
  442. type == KMUserScenarioTypeDmg_type34) {
  443. [[KMProductCompareWC shared] setOrientation:YES];
  444. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  445. [[KMProductCompareWC shared] showWindow:nil];
  446. } else {
  447. [[KMMemberInfo shared] advancedFunctionUsage];
  448. }
  449. }
  450. - (IBAction)officeButtonAction:(id)sender {
  451. }
  452. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  453. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  454. NSString *temp = nil;
  455. for (NSUInteger i = 0; i <string.length; i++) {
  456. temp = [string substringWithRange:NSMakeRange(i, 1)];
  457. if ([self isPureInt:temp]) {
  458. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  459. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  460. }
  461. }
  462. return attributedString;
  463. }
  464. - (BOOL)isPureInt:(NSString *)string {
  465. NSScanner *scan = [NSScanner scannerWithString:string];
  466. int value;
  467. return [scan scanInt:&value] && [scan isAtEnd];
  468. }
  469. - (IBAction)AIButtonAction:(NSButton *)sender {
  470. __block typeof(self) blockSelf = self;
  471. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  472. // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  473. //
  474. // }];
  475. // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  476. // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  477. //#if VERSION_DMG
  478. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  479. // [embeddedWC showWindow:nil];
  480. // [[embeddedWC window] center];
  481. //#else
  482. //
  483. // [[AIPurchaseWindowController currentWC] showWindow:nil];
  484. //#endif
  485. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  486. // };
  487. // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  488. // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  489. // verifyVC.callback = ^{
  490. //
  491. // };
  492. // [verifyVC showWindow:nil];
  493. // };
  494. //
  495. // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  496. // if (!blockSelf.guideWindowVC) {
  497. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  498. // blockSelf.guideWindowVC = guideWindowVC;
  499. // }
  500. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  501. // [blockSelf.guideWindowVC showWindow:nil];
  502. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  503. // [blockSelf.guideWindowVC.window orderFront:nil];
  504. // };
  505. //
  506. // NSPopover *popover = [[NSPopover alloc] init];
  507. // popover.contentViewController = controller;
  508. // popover.animates = YES;
  509. // popover.behavior = NSPopoverBehaviorTransient;
  510. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  511. [[KMFreeGetAIWC shared] showWindow:nil];
  512. }
  513. - (IBAction)userButtonAction:(NSButton *)sender {
  514. if ([KMMemberInfo shared].isLogin) {
  515. [self personalCenterAction:sender];
  516. } else {
  517. [KMLoginWindowsController.shared showWindow:nil];
  518. }
  519. }
  520. - (IBAction)personalCenterAction:(NSButton *)sender {
  521. [KMUserInfoViewController refreshTokenUserInfoWithCallback:^(BOOL success,KMMemberCenterResult*resDic) {
  522. if(success) {
  523. if([KMMemberInfo shared].isLogin == YES) {
  524. // 用户头像点击事件
  525. self.userMenu = [[NSMenu alloc] init];
  526. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  527. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  528. item.target = self;
  529. item.representedObject = userInfo;
  530. item.view = userInfo.view;
  531. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  532. }
  533. } else {
  534. NSInteger code = resDic.code;
  535. if(code == 304) {
  536. [[KMLoginWindowsController shared] showWindow:nil];
  537. }
  538. }
  539. }];
  540. }
  541. - (IBAction)signUpAction:(NSButton *)sender {
  542. [KMLoginWindowsController.shared showWindow:nil];
  543. }
  544. #pragma mark - NSNotification Methods
  545. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  546. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  547. [self reloadData];
  548. });
  549. }
  550. - (void)IAPResultReceived:(NSNotification *)notification {
  551. dispatch_async(dispatch_get_main_queue(), ^{
  552. [self reloadData];
  553. });
  554. }
  555. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  556. dispatch_async(dispatch_get_main_queue(), ^{
  557. [self reloadData];
  558. });
  559. }
  560. - (void)IAPRestoreFinish:(NSNotification *)notification {
  561. dispatch_async(dispatch_get_main_queue(), ^{
  562. [self reloadData];
  563. });
  564. }
  565. #pragma mark - Event
  566. - (void)mouseEntered:(NSEvent *)event {
  567. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  568. ActivityStatusTrial == [VerificationManager manager].status) {
  569. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  570. if (!self.popover.isShown) {
  571. [self buttonAction:self.button];
  572. }
  573. }
  574. }
  575. - (void)mouseExited:(NSEvent *)event {
  576. [super mouseExited:event];
  577. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  578. }
  579. - (void)popoverDidClose:(NSNotification *)notification {
  580. self.stopPopOverHide = NO;
  581. }
  582. - (void)popoverShowNoti:(NSNotification *)noti {
  583. if (self.popover) {
  584. [self.popover close];
  585. self.stopPopOverHide = NO;
  586. }
  587. }
  588. - (void)loginSuccessNotification:(NSNotification *)noti {
  589. _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  590. [self reloadData];
  591. }
  592. - (void)logoutSuccessNotification:(NSNotification *)noti {
  593. _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  594. [self reloadData];
  595. }
  596. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  597. if (self.userMenu != nil) {
  598. [self personalCenterAction:_userButton];
  599. }
  600. }
  601. - (void)closeMenu:(NSNotification *)noti {
  602. if (self.userMenu != nil) {
  603. [self.userMenu cancelTracking];
  604. self.userMenu = nil;
  605. }
  606. }
  607. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  608. [self reloadData];
  609. }
  610. - (void)popOverCloseAction {
  611. if (self.stopPopOverHide == NO) {
  612. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  613. ActivityStatusTrial == [VerificationManager manager].status) {
  614. if (self.popover.isShown) {
  615. [self.popover close];
  616. self.stopPopOverHide = NO;
  617. }
  618. }
  619. }
  620. }
  621. @end