Skip to content

Commit

Permalink
Enforce same style everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
martijn00 committed Sep 30, 2019
1 parent 14dd8e2 commit 683f34e
Show file tree
Hide file tree
Showing 89 changed files with 2,049 additions and 1,763 deletions.
2 changes: 1 addition & 1 deletion Samples/MaterialMvvmSample.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void OnCreate(Bundle savedInstanceState)

var app = CommonServiceLocator.ServiceLocator.Current.GetInstance<App>();

this.LoadApplication(app);
LoadApplication(app);
}

public override void OnBackPressed()
Expand Down
2 changes: 1 addition & 1 deletion Samples/MaterialMvvmSample.Core/AppContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Setup()
{
var containerBuilder = new ContainerBuilder();

this.RegisterServices(containerBuilder);
RegisterServices(containerBuilder);

var container = containerBuilder.Build();

Expand Down
2 changes: 1 addition & 1 deletion Samples/MaterialMvvmSample.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary
var appContainer = new PlatformContainer();
appContainer.Setup();

this.LoadApplication(CommonServiceLocator.ServiceLocator.Current.GetInstance<App>());
LoadApplication(CommonServiceLocator.ServiceLocator.Current.GetInstance<App>());

return base.FinishedLaunching(uiApplication, launchOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion Samples/MaterialMvvmSample.iOS/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace MaterialMvvmSample.iOS
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
private static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
Expand Down
2 changes: 1 addition & 1 deletion Samples/MaterialMvvmSample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class App : Application
{
public App(INavigationService navigationService)
{
this.InitializeComponent();
InitializeComponent();

XF.Material.Forms.Material.Init(this, "Material.Style");

Expand Down
22 changes: 13 additions & 9 deletions Samples/MaterialMvvmSample/Controls/CustomNavigationPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,47 @@ public CustomNavigationPage(string rootViewName, object parameter = null) : base

public async Task PopViewAsync()
{
await this.Navigation.PopAsync(true);
await Navigation.PopAsync(true);
}

public async Task PushViewAsync(string rootViewName, object parameter = null)
{
_currentNavigationParameter = parameter;
var view = ViewFactory.GetView(rootViewName);
await this.Navigation.PushAsync(view, true);
await Navigation.PushAsync(view, true);
}

public async Task PushModalAsync(string rootViewName, object parameter = null)
{
_currentNavigationParameter = parameter;
var view = ViewFactory.GetView(rootViewName);
await this.Navigation.PushModalAsync(view, true);
await Navigation.PushModalAsync(view, true);
}

public async Task PopModalAsync()
{
await this.Navigation.PopModalAsync(true);
await Navigation.PopModalAsync(true);
}

protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);

if (propertyName == nameof(this.RootPage) && this.RootPage != null)
if (propertyName == nameof(RootPage) && RootPage != null)
{
this.RootPage.Appearing += this.AppearingHandler;
RootPage.Appearing += AppearingHandler;
}
}

protected override void OnPagePush(Page page)
{
base.OnPagePush(page);

if (!(page.BindingContext is BaseViewModel viewModel)) return;
if (!(page.BindingContext is BaseViewModel viewModel))
{
return;
}

viewModel?.OnViewPushed(_currentNavigationParameter);
_currentNavigationParameter = null;
}
Expand All @@ -72,10 +76,10 @@ protected override void OnPagePop(Page previousPage, Page poppedPage)

private void AppearingHandler(object sender, EventArgs e)
{
var viewModel = this.RootPage.BindingContext as BaseViewModel;
var viewModel = RootPage.BindingContext as BaseViewModel;
viewModel?.OnViewPushed(_currentNavigationParameter);
_currentNavigationParameter = null;
this.RootPage.Appearing -= this.AppearingHandler;
RootPage.Appearing -= AppearingHandler;
}
}
}
6 changes: 3 additions & 3 deletions Samples/MaterialMvvmSample/ViewModels/BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public abstract class BaseViewModel : PropertyChangeAware, ICleanUp

protected BaseViewModel()
{
this.ServiceLocator = CommonServiceLocator.ServiceLocator.Current;
this.Navigation = this.ServiceLocator.GetInstance<INavigationService>();
ServiceLocator = CommonServiceLocator.ServiceLocator.Current;
Navigation = ServiceLocator.GetInstance<INavigationService>();
}

