Skip to content

Commit

Permalink
#1247 (Mac Catalyst edition)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dejal committed Oct 5, 2023
1 parent b08e1f3 commit 7272ccf
Show file tree
Hide file tree
Showing 43 changed files with 270 additions and 158 deletions.
8 changes: 4 additions & 4 deletions clients/ios/Classes/ActivityModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger activitiesCount = [appDelegate.userActivitiesArray count];
int minimumHeight;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (!appDelegate.isPhone) {
minimumHeight = MINIMUM_ACTIVITY_HEIGHT_IPAD;
} else {
minimumHeight = MINIMUM_ACTIVITY_HEIGHT_IPHONE;
Expand All @@ -165,7 +165,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
}

id activityCell;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (!appDelegate.isPhone) {
activityCell = [[ActivityCell alloc] init];
} else {
activityCell = [[SmallActivityCell alloc] init];
Expand All @@ -185,7 +185,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
ActivityCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"ActivityCell"];
if (cell == nil) {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (!appDelegate.isPhone) {
cell = [[ActivityCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"ActivityCell"];
Expand Down Expand Up @@ -304,7 +304,7 @@ - (UITableViewCell *)makeLoadingCell {
UIImage *img = [UIImage imageNamed:@"fleuron.png"];
UIImageView *fleuron = [[UIImageView alloc] initWithImage:img];
int height;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (!appDelegate.isPhone) {
height = MINIMUM_ACTIVITY_HEIGHT_IPAD;
} else {
height = MINIMUM_ACTIVITY_HEIGHT_IPHONE;
Expand Down
6 changes: 3 additions & 3 deletions clients/ios/Classes/AddSiteViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ - (void)viewWillAppear:(BOOL)animated {

//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// // Return YES for supported orientations
// if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// if (!self.isPhone) {
// return YES;
// } else if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
// return YES;
Expand Down Expand Up @@ -130,7 +130,7 @@ - (CGSize)preferredContentSize {
}

- (IBAction)doCancelButton {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (!self.isPhone) {
[appDelegate hidePopover];
} else {
[appDelegate hidePopoverAnimated:YES];
Expand Down Expand Up @@ -272,7 +272,7 @@ - (IBAction)addSite {
[self.errorLabel setText:[responseObject valueForKey:@"message"]];
[self.errorLabel setHidden:NO];
} else {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (!self.isPhone) {
[self->appDelegate hidePopover];
} else {
[self->appDelegate hidePopoverAnimated:YES];
Expand Down
5 changes: 3 additions & 2 deletions clients/ios/Classes/AuthorizeServicesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ - (void)viewWillAppear:(BOOL)animated {
[self.webView loadRequest:requestObj];
}];

if (self.fromStory && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (self.fromStory && !appDelegate.isPhone) {
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithTitle: @"Cancel"
style: UIBarButtonItemStylePlain
Expand All @@ -75,6 +75,7 @@ - (void)doCancelButton {
}

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
BOOL isPhone = appDelegate.isPhone;
NSURLRequest *request = navigationAction.request;
NSString *URLString = [[request URL] absoluteString];
NSLog(@"URL STRING IS %@", URLString);
Expand All @@ -86,7 +87,7 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati

if (self.fromStory) {
[self.appDelegate refreshUserProfile:^{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (!isPhone) {
[self.appDelegate.shareNavigationController viewWillAppear:YES];
[self.appDelegate.modalNavigationController dismissViewControllerAnimated:YES completion:nil];
} else {
Expand Down
9 changes: 7 additions & 2 deletions clients/ios/Classes/BaseViewController.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"

@interface BaseViewController : UIViewController {
}
@interface BaseViewController : UIViewController

@property (nonatomic, readonly) BOOL isPhone;
@property (nonatomic, readonly) BOOL isMac;
@property (nonatomic, readonly) BOOL isVision;
@property (nonatomic, readonly) BOOL isPortrait;
@property (nonatomic, readonly) BOOL isCompactWidth;

- (void)informError:(id)error;
- (void)informError:(id)error statusCode:(NSInteger)statusCode;
Expand Down
30 changes: 30 additions & 0 deletions clients/ios/Classes/BaseViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,34 @@ - (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}

- (BOOL)isPhone {
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone;
}

- (BOOL)isMac {
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomMac;
}

- (BOOL)isVision {
if (@available(iOS 17.0, *)) {
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomVision;
} else {
return NO;
}
}

- (BOOL)isPortrait {
UIInterfaceOrientation orientation = self.view.window.windowScene.interfaceOrientation;
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
return YES;
} else {
return NO;
}
}

- (BOOL)isCompactWidth {
return self.view.window.windowScene.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact;
//return self.compactWidth > 0.0;
}

@end
18 changes: 6 additions & 12 deletions clients/ios/Classes/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,10 @@ class DetailViewController: BaseViewController {
}
}

/// Returns `true` if the device is an iPhone, otherwise `false`.
@objc var isPhone: Bool {
return UIDevice.current.userInterfaceIdiom == .phone
}

/// Returns `true` if the window is in portrait orientation, otherwise `false`.
@objc var isPortraitOrientation: Bool {
return view.window?.windowScene?.interfaceOrientation.isPortrait ?? false
}

/// Position of the divider between the views.
var dividerPosition: CGFloat {
get {
let key = isPortraitOrientation ? Key.verticalPosition : Key.horizontalPosition
let key = isPortrait ? Key.verticalPosition : Key.horizontalPosition
let value = CGFloat(UserDefaults.standard.float(forKey: key))

if value == 0 {
Expand All @@ -212,7 +202,7 @@ class DetailViewController: BaseViewController {
return
}

let key = isPortraitOrientation ? Key.verticalPosition : Key.horizontalPosition
let key = isPortrait ? Key.verticalPosition : Key.horizontalPosition

UserDefaults.standard.set(Float(newValue), forKey: key)
}
Expand Down Expand Up @@ -453,6 +443,10 @@ private extension DetailViewController {
func checkViewControllers() {
let isTop = layout == .top

#if targetEnvironment(macCatalyst)
// splitViewController?.primaryBackgroundStyle = .sidebar //TODO: work in progress
#endif

if layout != .grid || isPhone {
storyPagesViewController = listStoryPagesViewController
_ = storyPagesViewController?.view
Expand Down
2 changes: 1 addition & 1 deletion clients/ios/Classes/FeedChooserTitleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ - (void)drawRect:(CGRect)rect {
UIImage *folderImage = [UIImage imageNamed:@"folder-open"];
CGFloat folderImageViewX = 10.0;

if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPad) {
if (((NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate]).isPhone) {
folderImageViewX = 7.0;
}

Expand Down
2 changes: 2 additions & 0 deletions clients/ios/Classes/FeedDetailGridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ struct FeedDetailGridView: View {
}
}
.modify({ view in
#if !targetEnvironment(macCatalyst)
if #available(iOS 15.0, *) {
view.refreshable {
if cache.canPullToRefresh {
feedDetailInteraction.pullToRefresh()
}
}
}
#endif
})
}
.background(Color.themed([0xE0E0E0, 0xFFF8CA, 0x363636, 0x101010]))
Expand Down
2 changes: 2 additions & 0 deletions clients/ios/Classes/FeedDetailObjCViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
@property (nonatomic) IBOutlet UIBarButtonItem * titleImageBarButton;
@property (nonatomic, retain) NBNotifier *notifier;
@property (nonatomic, retain) StoriesCollection *storiesCollection;
#if !TARGET_OS_MACCATALYST
@property (nonatomic) UIRefreshControl *refreshControl;
#endif
@property (nonatomic) UISearchBar *searchBar;
@property (nonatomic) IBOutlet UIView *messageView;
@property (nonatomic) IBOutlet UILabel *messageLabel;
Expand Down
16 changes: 13 additions & 3 deletions clients/ios/Classes/FeedDetailObjCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ - (void)viewDidLoad {
if (@available(iOS 15.0, *)) {
self.storyTitlesTable.allowsFocus = NO;
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (!self.isPhone) {
self.storyTitlesTable.dragDelegate = self;
self.storyTitlesTable.dragInteractionEnabled = YES;
}
Expand All @@ -119,10 +119,12 @@ - (void)viewDidLoad {
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
spacer2BarButton.width = 0;

#if !TARGET_OS_MACCATALYST
self.refreshControl = [UIRefreshControl new];
self.refreshControl.tintColor = UIColorFromLightDarkRGB(0x0, 0xffffff);
self.refreshControl.backgroundColor = UIColorFromRGB(0xE3E6E0);
[self.refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
#endif

self.searchBar = [[UISearchBar alloc]
initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.storyTitlesTable.frame), 44.)];
Expand Down Expand Up @@ -434,7 +436,7 @@ - (void)viewWillAppear:(BOOL)animated {
if (storiesCollection == nil) {
NSString *appOpening = [userPreferences stringForKey:@"app_opening"];

if ([appOpening isEqualToString:@"feeds"] && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if ([appOpening isEqualToString:@"feeds"] && !self.isPhone) {
self.messageLabel.text = @"Select a feed to read";
self.messageView.hidden = NO;
}
Expand Down Expand Up @@ -510,11 +512,13 @@ - (void)viewWillAppear:(BOOL)animated {
[self.searchBar setShowsCancelButton:NO animated:YES];
}

#if !TARGET_OS_MACCATALYST
if (self.canPullToRefresh) {
self.storyTitlesTable.refreshControl = self.refreshControl;
} else {
self.storyTitlesTable.refreshControl = nil;
}
#endif

[self updateTheme];

Expand Down Expand Up @@ -1440,7 +1444,7 @@ - (void)testForTryFeed {
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
NSString *feedOpening = [preferences stringForKey:@"feed_opening"];

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad && feedOpening == nil) {
if (!self.isPhone && feedOpening == nil) {
feedOpening = @"story";
}

Expand Down Expand Up @@ -3068,8 +3072,10 @@ - (void)updateTheme {
self.navigationItem.titleView = [appDelegate makeFeedTitle:storiesCollection.activeFeed];
}

#if !TARGET_OS_MACCATALYST
self.refreshControl.tintColor = UIColorFromLightDarkRGB(0x0, 0xffffff);
self.refreshControl.backgroundColor = UIColorFromRGB(0xE3E6E0);
#endif

self.searchBar.backgroundColor = UIColorFromRGB(0xE3E6E0);
self.searchBar.tintColor = UIColorFromRGB(0xffffff);
Expand Down Expand Up @@ -3165,6 +3171,7 @@ - (BOOL)canPullToRefresh {
return appDelegate.storiesCollection.activeFeed != nil && !river && !infrequent && !saved && !read && !widget;
}

#if !TARGET_OS_MACCATALYST
- (void)refresh:(UIRefreshControl *)refreshControl {
if (self.canPullToRefresh) {
self.inPullToRefresh_ = YES;
Expand All @@ -3173,10 +3180,13 @@ - (void)refresh:(UIRefreshControl *)refreshControl {
[self finishRefresh];
}
}
#endif

- (void)finishRefresh {
self.inPullToRefresh_ = NO;
#if !TARGET_OS_MACCATALYST
[self.refreshControl endRefreshing];
#endif
}

#pragma mark -
Expand Down
13 changes: 10 additions & 3 deletions clients/ios/Classes/FeedTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,18 @@ - (void)drawRect:(CGRect)r {
BOOL isHighlighted = cell.highlighted || cell.selected;
UIColor *backgroundColor;

#if TARGET_OS_MACCATALYST
backgroundColor = cell.isSocial ? UIColorFromRGB(0xD8E3DB) :
cell.isSearch ? UIColorFromRGB(0xDBDFE6) :
cell.isSaved ? UIColorFromRGB(0xDFDCD6) :
UIColor.clearColor;
#else
backgroundColor = cell.isSocial ? UIColorFromRGB(0xD8E3DB) :
cell.isSearch ? UIColorFromRGB(0xDBDFE6) :
cell.isSaved ? UIColorFromRGB(0xDFDCD6) :
UIColorFromRGB(0xF7F8F5);

#endif

// [backgroundColor set];
self.backgroundColor = backgroundColor;
cell.backgroundColor = backgroundColor;
Expand Down Expand Up @@ -219,7 +226,7 @@ - (void)drawRect:(CGRect)r {
paragraphStyle.alignment = NSTextAlignmentLeft;
CGSize faviconSize;
if (cell.isSocial) {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (!cell.appDelegate.isPhone) {
faviconSize = CGSizeMake(28, 28);
UIImage *feedIcon = [Utilities roundCorneredImage:cell.feedFavicon radius:4 convertToSize:faviconSize];
[feedIcon drawInRect:CGRectMake(9.0, CGRectGetMidY(r)-faviconSize.height/2, faviconSize.width, faviconSize.height)];
Expand All @@ -239,7 +246,7 @@ - (void)drawRect:(CGRect)r {
} else {
faviconSize = CGSizeMake(16, 16);
UIImage *feedIcon = [Utilities roundCorneredImage:cell.feedFavicon radius:4 convertToSize:faviconSize];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (!cell.appDelegate.isPhone) {
[feedIcon drawInRect:CGRectMake(12.0, CGRectGetMidY(r)-faviconSize.height/2, faviconSize.width, faviconSize.height)];
[cell.feedTitle drawInRect:CGRectMake(36.0, titleOffsetY, r.size.width - ([cell.unreadCount offsetWidth] + 36) - 10, font.pointSize*1.4)
withAttributes:@{NSFontAttributeName: font,
Expand Down
2 changes: 2 additions & 0 deletions clients/ios/Classes/FeedsObjCViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ UIGestureRecognizerDelegate, UISearchBarDelegate> {
@property (nonatomic, readwrite) BOOL viewShowingAllFeeds;
@property (nonatomic, readwrite) BOOL interactiveFeedDetailTransition;
@property (nonatomic, readwrite) BOOL isOffline;
#if !TARGET_OS_MACCATALYST
@property (nonatomic) UIRefreshControl *refreshControl;
#endif
@property (nonatomic) UISearchBar *searchBar;
@property (nonatomic, strong) NSArray<NSString *> *searchFeedIds;
@property (nonatomic) NSCache *imageCache;
Expand Down
Loading

0 comments on commit 7272ccf

Please sign in to comment.