add openhack files

This commit is contained in:
Ryan Peters
2022-11-03 16:41:13 -04:00
commit b2c9f7e29f
920 changed files with 118861 additions and 0 deletions

View File

@ -0,0 +1,134 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
using System;
using Foundation;
using UIKit;
using MyDriving.Model;
using MyDriving.ViewModel;
namespace MyDriving.iOS
{
public partial class SettingsDetailViewController : UIViewController
{
public SettingsViewModel ViewModel;
public SettingsDetailViewController(IntPtr handle) : base(handle)
{
}
public string SettingKey { get; set; }
public Setting Setting { get; set; }
public override void ViewDidLoad()
{
base.ViewDidLoad();
NavigationItem.Title = Setting.Name;
settingsDetailTableView.Source = new SettingsDetailTableViewSource(SettingKey, Setting);
NSNotificationCenter.DefaultCenter.AddObserver(new NSString("SettingTextFieldChanged"),
HandleSettingChangedNotification);
}
void HandleSettingChangedNotification(NSNotification obj)
{
var dict = (NSDictionary) obj.Object;
var row = dict.ObjectForKey(new NSString("Row")) as NSString;
var section = dict.ObjectForKey(new NSString("Section")) as NSString;
var value = dict.ObjectForKey(new NSString("Value")) as NSString;
ViewModel.SettingsData[section.ToString()][Int32.Parse(row.ToString())].Value = value.ToString();
}
}
public class SettingsDetailTableViewSource : UITableViewSource
{
readonly string key;
readonly Setting setting;
public SettingsDetailTableViewSource(string key, Setting setting)
{
this.setting = setting;
this.key = key;
}
public override string TitleForHeader(UITableView tableView, nint section)
{
return setting.Name;
}
public override void WillDisplayHeaderView(UITableView tableView, UIView headerView, nint section)
{
var header = headerView as UITableViewHeaderFooterView;
header.TextLabel.TextColor = "5C5C5C".ToUIColor();
header.TextLabel.Font = UIFont.FromName("AvenirNext-Medium", 16);
header.TextLabel.Text = TitleForHeader(tableView, section);
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
if (!setting.IsButton)
{
setting.Value = setting.PossibleValues[indexPath.Row];
var cells = tableView.VisibleCells;
int i = 0;
foreach (var cell in cells)
{
var value = setting.PossibleValues[i];
cell.Accessory = setting.Value != value
? UITableViewCellAccessory.None
: UITableViewCellAccessory.Checkmark;
i++;
}
NSNotificationCenter.DefaultCenter.PostNotificationName("RefreshTripUnits", null);
NSNotificationCenter.DefaultCenter.PostNotificationName("RefreshSettingsTable", null);
}
}
public override nint RowsInSection(UITableView tableview, nint section)
{
if (!setting.IsTextField)
return setting.PossibleValues.Count;
else
return 1;
}
public override nint NumberOfSections(UITableView tableView)
{
return 1;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
if (!setting.IsTextField)
{
var cell = tableView.DequeueReusableCell("SETTING__DETAIL_VALUE_CELL") as SettingDetailTableViewCell;
cell.Name = setting.PossibleValues[indexPath.Row];
cell.Accessory = UITableViewCellAccessory.None;
if (cell.Name == setting.Value)
cell.Accessory = UITableViewCellAccessory.Checkmark;
return cell;
}
else
{
var cell =
tableView.DequeueReusableCell("SETTING_DETAIL_TEXTFIELD_CELL") as
SettingDetailTextFieldTableViewCell;
cell.Row = indexPath.Row.ToString();
cell.Section = key;
cell.Value = setting.Value ?? string.Empty;
return cell;
}
}
}
}

View File

@ -0,0 +1,29 @@
// WARNING
//
// This file has been generated automatically by Visual Studio from the outlets and
// actions declared in your storyboard file.
// Manual changes to this file will not be maintained.
//
using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;
namespace MyDriving.iOS
{
[Register ("SettingsDetailViewController")]
partial class SettingsDetailViewController
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIKit.UITableView settingsDetailTableView { get; set; }
void ReleaseDesignerOutlets ()
{
if (settingsDetailTableView != null) {
settingsDetailTableView.Dispose ();
settingsDetailTableView = null;
}
}
}
}

View File

