Skip to content

Commit

Permalink
Refactor WP8 project to use the PCL
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbatum committed Mar 22, 2014
1 parent edb96ee commit c0ae54b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
5 changes: 0 additions & 5 deletions xamarinpcl/xamarinpcl-wp8/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public partial class App : Application
/// </summary>
/// <returns>The root frame of the Phone Application.</returns>
public static PhoneApplicationFrame RootFrame { get; private set; }

public static MobileServiceClient MobileService = new MobileServiceClient(
"https://xamarinpcl.azure-mobile.net/",
"IablidpNUIraXfejLXNLRgQMRRlwAR41"
);

/// <summary>
/// Constructor for the Application object.
Expand Down
26 changes: 8 additions & 18 deletions xamarinpcl/xamarinpcl-wp8/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,26 @@
using System.Windows.Controls;
using System.Windows.Navigation;
using xamarinpcl.Resources;
using Shared;

namespace xamarinpcl
{
public class TodoItem
{
public string Id { get; set; }

[JsonProperty(PropertyName = "text")]
public string Text { get; set; }

[JsonProperty(PropertyName = "complete")]
public bool Complete { get; set; }
}

public partial class MainPage : PhoneApplicationPage
{
// MobileServiceCollectionView implements ICollectionView (useful for databinding to lists) and
// is integrated with your Mobile Service to make it easy to bind your data to the ListView
private MobileServiceCollection<TodoItem, TodoItem> items;
private MobileServiceCollection<ToDoItem, ToDoItem> items;

private IMobileServiceTable<TodoItem> todoTable = App.MobileService.GetTable<TodoItem>();
private IMobileServiceTable<ToDoItem> todoTable = Common.MobileService.GetTable<ToDoItem>();

// Constructor
public MainPage()
{
InitializeComponent();
}

private async void InsertTodoItem(TodoItem todoItem)
private async void InsertTodoItem(ToDoItem todoItem)
{
// This code inserts a new TodoItem into the database. When the operation completes
// and Mobile Services has assigned an Id, the item is added to the CollectionView
Expand All @@ -52,8 +43,7 @@ private async void RefreshTodoItems()
// The query excludes completed TodoItems
try
{
items = await todoTable
.Where(todoItem => todoItem.Complete == false)
items = await Common.GetIncompleteItems()
.ToCollectionAsync();
}
catch (MobileServiceInvalidOperationException e)
Expand All @@ -64,7 +54,7 @@ private async void RefreshTodoItems()
ListItems.ItemsSource = items;
}

private async void UpdateCheckedTodoItem(TodoItem item)
private async void UpdateCheckedTodoItem(ToDoItem item)
{
// This code takes a freshly completed TodoItem and updates the database. When the MobileService
// responds, the item is removed from the list
Expand All @@ -79,14 +69,14 @@ private void ButtonRefresh_Click(object sender, RoutedEventArgs e)

private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
var todoItem = new TodoItem { Text = TodoInput.Text };
var todoItem = new ToDoItem { Text = TodoInput.Text };
InsertTodoItem(todoItem);
}

private void CheckBoxComplete_Checked(object sender, RoutedEventArgs e)
{
CheckBox cb = (CheckBox)sender;
TodoItem item = cb.DataContext as TodoItem;
ToDoItem item = cb.DataContext as ToDoItem;
item.Complete = true;
UpdateCheckedTodoItem(item);
}
Expand Down
6 changes: 6 additions & 0 deletions xamarinpcl/xamarinpcl-wp8/xamarinpcl-wp8.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\sl4-windowsphone71\System.Net.Http.Primitives.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\xamarinpcl-shared\xamarinpcl-shared.csproj">
<Project>{9B65BD76-FBBC-44D3-B52C-DEE2B719871D}</Project>
<Name>xamarinpcl-shared</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).$(TargetFrameworkVersion).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

0 comments on commit c0ae54b

Please sign in to comment.