Skip to content

Instantly share code, notes, and snippets.

View rid00z's full-sized avatar

Michael Ridland rid00z

View GitHub Profile
@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 / 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 / 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 / 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 / JellyBeanGraphCalculator.cs
Last active August 29, 2015 14:05
JellyBeanGraphCalculator
public class JellyBeanGraphCalculator
{
IDataSource _datasource;
public JellyBeanGraphCalculator (IDataSource datasource)
{
_datasource = datasource;
}
public IEnumerable<JellyBeanGraphData> GetGraphData()
{
@rid00z
rid00z / LocalDataSource.cs
Created August 19, 2014 11:42
Local Data Source
public class LocalDataSource : IDataSource
{
SQLiteConnection _sqliteConnection;
public LocalDataSource ()
{
_sqliteConnection = Xamarin.Forms.DependencyService.Get<ISQLiteFactory> ().GetConnection("app.db");
CreateTable ();
}
@rid00z
rid00z / RemoteDataSource.cs
Last active August 29, 2015 14:05
Remote Data Source
/*
* Note* this is for demo purposes only and is not a example of good network code,
* http://www.michaelridland.com/mobile/asp-net-mvc-xamarin-mashups/
*/
public class RemoteDataSource : IDataSource
{
static string HostBase = "http://192.168.56.101:49203";
public RemoteDataSource ()
{
}
@rid00z
rid00z / Extensions.cs
Created July 15, 2015 11:15
Bluetooth APIs with TaskCompletionSource
using System;
using System.Threading.Tasks;
using System.Linq;
using System.Diagnostics;
namespace Robotics.Mobile.Core.Bluetooth.LE
{
public static class Extensions
{
/// <summary>
@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 ()
{
@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;