Skip to content

Commit

Permalink
caching block size on target; dbug w dsym for all targets to resolve …
Browse files Browse the repository at this point in the history
…fabric warn; fixed icons; resolved remaining warns
  • Loading branch information
Paul Shapiro committed Dec 25, 2015
1 parent 0bfa55c commit a601255
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Modules/WGW_Analytics/C/WGWAnalytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void WGWAnalytics_trackEvent(NSString *named, NSDictionary *parameters_base)
}
});
}
assert(string != nil);
NSCAssert(string != nil, @"e");

return string;
}
Expand Down
17 changes: 13 additions & 4 deletions Modules/WGW_Banner/Views/WGWBannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ - (id)init

- (void)setup
{
{
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
[self addGestureRecognizer:recognizer];
}
{
UIVisualEffect *visualEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
UIVisualEffectView *view = [[UIVisualEffectView alloc] initWithEffect:visualEffect];
Expand Down Expand Up @@ -254,9 +258,14 @@ - (void)layoutSubviews
////////////////////////////////////////////////////////////////////////////////
#pragma mark - Runtime - Delegation





- (void)tapped
{
WGWAnalytics_trackEvent(@"banner tapped", @
{
@"msg lbl txt" : self.messageLabel.text ?: @"nil"
});

[[self class] dismissImmediately];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ - (void)_showContextualMenuForGoesWithAggregateItem:(WGWGoesWithAggregateItem *)
// handler:^(UIAlertAction * _Nonnull action)
// {
/// WGWAnalytics_trackEvent(@"view recipes with '%@'", @{ @"ingredient keyword" : ingredientName ?: @"nil" });
NSString *urlString = [NSString stringWithFormat:@"https://allrecipes.com/search/results/?sort=re&wt=%@", urlQueryFormatted_ingredientName];
// NSString *urlString = [NSString stringWithFormat:@"https://allrecipes.com/search/results/?sort=re&wt=%@", urlQueryFormatted_ingredientName];
// TOWebViewController *webViewController = [[TOWebViewController alloc] initWithURL:[NSURL URLWithString:urlString]];
// UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:webViewController];
// [self presentViewController:navigationController animated:YES completion:nil];
Expand Down Expand Up @@ -354,8 +354,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
}
WGWExploreCollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:[WGWExploreCollectionViewCell reuseIdentifier] forIndexPath:indexPath];
WGWGoesWithAggregateItem *item = [self.items objectAtIndex:indexPath.row];
CGSize blockSize = [self blockSizeForItemAtIndexPath:indexPath];
[cell configureWithItem:item andBlockSize:blockSize];
[cell configureWithItem:item];
{ // Initial visibility
if (self.shouldCellOverlaysBeVisible) {
[cell showOverlayAtFullOpacityOverDuration:0];
Expand All @@ -375,50 +374,12 @@ - (CGSize)blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row >= self.items.count) {
DDLogWarn(@"Asking for index paths of non-existent cells!! %ld from %lu cells", (long)indexPath.row, (unsigned long)self.items.count);
}
switch (self.searchController.searchResultType) {
case WGWSearchResultTypeNoSearch:
{ // it's showing 'random' choice
return [WGWExploreCollectionViewCell largeCellBlockSize];

break;
}

default:
{
if (indexPath.row == 0) {
return [WGWExploreCollectionViewCell principalCellBlockSize];
}
break;
}
}
if (self.items.count < 2) {

return [WGWExploreCollectionViewCell largeCellBlockSize];
}
WGWGoesWithAggregateItem *firstItem = (WGWGoesWithAggregateItem *)[self.items firstObject];
WGWGoesWithAggregateItem *lastItem = (WGWGoesWithAggregateItem *)[self.items lastObject];
assert([firstItem isEqual:lastItem] == NO);
// ^ this can be cached at '-setGoesWithAggregateItems' for optimization
CGFloat topScore = firstItem.totalScore;
CGFloat bottomScore = lastItem.totalScore;
CGFloat scoreRange = topScore - bottomScore;

WGWGoesWithAggregateItem *thisItem = (WGWGoesWithAggregateItem *)self.items[indexPath.row];
CGFloat thisItemScore = thisItem.totalScore;
CGFloat normalizedScore = thisItemScore / (bottomScore + scoreRange);
assert(normalizedScore >= 0 && normalizedScore <= 1);

if (normalizedScore == 1) {
return [WGWExploreCollectionViewCell largeCellBlockSize];
} else if (normalizedScore == 0) {
return [WGWExploreCollectionViewCell smallCellBlockSize];
} else if (normalizedScore < 0.4) {
return [WGWExploreCollectionViewCell smallCellBlockSize];
} else if (normalizedScore < 0.7) {
return [WGWExploreCollectionViewCell mediumCellBlockSize];
} else {
return [WGWExploreCollectionViewCell largeCellBlockSize];
}
return thisItem.cached_blockSize;
}

- (UIEdgeInsets)insetsForItemAtIndexPath:(NSIndexPath *)indexPath
Expand Down
2 changes: 1 addition & 1 deletion Modules/WGW_Explore/Controllers/WGWExploreViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ - (void)WGWSearch_notification_resultUpdated
}