/// <summary>
Expand All @@ -26,7 +26,7 @@ public virtual void OnViewPushed(object navigationParameter = null) { }
/// </summary>
public virtual void OnViewPopped()
{
this.CleanUp();
CleanUp();
}

public virtual void CleanUp() { }
Expand Down
56 changes: 28 additions & 28 deletions Samples/MaterialMvvmSample/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MainViewModel(IJobDialogService dialogService)
{
_dialogService = dialogService;

this.Models = new ObservableCollection<TestModel>()
Models = new ObservableCollection<TestModel>()
{
new TestModel
{
Expand All @@ -39,7 +39,7 @@ public MainViewModel(IJobDialogService dialogService)
Id = Guid.NewGuid().ToString("N")
}
};
this.SelectedFilters = new List<int>();
SelectedFilters = new List<int>();
}

public Color PrimaryColor => Color.Red;
Expand All @@ -62,25 +62,25 @@ public string SelectedChoice
get => _selectedChoice;
set
{
this.HasError = string.Equals(value, Choices[0]);
this.Set(ref _selectedChoice, value);
HasError = string.Equals(value, Choices[0]);
Set(ref _selectedChoice, value);
}
}

private bool _hasError;
public bool HasError
{
get => _hasError;
set => this.Set(ref _hasError, value);
set => Set(ref _hasError, value);
}

public static string[] Filters => new string[] { "None", "Alhpabetical" };

public string[] ListActions => new string[] { "Add job", "Sort" };

public ICommand ListMenuCommand => new Command<MaterialMenuResult>(async (s) => await this.ListMenuSelected(s));
public ICommand ListMenuCommand => new Command<MaterialMenuResult>(async (s) => await ListMenuSelected(s));

public ICommand MenuCommand => new Command<MaterialMenuResult>(async (s) => await this.MenuSelected(s));
public ICommand MenuCommand => new Command<MaterialMenuResult>(async (s) => await MenuSelected(s));

public ICommand FiltersSelectedCommand => new Command<int[]>((s) =>
{
Expand All @@ -98,47 +98,47 @@ public bool HasError
"ERNI Development Center Philippines, Inc., Bern, Switzerland"
};

public ICommand JobSelectedCommand => new Command<string>(async (s) => await this.ViewItemSelected(s));
public ICommand JobSelectedCommand => new Command<string>(async (s) => await ViewItemSelected(s));

public ICommand EmailFocusCommand => new Command<bool>((s) =>
{
if (!s && this.Email?.Length > 3)
if (!s && Email?.Length > 3)
{
this.EmailHasError = true;
EmailHasError = true;
}
else if (!s && this.Email?.Length <= 3)
else if (!s && Email?.Length <= 3)
{
this.EmailHasError = false;
EmailHasError = false;
}
});

private bool _emailHasError;
public bool EmailHasError
{
get => _emailHasError;
set => this.Set(ref _emailHasError, value);
set => Set(ref _emailHasError, value);
}

private string _email;
public string Email
{
get => _email;
set => this.Set(ref _email, value);
set => Set(ref _email, value);
}

private ObservableCollection<TestModel> _models;
public ObservableCollection<TestModel> Models
{
get => _models;
set => this.Set(ref _models, value);
set => Set(ref _models, value);
}

private List<int> _selectedFilters;
public List<int> SelectedFilters
{
get => _selectedFilters;
set => this.Set(ref _selectedFilters, value);
set => Set(ref _selectedFilters, value);
}

private async Task ListMenuSelected(MaterialMenuResult s)
Expand All @@ -149,13 +149,13 @@ private async Task ListMenuSelected(MaterialMenuResult s)
{
var result = await _dialogService.AddNewJob();

if (this.Models.Any(m => m.Title == result))
if (Models.Any(m => m.Title == result))
{
await _dialogService.AlertExistingJob(result);
}
else if (!string.IsNullOrEmpty(result))
{
this.Models.Where(m => m.IsNew).ForEach(m => m.IsNew = false);
Models.Where(m => m.IsNew).ForEach(m => m.IsNew = false);

var model = new TestModel
{
Expand All @@ -164,30 +164,30 @@ private async Task ListMenuSelected(MaterialMenuResult s)
IsNew = true
};

this.Models.Add(model);
Models.Add(model);
}

break;
}
case 1:
this.Models = new ObservableCollection<TestModel>(this.Models.OrderBy(m => m.Title));
Models = new ObservableCollection<TestModel>(Models.OrderBy(m => m.Title));
break;
case 2:
this.SelectedFilters = new List<int>();
SelectedFilters = new List<int>();
break;
}
}

