Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

can change presets kinda

roryclear1743c1cf34e8
diff --git a/clearcam/NumberSelectionViewController.h b/clearcam/NumberSelectionViewController.h
new file mode 100644
index 0000000..acf4333
--- /dev/null
+++ b/clearcam/NumberSelectionViewController.h
@@ -0,0 +1,9 @@
+#import <UIKit/UIKit.h>
+
+@interface NumberSelectionViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
+
+@property (nonatomic, strong) NSString *presetKey; // The preset being edited
+@property (nonatomic, strong) NSMutableArray<NSNumber *> *selectedIndexes; // Selected numbers (0-79)
+@property (nonatomic, copy) void (^completionHandler)(NSArray<NSNumber *> *selectedIndexes); // Callback to save the selected numbers
+
+@end
diff --git a/clearcam/NumberSelectionViewController.m b/clearcam/NumberSelectionViewController.m
new file mode 100644
index 0000000..cffa145
--- /dev/null
+++ b/clearcam/NumberSelectionViewController.m
@@ -0,0 +1,88 @@
+#import <UIKit/UIKit.h>
+
+@interface NumberSelectionViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
+
+@property (nonatomic, strong) NSString *presetKey; // The preset being edited
+@property (nonatomic, strong) NSMutableArray<NSNumber *> *selectedIndexes; // Selected numbers (0-79)
+@property (nonatomic, copy) void (^completionHandler)(NSArray<NSNumber *> *selectedIndexes); // Callback to save the selected numbers
+@property (nonatomic, strong) NSArray<NSString *> *classes; // Selected numbers (0-79)
+
+@end
+
+@implementation NumberSelectionViewController
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ self.classes = @[
+ @"person", @"bicycle", @"car", @"motorcycle", @"airplane",
+ @"bus", @"train", @"truck", @"boat", @"traffic light",
+ @"fire hydrant", @"stop sign", @"parking meter", @"bench",
+ @"bird", @"cat", @"dog", @"horse", @"sheep", @"cow",
+ @"elephant", @"bear", @"zebra", @"giraffe", @"backpack",
+ @"umbrella", @"handbag", @"tie", @"suitcase", @"frisbee",
+ @"skis", @"snowboard", @"sports ball", @"kite", @"baseball bat",
+ @"baseball glove", @"skateboard", @"surfboard", @"tennis racket",
+ @"bottle", @"wine glass", @"cup", @"fork", @"knife",
+ @"spoon", @"bowl", @"banana", @"apple", @"sandwich",
+ @"orange", @"broccoli", @"carrot", @"hot dog", @"pizza",
+ @"donut", @"cake", @"chair", @"couch", @"potted plant",
+ @"bed", @"dining table", @"toilet", @"tv", @"laptop",
+ @"mouse", @"remote", @"keyboard", @"cell phone", @"microwave",
+ @"oven", @"toaster", @"sink", @"refrigerator", @"book",
+ @"clock", @"vase", @"scissors", @"teddy bear", @"hair drier",
+ @"toothbrush"
+ ];
+
+ self.title = self.presetKey ?: @"New Preset";
+ self.view.backgroundColor = [UIColor systemBackgroundColor];
+
+ // Create table view
+ UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
+ tableView.delegate = self;
+ tableView.dataSource = self;
+ [self.view addSubview:tableView];
+
+ // Add a "Save" button
+ UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(savePreset)];
+ self.navigationItem.rightBarButtonItem = saveButton;
+}
+
+#pragma mark - UITableView DataSource
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ return 80; // Numbers 0-79
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NumberCell"];
+ if (!cell) {
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"NumberCell"];
+ }
+ cell.textLabel.text = [NSString stringWithFormat:@"%@", self.classes[indexPath.row]];
+ cell.accessoryType = [self.selectedIndexes containsObject:@(indexPath.row)] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
+ return cell;
+}
+
+#pragma mark - UITableView Delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ NSNumber *number = @(indexPath.row);
+ if ([self.selectedIndexes containsObject:number]) {
+ [self.selectedIndexes removeObject:number];
+ } else {
+ [self.selectedIndexes addObject:number];
+ }
+ [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
+}
+
+#pragma mark - Save Preset
+
+- (void)savePreset {
+ if (self.completionHandler) {
+ self.completionHandler(self.selectedIndexes);
+ }
+ [self.navigationController popViewControllerAnimated:YES];
+}
+
+@end
diff --git a/clearcam/SettingsViewController.m b/clearcam/SettingsViewController.m
index 2c7519f..1f00eac 100644
--- a/clearcam/SettingsViewController.m
+++ b/clearcam/SettingsViewController.m
@@ -1,5 +1,6 @@
#import "SettingsViewController.h"
-#import "SettingsManager.h" // Import SettingsManager
+#import "SettingsManager.h"
+#import "NumberSelectionViewController.h" // Import the new class
@interface SettingsViewController () <UITableViewDelegate, UITableViewDataSource>
@@ -38,7 +39,7 @@
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 2; // One for resolution, one for YOLO indexes key
+ return 3; // One for resolution, one for YOLO indexes key, one for managing presets
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -60,6 +61,9 @@
} else if (indexPath.row == 1) {
cell.textLabel.text = @"Detect objects";
cell.detailTextLabel.text = self.selectedPresetKey;
+ } else if (indexPath.row == 2) {
+ cell.textLabel.text = @"Manage Presets";
+ cell.detailTextLabel.text = nil; // No detail text for this row
}
return cell;
@@ -72,6 +76,8 @@
[self showResolutionPicker];
} else if (indexPath.row == 1) {
[self showYoloIndexesPicker];
+ } else if (indexPath.row == 2) {
+ [self showPresetManagementOptions];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
@@ -150,4 +156,123 @@
[self presentViewController:alert animated:YES completion:nil];
}
+#pragma mark - Preset Management
+
+- (void)showPresetManagementOptions {
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Manage Presets"
+ message:nil
+ preferredStyle:UIAlertControllerStyleActionSheet];
+
+ // Add Preset
+ UIAlertAction *addAction = [UIAlertAction actionWithTitle:@"Add Preset"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction * _Nonnull action) {
+ [self showAddPresetDialog];
+ }];
+ [alert addAction:addAction];
+
+ // Edit Preset
+ UIAlertAction *editAction = [UIAlertAction actionWithTitle:@"Edit Preset"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction * _Nonnull action) {
+ [self showEditPresetDialog];
+ }];
+ [alert addAction:editAction];
+
+ // Delete Preset
+ UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"Delete Preset"
+ style:UIAlertActionStyleDestructive
+ handler:^(UIAlertAction * _Nonnull action) {
+ [self showDeletePresetDialog];
+ }];
+ [alert addAction:deleteAction];
+
+ // Cancel
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
+ style:UIAlertActionStyleCancel
+ handler:nil];
+ [alert addAction:cancelAction];
+
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
+- (void)showAddPresetDialog {
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Add Preset"
+ message:@"Enter a name for the new preset"
+ preferredStyle:UIAlertControllerStyleAlert];
+ [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
+ textField.placeholder = @"Preset Name";
+ }];
+ UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"Save"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction * _Nonnull action) {
+ NSString *presetName = alert.textFields.firstObject.text;
+ if (presetName.length > 0) {
+ [self showNumberSelectionForPreset:presetName selectedIndexes:@[]];
+ }
+ }];
+ [alert addAction:saveAction];
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
+- (void)showEditPresetDialog {
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Edit Preset"
+ message:@"Select a preset to edit"
+ preferredStyle:UIAlertControllerStyleActionSheet];
+ SettingsManager *settingsManager = [SettingsManager sharedManager];
+ NSArray *presetKeys = [settingsManager.presets allKeys];
+ for (NSString *presetKey in presetKeys) {
+ UIAlertAction *action = [UIAlertAction actionWithTitle:presetKey
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction * _Nonnull action) {
+ NSArray *selectedIndexes = settingsManager.presets[presetKey];
+ [self showNumberSelectionForPreset:presetKey selectedIndexes:selectedIndexes];
+ }];
+ [alert addAction:action];
+ }
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
+ style:UIAlertActionStyleCancel
+ handler:nil];
+ [alert addAction:cancelAction];
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
+- (void)showNumberSelectionForPreset:(NSString *)presetKey selectedIndexes:(NSArray<NSNumber *> *)selectedIndexes {
+ NumberSelectionViewController *numberSelectionVC = [[NumberSelectionViewController alloc] init];
+ numberSelectionVC.presetKey = presetKey;
+ numberSelectionVC.selectedIndexes = [selectedIndexes mutableCopy];
+ numberSelectionVC.completionHandler = ^(NSArray<NSNumber *> *selectedIndexes) {
+ SettingsManager *settingsManager = [SettingsManager sharedManager];
+ settingsManager.presets[presetKey] = selectedIndexes;
+ [[NSUserDefaults standardUserDefaults] synchronize];
+ [self.tableView reloadData];
+ };
+ [self.navigationController pushViewController:numberSelectionVC animated:YES];
+}
+
+- (void)showDeletePresetDialog {
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Delete Preset"
+ message:@"Select a preset to delete"
+ preferredStyle:UIAlertControllerStyleActionSheet];
+ SettingsManager *settingsManager = [SettingsManager sharedManager];
+ NSArray *presetKeys = [settingsManager.presets allKeys];
+ for (NSString *presetKey in presetKeys) {
+ if (![presetKey isEqualToString:@"all"]) { // Prevent deletion of the "all" preset
+ UIAlertAction *action = [UIAlertAction actionWithTitle:presetKey
+ style:UIAlertActionStyleDestructive
+ handler:^(UIAlertAction * _Nonnull action) {
+ [settingsManager.presets removeObjectForKey:presetKey];
+ [[NSUserDefaults standardUserDefaults] synchronize];
+ [self.tableView reloadData];
+ }];
+ [alert addAction:action];
+ }
+ }
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
+ style:UIAlertActionStyleCancel
+ handler:nil];
+ [alert addAction:cancelAction];
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
@end