default:
assert(false);
NSAssert(false, @"");
break;
}
}
Expand Down
50 changes: 49 additions & 1 deletion Modules/WGW_Explore/Controllers/WGWSearchController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "WGWSearchController.h"
#import "WGWGoesWithAggregateItem.h"
#import "WGWExploreCollectionViewCell.h"


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -130,7 +131,7 @@ - (NSString *)new_searchQueryStringByAppendingIngredientAtIndex:(NSUInteger)inde
{
NSUInteger numberOf_scoreOrdered_desc_goesWithAggregateItems = _scoreOrdered_desc_goesWithAggregateItems.count;
if (index >= numberOf_scoreOrdered_desc_goesWithAggregateItems) {
assert(false);
NSCAssert(false, @"");

return @"";
}
Expand Down Expand Up @@ -234,6 +235,7 @@ - (void)_refreshQueryResults
goesWithItem.cached_goesWithIngredientKeyword = goesWithOtherIngredient.keyword;
goesWithItem.cached_hosted_ingredientThumbnailImageURLString = goesWithOtherIngredient.hosted_ingredientThumbnailImageURLString;
goesWithItem.totalScore = 0;
// we generate the block size below after obtaining the spread of items
}
goesWithAggregateItems_byKeyword[goesWithOtherIngredient.keyword] = goesWithItem;
}
Expand All @@ -250,6 +252,51 @@ - (void)_refreshQueryResults
self.goesWithAggregateItems_byKeyword = goesWithAggregateItems_byKeyword;

self.scoreOrdered_desc_goesWithAggregateItems = [self _new_scoreOrdered_desc_goesWithAggregateItems];
{ // Now that we have the ordering, we must go through and compute the block sizes for the goesWithItems we generated above
NSUInteger i = 0;
NSUInteger numberOf_scoreOrdered_desc_goesWithAggregateItems = _scoreOrdered_desc_goesWithAggregateItems.count;
if (numberOf_scoreOrdered_desc_goesWithAggregateItems > 0) {
WGWGoesWithAggregateItem *firstItem = (WGWGoesWithAggregateItem *)[_scoreOrdered_desc_goesWithAggregateItems firstObject];
WGWGoesWithAggregateItem *lastItem = (WGWGoesWithAggregateItem *)[_scoreOrdered_desc_goesWithAggregateItems lastObject];
CGFloat topScore = firstItem.totalScore;
CGFloat bottomScore = lastItem.totalScore;
CGFloat scoreRange = topScore - bottomScore;
{
for (WGWGoesWithAggregateItem *thisItem in _scoreOrdered_desc_goesWithAggregateItems) {
CGSize blockSize;
{
if (i == 0) {
blockSize = [WGWExploreCollectionViewCell principalCellBlockSize];
} else if (numberOf_scoreOrdered_desc_goesWithAggregateItems < 2) {
blockSize = [WGWExploreCollectionViewCell largeCellBlockSize];
} else {
NSAssert([firstItem isEqual:lastItem] == NO, @"");

CGFloat thisItemScore = thisItem.totalScore;
CGFloat normalizedScore = thisItemScore / (bottomScore + scoreRange);
NSAssert(normalizedScore >= 0 && normalizedScore <= 1, @"");

if (normalizedScore == 1) {
blockSize = [WGWExploreCollectionViewCell largeCellBlockSize];
} else if (normalizedScore == 0) {
blockSize = [WGWExploreCollectionViewCell smallCellBlockSize];
} else if (normalizedScore < 0.4) {
blockSize = [WGWExploreCollectionViewCell smallCellBlockSize];
} else if (normalizedScore < 0.7) {
blockSize = [WGWExploreCollectionViewCell mediumCellBlockSize];
} else {
blockSize = [WGWExploreCollectionViewCell largeCellBlockSize];
}
}
}
thisItem.cached_blockSize = blockSize;
{
i++;
}
}
}
}
}
[self _yieldThat_searchResultUpdated];
}

