Skip to content

Commit

Permalink
Move HomeBrew Hub to a tab bar
Browse files Browse the repository at this point in the history
  • Loading branch information
LIJI32 committed Sep 7, 2024
1 parent 8e3d8c4 commit 392bc8c
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 20 deletions.
Binary file added iOS/FolderTemplate@2x.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 added iOS/FolderTemplate@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion iOS/GBHubViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ @implementation GBHubViewController
NSArray<GBHubGame *> *_results;
NSString *_resultsTitle;
bool _showingAllGames;
bool _appear;
}

- (instancetype)init
Expand All @@ -25,10 +26,18 @@ - (instancetype)init
object:nil];
_imageCache = [NSMutableDictionary dictionary];
self.tableView.rowHeight = UITableViewAutomaticDimension;
[GBHub.sharedHub refresh];
return self;
}

- (void)viewDidAppear:(BOOL)animated
{
if (!_appear) {
_appear = true;
[GBHub.sharedHub refresh];
}
[super viewDidAppear:animated];
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand Down
6 changes: 6 additions & 0 deletions iOS/GBLibraryViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import <UIKit/UIKit.h>

@interface GBLibraryViewController : UITabBarController

@end

53 changes: 53 additions & 0 deletions iOS/GBLibraryViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#import "GBLibraryViewController.h"
#import "GBLoadROMTableViewController.h"
#import "GBHubViewController.h"
#import "GBViewController.h"

@implementation GBLibraryViewController

+ (UIViewController *)wrapViewController:(UIViewController *)controller
{
UINavigationController *ret = [[UINavigationController alloc] initWithRootViewController:controller];
UIBarButtonItem *close = [[UIBarButtonItem alloc] initWithTitle:@"Close"
style:UIBarButtonItemStylePlain
target:[UIApplication sharedApplication].delegate
action:@selector(dismissViewController)];
[ret.visibleViewController.navigationItem setLeftBarButtonItem:close];
return ret;
}

- (void)viewDidLoad
{
[super viewDidLoad];
self.viewControllers = @[
[self.class wrapViewController:[[GBLoadROMTableViewController alloc] init]],
[self.class wrapViewController:[[GBHubViewController alloc] init]],
];
if (@available(iOS 13.0, *)) {
UIEdgeInsets insets = [UIApplication sharedApplication].keyWindow.safeAreaInsets;
bool hasHomeButton = insets.bottom == 0;
bool isPad = [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad;
NSString *symbol = isPad? @"ipad" : @"iphone";
if (hasHomeButton) {
symbol = [symbol stringByAppendingString:@".homebutton"];
}
else if (!isPad) {
if (@available(iOS 16.1, *)) {
if (MAX(insets.left, MAX(insets.right, MAX(insets.top, insets.bottom))) > 51) {
symbol = @"iphone.gen3";
}
else {
symbol = @"iphone.gen2";
}
}
}
self.viewControllers[0].tabBarItem.image = [UIImage systemImageNamed:symbol] ?: [UIImage systemImageNamed:@"folder.fill"];
self.viewControllers[1].tabBarItem.image = [UIImage systemImageNamed:@"globe"];
}
else {
self.viewControllers[0].tabBarItem.image = [UIImage imageNamed:@"FolderTemplate"];
self.viewControllers[1].tabBarItem.image = [UIImage imageNamed:@"GlobeTemplate"];
}
}

@end
13 changes: 3 additions & 10 deletions iOS/GBLoadROMTableViewController.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import "GBLoadROMTableViewController.h"
#import "GBROMManager.h"
#import "GBViewController.h"
#import "GBHubViewController.h"
#import <CoreServices/CoreServices.h>
#import <objc/runtime.h>

Expand Down Expand Up @@ -33,7 +32,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 1) return 3;
if (section == 1) return 2;
return [GBROMManager sharedManager].allROMs.count;
}

Expand All @@ -43,8 +42,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
switch (indexPath.item) {
case 0: cell.textLabel.text = @"Import ROM files"; break;
case 1: cell.textLabel.text = @"Browse Homebrew Hub"; break;
case 2: cell.textLabel.text = @"Show Library in Files"; break;
case 1: cell.textLabel.text = @"Show Library in Files"; break;
}
return cell;
}
Expand Down Expand Up @@ -81,7 +79,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa

- (NSString *)title
{
return @"ROM Library";
return @"Local Library";
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
Expand Down Expand Up @@ -143,11 +141,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
return;
}
case 1: {
[self.navigationController pushViewController:[[GBHubViewController alloc] init]
animated:true];
return;
}
case 2: {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"shareddocuments://%@", NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true).firstObject]]
options:nil
completionHandler:nil];
Expand Down
2 changes: 1 addition & 1 deletion iOS/GBMenuViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ - (void)viewWillAppear:(BOOL)animated
{@"Connect", @"LinkCableTemplate", SelectorString(openConnectMenu), true},
{@"Model", @"ModelTemplate", SelectorString(changeModel)},
{@"States", @"square.stack", SelectorString(openStates), true},
{@"Cheats", @"CheatsTemplate", SelectorString(openCheats), true}, // TODO
{@"Cheats", @"CheatsTemplate", SelectorString(openCheats), true},
{@"Settings", @"gear", SelectorString(openSettings)},
{@"About", @"info.circle", SelectorString(showAbout)},
};
Expand Down
1 change: 1 addition & 0 deletions iOS/GBViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ typedef enum {
- (void)saveStateToFile:(NSString *)file;
- (bool)loadStateFromFile:(NSString *)file;
- (bool)handleOpenURLs:(NSArray <NSURL *> *)urls openInPlace:(bool)inPlace;
- (void)dismissViewController;
@property (nonatomic) GBRunMode runMode;
@end
10 changes: 2 additions & 8 deletions iOS/GBViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#import "GBViewMetal.h"
#import "GBAudioClient.h"
#import "GBROMManager.h"
#import "GBLoadROMTableViewController.h"
#import "GBLibraryViewController.h"
#import "GBBackgroundView.h"
#import "GBHapticManager.h"
#import "GBMenuViewController.h"
Expand Down Expand Up @@ -723,13 +723,7 @@ - (void)reset

- (void)openLibrary
{
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:[[GBLoadROMTableViewController alloc] init]];
UIBarButtonItem *close = [[UIBarButtonItem alloc] initWithTitle:@"Close"
style:UIBarButtonItemStylePlain
target:self
action:@selector(dismissViewController)];
[controller.visibleViewController.navigationItem setLeftBarButtonItem:close];
[self presentViewController:controller
[self presentViewController:[[GBLibraryViewController alloc] init]
animated:true
completion:nil];
}
Expand Down
Binary file added iOS/GlobeTemplate@2x.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 added iOS/GlobeTemplate@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 392bc8c

Please sign in to comment.