private async Task ViewItemSelected(string id)
{
var selectedModel = this.Models.FirstOrDefault(m => m.Id == id);
var selectedModel = Models.FirstOrDefault(m => m.Id == id);

await this.Navigation.PushAsync(ViewNames.SecondView, selectedModel);
await Navigation.PushAsync(ViewNames.SecondView, selectedModel);
}

private async Task MenuSelected(MaterialMenuResult i)
{
var model = this.Models.FirstOrDefault(m => m.Title == (string)i.Parameter);
var model = Models.FirstOrDefault(m => m.Title == (string)i.Parameter);

switch (i.Index)
{
Expand All @@ -213,7 +213,7 @@ private async Task MenuSelected(MaterialMenuResult i)

if (confirmed == true)
{
this.Models.Remove(model);
Models.Remove(model);

await _dialogService.JobDeleted();
}
Expand All @@ -234,19 +234,19 @@ public class TestModel : PropertyChangeAware
public string Id
{
get => _id;
set => this.Set(ref _id, value);
set => Set(ref _id, value);
}

public string Title
{
get => _title;
set => this.Set(ref _title, value);
set => Set(ref _title, value);
}

public bool IsNew
{
get => _isNew;
set => this.Set(ref _isNew, value);
set => Set(ref _isNew, value);
}
}
}
12 changes: 8 additions & 4 deletions Samples/MaterialMvvmSample/ViewModels/PropertyChangeAware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ public abstract class PropertyChangeAware : INotifyPropertyChanged
{
if (!EqualityComparer<T>.Default.Equals(field, default(T)))
{
if (field.Equals(newValue)) return;
if (field.Equals(newValue))
{
return;
}

field = newValue;
this.OnPropertyChanged(propertyName);
OnPropertyChanged(propertyName);
}

else if (!EqualityComparer<T>.Default.Equals(newValue, default(T)))
{
field = newValue;
this.OnPropertyChanged(propertyName);
OnPropertyChanged(propertyName);
}
}

Expand All @@ -45,7 +49,7 @@ public abstract class PropertyChangeAware : INotifyPropertyChanged
/// <param name="propertyName">The name of the property who's value has changed.</param>
protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
4 changes: 2 additions & 2 deletions Samples/MaterialMvvmSample/ViewModels/SecondViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public class SecondViewModel : BaseViewModel
public string JobTitle
{
get => _jobTitle;
set => this.Set(ref _jobTitle, value);
set => Set(ref _jobTitle, value);
}

public override void OnViewPushed(object navigationParameter = null)
{
var selectedJob = (TestModel)navigationParameter;
this.JobTitle = selectedJob?.Title;
JobTitle = selectedJob?.Title;
}
}
}
6 changes: 3 additions & 3 deletions Samples/MaterialMvvmSample/Views/BaseView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public abstract class BaseView<TViewModel> : ContentPage where TViewModel : Base

protected BaseView()
{
this.ViewModel = CommonServiceLocator.ServiceLocator.Current.GetInstance<TViewModel>();
this.BindingContext = this.ViewModel;
this.On<iOS>().SetUseSafeArea(true);
ViewModel = CommonServiceLocator.ServiceLocator.Current.GetInstance<TViewModel>();
BindingContext = ViewModel;
On<iOS>().SetUseSafeArea(true);
}
}
}
2 changes: 1 addition & 1 deletion Samples/MaterialMvvmSample/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public partial class MainView : BaseMainView
{
public MainView()
{
this.InitializeComponent();
InitializeComponent();
}
}

Expand Down
Loading

0 comments on commit 683f34e

Please sign in to comment.