Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Removed unecessary OAPH #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions ReactiveUIDemo/ReactiveUIDemo.iOS/Main.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using UIKit;
using UIKit;

namespace ReactiveUIDemo.iOS
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\ReactiveUIDemo\ReactiveUIDemo.csproj">
<Project>{F5534636-F3BA-43CC-B276-DAD365A7EC72}</Project>
<Project>{C3060E03-DF8C-4422-8EA2-B80BF41DF56A}</Project>
<Name>ReactiveUIDemo</Name>
</ProjectReference>
</ItemGroup>
Expand Down
4 changes: 1 addition & 3 deletions ReactiveUIDemo/ReactiveUIDemo/Services/#Service.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ReactiveUIDemo.Services
Expand Down
47 changes: 19 additions & 28 deletions ReactiveUIDemo/ReactiveUIDemo/ViewModel/ItemsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using ReactiveUI;
using ReactiveUIDemo.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using ReactiveUI;
using ReactiveUIDemo.Model;

namespace ReactiveUIDemo.ViewModel
{
Expand All @@ -23,35 +19,28 @@ public ReactiveList<Todo> Todos
private Todo _selectedTodo;
public Todo SelectedTodo
{
get => _selectedTodo;
set => this.RaiseAndSetIfChanged(ref _selectedTodo , value);
get => _selectedTodo;
set => this.RaiseAndSetIfChanged(ref _selectedTodo, value);
}

private ObservableAsPropertyHelper<bool> _canAdd;
public bool CanAdd => _canAdd?.Value ?? false;

private string _todoTitl;
public string TodoTitle
{
get { return _todoTitl; }
set {this.RaiseAndSetIfChanged(ref _todoTitl, value); }
set { this.RaiseAndSetIfChanged(ref _todoTitl, value); }
}

public ReactiveCommand AddCommand { get; private set; }

public ItemsViewModel(IScreen hostScreen = null) : base(hostScreen)
{
this.WhenAnyValue(x => x.TodoTitle,
title =>
!String.IsNullOrEmpty(title)).ToProperty(this, x => x.CanAdd, out _canAdd);
var canAdd = this.WhenAnyValue(x => x.TodoTitle, title => !String.IsNullOrEmpty(title));

AddCommand = ReactiveCommand.CreateFromTask( () =>
AddCommand = ReactiveCommand.Create(() =>
{
Todos.Add(new Todo() { Title = TodoTitle });
TodoTitle = string.Empty;
return Task.CompletedTask;

}, this.WhenAnyValue(x => x.CanAdd, canAdd => canAdd && canAdd));
}, canAdd);

//Dont forget to set ChangeTrackingEnabled to true.
Todos = new ReactiveList<Todo>() { ChangeTrackingEnabled = true };
Expand All @@ -64,16 +53,18 @@ public ItemsViewModel(IScreen hostScreen = null) : base(hostScreen)
///Lets detect when ever a todo Item is marked as done
///IF it is, it is sent to the bottom of the list
///Else nothing happens
Todos.ItemChanged.Where(x => x.PropertyName == "IsDone" && x.Sender.IsDone)
Todos
.ItemChanged
.Where(x => x.PropertyName == "IsDone" && x.Sender.IsDone)
.Select(x => x.Sender)
.Subscribe(x =>
{
if (x.IsDone)
{
Todos.Remove(x);
Todos.Add(x);
}
});
{
if (x.IsDone)
{
Todos.Remove(x);
Todos.Add(x);
}
});
}
}
}
66 changes: 23 additions & 43 deletions ReactiveUIDemo/ReactiveUIDemo/ViewModel/#ViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using ReactiveUI;
using ReactiveUIDemo.Services;
using System;
using System.Collections.Generic;
using System.Reactive.Concurrency;
using System.Text;
using System;
using System.Reactive;
using System.Reactive.Linq;
using System.Text.RegularExpressions;
using ReactiveUI;
using ReactiveUIDemo.Services;

namespace ReactiveUIDemo.ViewModel
{
Expand All @@ -27,54 +26,35 @@ public string Password
set => this.RaiseAndSetIfChanged(ref _password, value);
}

/// <summary>
/// This is an Oaph Observable propperty helper,
/// Which is used to determine whether a subsequent action
/// Could be performed or not depending on its value
/// This condition is calculated every time its value changes.
/// </summary>
ObservableAsPropertyHelper<bool> _validLogin;
public bool ValidLogin
{
get { return _validLogin?.Value ?? false; }
}

public ReactiveCommand LoginCommand { get; private set; }

public ReactiveCommand<Unit, bool> LoginCommand { get; private set; }

public LoginViewModel(ILogin login, IScreen hostScreen = null) : base(hostScreen)
{
_loginService = login;

this.WhenAnyValue(x => x.UserName, x => x.Password,
var canLogin = this.WhenAnyValue(x => x.UserName, x => x.Password,
(email, password) =>
(
///Validate the password
//Validate the password
!string.IsNullOrEmpty(password) && password.Length > 5
)
&&
(
///Validate teh email.
//Validate the email.
!string.IsNullOrEmpty(email)
&&
Regex.Matches(email, "^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$").Count == 1
))
.ToProperty(this, v => v.ValidLogin, out _validLogin);

LoginCommand = ReactiveCommand.CreateFromTask(async () =>
{

var lg = await login.Login(_userName, _password);
if (lg)
{
HostScreen.Router
.Navigate
.Execute(new ItemsViewModel())
.Subscribe();
}
}, this.WhenAnyValue(x => x.ValidLogin, x => x.ValidLogin, (validLogin, valid) => ValidLogin && valid));

&&
Regex.Matches(email, "^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$").Count == 1
));

LoginCommand = ReactiveCommand.CreateFromTask(_ => login.Login(_userName, _password), canLogin);

LoginCommand
.Where(logged => logged)
.SelectMany(logged => HostScreen
.Router
.Navigate
.Execute(new ItemsViewModel()))
.Subscribe();
}


}
}