Expand All @@ -274,6 +321,7 @@ - (void)loadRandomIngredients
goesWithItem.cached_goesWithIngredientKeyword = ingredient.keyword;
goesWithItem.cached_hosted_ingredientThumbnailImageURLString = ingredient.hosted_ingredientThumbnailImageURLString;
goesWithItem.totalScore = latestScore;
goesWithItem.cached_blockSize = [WGWExploreCollectionViewCell largeCellBlockSize];

latestScore -= scoreStep;
}
Expand Down
2 changes: 2 additions & 0 deletions Modules/WGW_Explore/Models/WGWGoesWithAggregateItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
@property (nonatomic) WGWRLMIngredient *goesWithIngredient;
@property (nonatomic, copy) NSString *cached_goesWithIngredientKeyword;
@property (nonatomic, copy) NSString *cached_hosted_ingredientThumbnailImageURLString;

@property (nonatomic) CGFloat totalScore;
@property (nonatomic) CGSize cached_blockSize;

- (BOOL)isEqualToAggregateItem:(WGWGoesWithAggregateItem *)item;

Expand Down
16 changes: 8 additions & 8 deletions Modules/WGW_Explore/Vendor/RFQuiltLayout/RFQuiltLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ - (void) fillInBlocksToUnrestrictedRow:(int)endRow {
// a vertical layout, then when we assign positions to
// the items we'll invert the axis

int numSections = [self.collectionView numberOfSections];
for (int section=self.lastIndexPathPlaced.section; section<numSections; section++) {
int numRows = [self.collectionView numberOfItemsInSection:section];
NSUInteger numSections = [self.collectionView numberOfSections];
for (NSUInteger section=self.lastIndexPathPlaced.section; section<numSections; section++) {
NSUInteger numRows = [self.collectionView numberOfItemsInSection:section];

for (int row=(!self.lastIndexPathPlaced? 0 : self.lastIndexPathPlaced.row+1); row<numRows; row++) {
for (NSUInteger row=(!self.lastIndexPathPlaced? 0 : self.lastIndexPathPlaced.row+1); row<numRows; row++) {
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:row inSection:section];

if([self placeBlockAtIndex:indexPath]) {
Expand All @@ -194,11 +194,11 @@ - (void) fillInBlocksToIndexPath:(NSIndexPath*)path {
// a vertical layout, then when we assign positions to
// the items we'll invert the axis

int numSections = [self.collectionView numberOfSections];
for (int section=self.lastIndexPathPlaced.section; section<numSections; section++) {
int numRows = [self.collectionView numberOfItemsInSection:section];
NSUInteger numSections = [self.collectionView numberOfSections];
for (NSUInteger section=self.lastIndexPathPlaced.section; section<numSections; section++) {
NSUInteger numRows = [self.collectionView numberOfItemsInSection:section];

for (int row=(!self.lastIndexPathPlaced? 0 : self.lastIndexPathPlaced.row+1); row<numRows; row++) {
for (NSUInteger row=(!self.lastIndexPathPlaced? 0 : self.lastIndexPathPlaced.row+1); row<numRows; row++) {

// exit when we are past the desired row
if(section >= path.section && row > path.row) { return; }
Expand Down
5 changes: 1 addition & 4 deletions Modules/WGW_Explore/Views/WGWExploreCollectionViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
////////////////////////////////////////////////////////////////////////////////
#pragma mark - Imperatives

- (void)configureWithItem:(WGWGoesWithAggregateItem *)item andBlockSize:(CGSize)blockSize;
- (void)configureWithItem:(WGWGoesWithAggregateItem *)item;

- (void)showOverlayAtFullOpacityOverDuration:(NSTimeInterval)duration;
- (void)hideOverlayOverDuration:(NSTimeInterval)duration;
Expand All @@ -32,7 +32,6 @@
#pragma mark - Class - Accessors - Block size

+ (CGFloat)blocksPerScreenWidth;
+ (CGFloat)blocksPerScreenHeight;

+ (CGSize)principalCellBlockSize;
+ (CGSize)largeCellBlockSize;
Expand All @@ -43,6 +42,4 @@

+ (CGRect)labelFrameScaffoldForBlockSize:(CGSize)blockSize; // returns a frame with origin.x and size.width set

+ (BOOL)isEvenBlockCount;

@end
18 changes: 13 additions & 5 deletions Modules/WGW_Explore/Views/WGWExploreCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ - (CGRect)infoContainerViewFrame
#pragma mark - Imperatives - Configuration

- (void)configureWithItem:(WGWGoesWithAggregateItem *)item
andBlockSize:(CGSize)blockSize
{
self.item = item;
self.blockSize = blockSize;
self.blockSize = item.cached_blockSize;
NSAssert(CGSizeEqualToSize(_blockSize, CGSizeZero) == NO, @"");

_overlayView.alpha = 0.3; // start off invisible because we're scrolling if new cells are being requested
_isShowingOverlay = NO;
Expand Down Expand Up @@ -279,7 +279,15 @@ - (void)configureImageView
- (void)configureLabels
{
_titleLabel.numberOfLines = 0;//[[self class] titleLabelMaxNumberOfLinesForBlockSize:self.blockSize]; // because it may change based on the blockSize, and set this before changing the text
_titleLabel.font = [self titleLabelFont]; // because it changes based on the titleText, and set this before changing the text

// because it changes based on the titleText, and set font before changing the text
UIFont *font = [self titleLabelFont];
UIFont *existingFont = _titleLabel.font;
if (!existingFont
|| existingFont.pointSize != font.pointSize
|| [existingFont.familyName isEqualToString:font.familyName] == NO) {
_titleLabel.font = font;
}

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.hyphenationFactor = 1.0f;
Expand Down Expand Up @@ -394,7 +402,7 @@ + (CGFloat)blocksPerScreenWidth
} else if ([self isWidth_divisibleByNumber:18]) {
return 18;
} else {
assert([self isWidth_divisibleByNumber:8]);
NSAssert([self isWidth_divisibleByNumber:8], @"E");
return 8;
}
} else {
Expand All @@ -404,7 +412,7 @@ + (CGFloat)blocksPerScreenWidth
return 25;
}
}
assert(false);
NSCAssert(false, @"E");

return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/WGW_Realm
Submodule WGW_Realm updated from 63aad4 to 6cb59d
6 changes: 5 additions & 1 deletion Whatgoeswith.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand All @@ -833,6 +833,7 @@
"$(inherited)",
"ANALYTICS_OFF=1",
);
GCC_UNROLL_LOOPS = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand Down Expand Up @@ -871,13 +872,16 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = fast;
GCC_UNROLL_LOOPS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
LLVM_LTO = YES;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
Binary file modified Whatgoeswith/Assets.xcassets/AppIcon.appiconset/Icon_29.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Whatgoeswith/Assets.xcassets/AppIcon.appiconset/Icon_40.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Whatgoeswith/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<string>armv7</string>
</array>
<key>UIRequiresFullScreen</key>
<false/>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down

0 comments on commit a601255

Please sign in to comment.