@ -0,0 +1,164 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
using Foundation;
using System;
using System.Collections.Generic;
using UIKit;
using MyDriving.Model;
using MyDriving.ViewModel;
using HockeyApp;
namespace MyDriving.iOS
{
partial class SettingsViewController : UIViewController
{
string[] keys;
public SettingsViewController(IntPtr handle) : base(handle)
{
}
SettingsViewModel ViewModel { get; set; }
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Wire up view model
ViewModel = new SettingsViewModel();
keys = new string[ViewModel.SettingsData.Count];
int i = 0;
foreach (var grouping in ViewModel.SettingsData)
{
keys[i] = grouping.Key;
i++;
}
// Wire up table source
settingsTableView.Source = new SettingsDataSource(ViewModel, keys);
btnLogout.SetTitle("Leave Feedback", UIControlState.Normal);
btnLogout.TouchUpInside += LeaveFeedbackButtonClicked;
NSNotificationCenter.DefaultCenter.AddObserver(new NSString("RefreshSettingsTable"),
HandleReloadTableNotification);
}
public override bool ShouldPerformSegue(string segueIdentifier, NSObject sender)
{
var cell = (SettingTableViewCell) sender;
if (cell.Accessory == UITableViewCellAccessory.None)
return false;
else
return true;
}
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
{
if (segue.Identifier == "settingsDetailSegue")
{
var controller = segue.DestinationViewController as SettingsDetailViewController;
var cell = settingsTableView.IndexPathForCell(sender as UITableViewCell);
var row = cell.Row;
var section = cell.Section;
var setting = ViewModel.SettingsData[keys[section]][row];
settingsTableView.DeselectRow(settingsTableView.IndexPathForSelectedRow, true);
controller.Setting = setting;
controller.ViewModel = ViewModel;
controller.SettingKey = keys[cell.Section];
}
}
void LeaveFeedbackButtonClicked(object sender, EventArgs e)
{
BITHockeyManager.SharedHockeyManager.FeedbackManager.ShowFeedbackComposeView();
}
void HandleReloadTableNotification(NSNotification obj)
{
InvokeOnMainThread(delegate { settingsTableView.ReloadData(); });
}
}
public class SettingsDataSource : UITableViewSource
{
readonly Dictionary<string, List<Setting>> data;
readonly string[] keys;
readonly SettingsViewModel viewModel;
public SettingsDataSource(SettingsViewModel viewModel, string[] keys)
{
this.viewModel = viewModel;
data = viewModel.SettingsData;
this.keys = keys;
}
public override void WillDisplayHeaderView(UITableView tableView, UIView headerView, nint section)
{
var header = headerView as UITableViewHeaderFooterView;
header.TextLabel.TextColor = "5C5C5C".ToUIColor();
header.TextLabel.Font = UIFont.FromName("AvenirNext-Medium", 16);
header.TextLabel.Text = TitleForHeader(tableView, section);
}
public override async void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
var setting = data[keys[indexPath.Section]][indexPath.Row];
if (setting.IsButton)
{
if (setting.ButtonUrl != "Permissions")
{
await viewModel.ExecuteOpenBrowserCommandAsync(setting.ButtonUrl);
}
else
{
var url = NSUrl.FromString(UIApplication.OpenSettingsUrlString);
UIApplication.SharedApplication.OpenUrl(url);
}
}
}
public override nint NumberOfSections(UITableView tableView)
{
return keys.Length;
}
public override string TitleForHeader(UITableView tableView, nint section)
{
return keys[section];
}
public override nint RowsInSection(UITableView tableView, nint section)
{
return data[keys[section]].Count;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell("SETTING_VALUE_CELL") as SettingTableViewCell;
var setting = data[keys[indexPath.Section]][indexPath.Row];
if (setting.IsButton)
{
cell.Accessory = UITableViewCellAccessory.None;
cell.Value = "";
}
else
{
cell.Value = !String.IsNullOrEmpty(setting.Value) ? cell.Value = setting.Value : cell.Value = "";
}
cell.Name = setting.Name;
return cell;
}
}
}

View File

@ -0,0 +1,38 @@
// WARNING
//
// This file has been generated automatically by Visual Studio from the outlets and
// actions declared in your storyboard file.
// Manual changes to this file will not be maintained.
//
using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;
namespace MyDriving.iOS
{
[Register ("SettingsViewController")]
partial class SettingsViewController
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIKit.UIButton btnLogout { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIKit.UITableView settingsTableView { get; set; }
void ReleaseDesignerOutlets ()
{
if (btnLogout != null) {
btnLogout.Dispose ();
btnLogout = null;
}
if (settingsTableView != null) {
settingsTableView.Dispose ();
settingsTableView = null;
}
}
}
}