add openhack files
This commit is contained in:
116
MobileApps/MyDriving/MyDriving/Helpers/RelayCommand.cs
Normal file
116
MobileApps/MyDriving/MyDriving/Helpers/RelayCommand.cs
Normal file
@ -0,0 +1,116 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace MyDriving.Helpers
|
||||
{
|
||||
public class RelayCommand : ICommand
|
||||
{
|
||||
private readonly Func<bool> canExecute;
|
||||
private readonly Action handler;
|
||||
private bool isEnabled;
|
||||
|
||||
public RelayCommand(Action handler, Func<bool> canExecute = null)
|
||||
{
|
||||
this.handler = handler;
|
||||
this.canExecute = canExecute;
|
||||
if (canExecute == null)
|
||||
isEnabled = true;
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get { return isEnabled; }
|
||||
set
|
||||
{
|
||||
if (value != isEnabled)
|
||||
{
|
||||
isEnabled = value;
|
||||
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
if (canExecute != null)
|
||||
IsEnabled = canExecute();
|
||||
|
||||
return IsEnabled;
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used to raise the <see cref="CanExecuteChanged" /> event
|
||||
/// to indicate that the return value of the <see cref="CanExecute" />
|
||||
/// method has changed.
|
||||
/// </summary>
|
||||
public void RaiseCanExecuteChanged()
|
||||
{
|
||||
var handler = CanExecuteChanged;
|
||||
handler?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public class RelayCommand<T> : ICommand
|
||||
{
|
||||
private readonly Func<T, bool> canExecute;
|
||||
private readonly Action<T> handler;
|
||||
private bool isEnabled = true;
|
||||
|
||||
public RelayCommand(Action<T> handler, Func<T, bool> canExecute = null)
|
||||
{
|
||||
this.handler = handler;
|
||||
this.canExecute = canExecute;
|
||||
if (canExecute == null)
|
||||
isEnabled = true;
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get { return isEnabled; }
|
||||
set
|
||||
{
|
||||
if (value != isEnabled)
|
||||
{
|
||||
isEnabled = value;
|
||||
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
if (canExecute != null)
|
||||
IsEnabled = canExecute((T) parameter);
|
||||
|
||||
return IsEnabled;
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
handler((T) parameter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used to raise the <see cref="CanExecuteChanged" /> event
|
||||
/// to indicate that the return value of the <see cref="CanExecute" />
|
||||
/// method has changed.
|
||||
/// </summary>
|
||||
public void RaiseCanExecuteChanged()
|
||||
{
|
||||
var handler = CanExecuteChanged;
|
||||
handler?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
43
MobileApps/MyDriving/MyDriving/Helpers/Settings.cs
Normal file
43
MobileApps/MyDriving/MyDriving/Helpers/Settings.cs
Normal file
@ -0,0 +1,43 @@
|
||||
// Helpers/Settings.cs
|
||||
using Plugin.Settings;
|
||||
using Plugin.Settings.Abstractions;
|
||||
|
||||
namespace MyDriving.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the Settings static class that can be used in your Core solution or in any
|
||||
/// of your client applications. All settings are laid out the same exact way with getters
|
||||
/// and setters.
|
||||
/// </summary>
|
||||
public static class Settings
|
||||
{
|
||||
private static ISettings AppSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return CrossSettings.Current;
|
||||
}
|
||||
}
|
||||
|
||||
#region Setting Constants
|
||||
|
||||
private const string SettingsKey = "settings_key";
|
||||
private static readonly string SettingsDefault = string.Empty;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public static string GeneralSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return AppSettings.GetValueOrDefault(SettingsKey, SettingsDefault);
|
||||
}
|
||||
set
|
||||
{
|
||||
AppSettings.AddOrUpdateValue(SettingsKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
35
MobileApps/MyDriving/MyDriving/Helpers/UserProfile.cs
Normal file
35
MobileApps/MyDriving/MyDriving/Helpers/UserProfile.cs
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
||||
|
||||
using Microsoft.WindowsAzure.MobileServices;
|
||||
using System.Threading.Tasks;
|
||||
using MyDriving.Utils;
|
||||
using MyDriving.DataObjects;
|
||||
|
||||
namespace MyDriving.Helpers
|
||||
{
|
||||
public class UserProfileHelper
|
||||
{
|
||||
//returns info for the authenticated user
|
||||
public static async Task<UserProfile> GetUserProfileAsync(IMobileServiceClient client)
|
||||
{
|
||||
var userprof =
|
||||
await client.InvokeApiAsync<UserProfile>(
|
||||
"UserInfo",
|
||||
System.Net.Http.HttpMethod.Get,
|
||||
null);
|
||||
|
||||
Settings.Current.UserFirstName = userprof?.FirstName ?? string.Empty;
|
||||
Settings.Current.UserLastName = userprof?.LastName ?? string.Empty;
|
||||
Settings.Current.UserProfileUrl = userprof?.ProfilePictureUri ?? string.Empty;
|
||||
Settings.Current.UserUID = userprof?.UserId ?? string.Empty;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(userprof?.ProfilePictureUri))
|
||||
{
|
||||
Settings.Current.UserProfileUrl = "http://appstudio.windows.com/Content/img/temp/icon-user.png";
|
||||
}
|
||||
|
||||
return userprof;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user