Skip to content

Instantly share code, notes, and snippets.

View rid00z's full-sized avatar

Michael Ridland rid00z

View GitHub Profile
@rid00z
rid00z / ContactPageModelTest.cs
Created June 18, 2014 02:32
A example of a test for a Xamarin.Forms App with Mvvm
[TestFixture]
public class ContactPageModelTests
{
[Test]
public static void CreateNewContact()
{
var container = A.Fake<IRootNavigation> ();
TinyIoC.TinyIoCContainer.Current.Register<IRootNavigation> (container);
var db = new DatabaseService (new SQLiteFactory());
@rid00z
rid00z / RootContainerPage.cs
Created June 18, 2014 02:29
A RootNavigation page for a Mvvm in Xamarin.Forms
public class RootContainerPage : MasterDetailPage, IRootNavigation
{
ContentPage _menuPage;
NavigationPage _contactNavPage, _quotesNavPage;
public RootContainerPage ()
{
_contactNavPage = new NavigationPage (BasePageModel.ResolvePageModel<ContactsRootPageModel> (null));
_quotesNavPage = new NavigationPage (BasePageModel.ResolvePageModel<QuotesRootPageModel> (null));
Detail = _contactNavPage;
@rid00z
rid00z / QuotePageModel.cs
Last active August 29, 2015 14:02
A sample PageModel from a Xamain.Forms Mvvm
public class QuotePageModel : BasePageModel
{
IDatabaseService _databaseService;
public Quote Quote { get; set; }
//The database service is automatically injected.
public QuotePageModel (IDatabaseService databaseService)
{
_databaseService = databaseService;
}
@rid00z
rid00z / QuotePage.cs
Created June 18, 2014 02:18
Sample MvvmPage
public class QuotePage : ContentPage
{
//automatically populated when pushed
public QuotePageModel PageModel { get; set; }
public QuotePage ()
{
}
//automatically executed when pushed
@rid00z
rid00z / BaseViewModel.cs
Last active January 24, 2016 08:57
A mini Mvvm for Xamarin.Forms
public abstract class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public virtual void ReverseInit(object value) { }
protected void PushViewModel<T> () where T : BaseViewModel
{
PushViewModel<T> (null);
}
@rid00z
rid00z / MvxFastFileDownloadRequest
Last active December 27, 2015 16:09
Implementing ModernHttpClient in MvvmCross - MvxFastFileDownloadRequest
using System;
using Cirrious.MvvmCross.Plugins.DownloadCache;
using Cirrious.CrossCore.Core;
using System.Net.Http;
using ModernHttpClient;
using System.Threading.Tasks;
using System.IO;
namespace Ridland.MvvmCross.iOS.Plugins
{
@rid00z
rid00z / MvxFastHttpFileDownloader
Created November 7, 2013 10:48
Implementing ModernHttpClient in MvvmCross - MvxFastHttpFileDownloader
using System;
using Cirrious.CrossCore.Core;
using Cirrious.MvvmCross.Plugins.DownloadCache;
using System.Collections.Generic;
using System.Linq;
namespace Ridland.MvvmCross.Plugins
{
public class MvxFastHttpFileDownloader
: MvxLockableObject
@rid00z
rid00z / MvxBindableView
Last active December 22, 2015 21:19
ios Bindable View. Required because of limitations with ViewController, specifically ViewControllers always require a NavigationController which we don't want on all views.
public class MvxBindableView : MvxView, IMvxTouchView, IMvxEventSourceViewController
{
public event EventHandler ViewDidLoadCalled;
public event EventHandler<MvxValueEventArgs<bool>> ViewWillAppearCalled;
public event EventHandler<MvxValueEventArgs<bool>> ViewDidAppearCalled;
public event EventHandler<MvxValueEventArgs<bool>> ViewDidDisappearCalled;
public event EventHandler<MvxValueEventArgs<bool>> ViewWillDisappearCalled;
public event EventHandler DisposeCalled;
@rid00z
rid00z / FollowFingerViewController
Last active December 21, 2015 08:08
ViewController that follows fingers.
public partial class FollowFingerViewController : UIViewController
{
static bool UserInterfaceIdiomIsPhone {
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}
UIView _square;
public FollowFingerViewController ()
{