Move HomeBrew Hub to a tab bar

This commit is contained in:
Lior Halphon 2024-09-07 17:39:38 +03:00
parent 8e3d8c4a18
commit 392bc8c0d9
11 changed files with 76 additions and 20 deletions

BIN
iOS/FolderTemplate@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

BIN
iOS/FolderTemplate@3x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

View File

@ -14,6 +14,7 @@
NSArray<GBHubGame *> *_results;
NSString *_resultsTitle;
bool _showingAllGames;
bool _appear;
}
- (instancetype)init
@ -25,10 +26,18 @@
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];

View File

@ -0,0 +1,6 @@
#import <UIKit/UIKit.h>
@interface GBLibraryViewController : UITabBarController
@end

View File

@ -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

View File

@ -1,7 +1,6 @@
#import "GBLoadROMTableViewController.h"
#import "GBROMManager.h"
#import "GBViewController.h"
#import "GBHubViewController.h"
#import <CoreServices/CoreServices.h>
#import <objc/runtime.h>
@ -33,7 +32,7 @@
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 1) return 3;
if (section == 1) return 2;
return [GBROMManager sharedManager].allROMs.count;
}
@ -43,8 +42,7 @@
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;
}
@ -81,7 +79,7 @@
- (NSString *)title
{
return @"ROM Library";
return @"Local Library";
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
@ -143,11 +141,6 @@
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];

View File

@ -61,7 +61,7 @@ static NSString *const tips[] = {
{@"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)},
};

View File

@ -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

View File

@ -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"
@ -723,13 +723,7 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
- (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];
}

BIN
iOS/GlobeTemplate@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
iOS/GlobeTemplate@3x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB