From 0fe8d985382bf86ad39a10620805eb7ffce90c7e Mon Sep 17 00:00:00 2001 From: Arun Kumar Chintakrinda Date: Fri, 18 Oct 2024 16:12:45 +0530 Subject: [PATCH] Bokmark changes --- .../MVMCoreLoadRequestOperation.m | 65 ++++++++++++++++++- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 5 ++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 172dd8b..04ea067 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -408,7 +408,51 @@ loadObject.responseJSON = jsonDictionary; // Store the new page data if we didn't load page data from the cache. - NSDictionary *pageJSON = [jsonDictionary objectForKey:KeyPage ofType:[NSDictionary class]]; + + //MARK: Temp code for bookmark test + NSMutableDictionary *mutablepageJSON = [NSMutableDictionary dictionaryWithDictionary:[jsonDictionary dict:KeyPage]]; + if ([@"myFeed" isEqualToString:[mutablepageJSON string:KeyPageType]]) { + NSMutableDictionary *navigationBar = [NSMutableDictionary dictionaryWithDictionary:mutablepageJSON[@"navigationBar"]]; + navigationBar[@"pattern"] = @"ABookmark"; + mutablepageJSON[@"navigationBar"] = navigationBar; + } + + NSString *KeyBookmarkName = @"bookmarkName"; + NSString *KeyBrowserUrl = @"browserUrl"; + NSArray *bookMarkEligiblePageTypes = @[@{KeyBookmarkName: @"feedback", KeyPageType: @"selectFeedbackSource"}, @{KeyBookmarkName: @"perks", KeyPageType: @"webPunchOut_UAD", KeyBrowserUrl: @"https://www.verizon.com/digital/nsa/secure/ui/products/producthub/home?intcmp=uad-screen&tabbar=true"}, @{KeyBookmarkName: @"plans", KeyPageType: @"webPunchOut_UAD", KeyBrowserUrl: @"https://www.verizon.com/digital/nsa/secure/ui/cpc/mvm?pmd=y&tabbar=true&intcmp=uad-screen&tabbar=true"}]; + + for (NSDictionary *bookmark in bookMarkEligiblePageTypes) { + if ([[bookmark string:KeyPageType] isEqualToString:[mutablepageJSON string:KeyPageType]]) { + NSString *browserUrl = [bookmark string:KeyBrowserUrl]; + if (browserUrl) { + if ([browserUrl isEqualToString:[mutablepageJSON string:KeyBrowserUrl]]) { + mutablepageJSON[KeyBookmarkName] = [bookmark string:KeyBookmarkName]; + } + } else { + mutablepageJSON[KeyBookmarkName] = [bookmark string:KeyBookmarkName]; + } + } + } + + //Bookmarks list + if ([@"bookmark" isEqualToString:[mutablepageJSON string:KeyPageType]]) { + NSDictionary *noBookmarksMolecule = @{@"moleculeName": @"listItem", @"molecule": @{@"moleculeName": @"label", @"text": @"No saved bookmarks"}}; + + NSArray *jsonBookmarks = [mutablepageJSON array:@"molecules"]; + NSMutableArray *newBookmarksArray = [NSMutableArray new]; + NSArray *ud_bookmarks = [[NSUserDefaults standardUserDefaults] arrayForKey:@"savedBookmarks"]; + for (NSDictionary *bookmark in jsonBookmarks) { + if ([ud_bookmarks containsObject:[bookmark string:@"bookmarkName"]]) { + [newBookmarksArray addObject:bookmark]; + } + } + if (newBookmarksArray.count == 0) { + [newBookmarksArray addObject:noBookmarksMolecule]; + } + mutablepageJSON[@"molecules"] = newBookmarksArray; + } + + NSDictionary *pageJSON = [NSDictionary dictionaryWithDictionary:mutablepageJSON]; if (!loadObject.pageDataFromCache) { loadObject.pageJSON = pageJSON; loadObject.pageType = [pageJSON string:KeyPageType]; @@ -431,7 +475,24 @@ } // Adds the modules received from server to any modules we grabbed from the cache. - NSDictionary *modules = [jsonDictionary dict:KeyModuleMap]; + NSMutableDictionary *tempModules = [NSMutableDictionary dictionaryWithDictionary:[jsonDictionary dict:KeyModuleMap]]; + if ([@"myFeed" isEqualToString:loadObject.pageType]) { + NSMutableDictionary *patterns = [NSMutableDictionary dictionaryWithDictionary:[tempModules dict: @"navigationPatterns"]]; + NSMutableDictionary *patternA = [NSMutableDictionary dictionaryWithDictionary:[patterns dict:@"A"]]; + NSMutableArray *additionalRightButtons = [NSMutableArray arrayWithArray:[patternA arrayForKey:@"additionalRightButtons"]]; + [additionalRightButtons insertObject:@{@"accessibilityText" : @"Bookmarks", @"moleculeName" : @"navigationImageButton", @"image" : @"star.fill", @"action" : @{ + @"analyticsData" : @{ + @"vzdl.page.linkName" : @"global monarch nav: vz icon" + }, + @"actionType" : @"openPage", + @"pageType": @"bookmarks" + }} atIndex:0]; + patternA[@"additionalRightButtons"] = additionalRightButtons; + patterns[@"ABookmark"] = patternA; + tempModules[@"navigationPatterns"] = patterns; + [tempModules addEntriesFromDictionary:@{@"bookmark": @{@"bookmarkAction": @{KeyActionType: KeyActionTypeOpen, KeyPageType: @"saveBookmark"}, @"bookmarks": @[@{@"bookmarkName": @"plans", @"bookmarked": @YES, KeyBrowserUrl: @"https://www.verizon.com/digital/nsa/secure/ui/cpc/mvm?pmd=y&tabbar=true&intcmp=uad-screen&tabbar=true"}, @{@"bookmarkName": @"perks", @"bookmarked": @NO, KeyBrowserUrl: @"https://www.verizon.com/digital/nsa/secure/ui/products/producthub/home?intcmp=uad-screen&tabbar=true"}]}}]; + } + NSDictionary *modules = [NSDictionary dictionaryWithDictionary:tempModules]; if (loadObject.modulesJSON && modules) { NSMutableDictionary *mutableModules = [NSMutableDictionary dictionaryWithDictionary:loadObject.modulesJSON]; [mutableModules addEntriesFromDictionary:modules]; diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 60ad720..73bfbb7 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -518,6 +518,11 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; } } }); + + if (!image) { + image = [UIImage systemImageNamed:imageName]; + } + return image; }