Hybrid Apps in Xamarin?? Part 2

By September 5, 2014 News, Xamarin 2 Comments
StockPhotoApp

In my previous blog post I started to create a hybrid application in Xamarin (see that post for why this is not an entirely crazy idea).

I glossed over the implementation of IdataAccess. Let’s focus on that now.  In the iosStockPhoto project we have divided the implementation of IDataAccess into two partial class files, DataAccess.cs and DataAccess.ios.cs.  The latter handles the path for the database file,

It is DataAccess.cs, however, that we want to focus on now.  Let’s start with the implementation for LoadAllPhotos.  This will return a list of photo objects, each of which will contain data about the photo, including its name on disk,

the first step is to get a command object and open the connection.

With that we can set up our select statement and execute it.  Which statement we execute depends on whether we are looking only for our favorite photos, or all of them,

Execution returns a SqliteDataReader, which we can index into to obtain the values for our Photo objects,

 Getting A Photo By ID

Getting a single photo by ID is very similar. This time, we modify the select statement to get the one photo we want,

 

We’re now in a position to return to the controller and fill in the missing code.

The three methods in PhotoController are very similar.

 

The factored out code in ShowTemplatedPage uses the facilities provided by PortableRazor.

In the previous posting, we looked at the cshtml for the list page.  When you tap on a photo you are taken to the details page. Here is that cshtml,

Once again, no surprises; straight forward cshtml with Razor.

Here is what the second page looks like,

 

Foliage

Details page

 

The following two tabs change content below.

Jesse Liberty

Master Consultant at Falafel Software
Jesse Liberty is a Master Consultant for Falafel Software, an author and he creates courses for Pluralsight . He is a Microsoft MVP and a Certified Xamarin Mobile Developer. Liberty hosts the popular Yet Another Podcast and his blog is considered required reading. He was a Senior Evangelist for Microsoft, , a XAML Evangelist for Telerik , Distinguished Software Engineer at AT&T; Software Architect for PBS and Vice President of Information Technology at Citibank.