Viand Sync Diary #2 – Refreshing

Syncing data between the device and the cloud will happen at two times:

  • Automatically when the application starts
  • Automatically when the application comes to the foreground
  • Manually when the user makes the refresh gesture on either list

While I continue refactoring the application to add the automatic sync calls I’ve added a manual refresh gesture to the iPhone app. With Xamarin Forms it’s quite simple (like everything once you figure how to do it). Here’s the code that I added to the Buy list constructor.

buyView.IsPullToRefreshEnabled = true;
buyView.Refreshing += delegate(object sender, EventArgs e) {
	Device.StartTimer(TimeSpan.FromSeconds(5), SyncItems;

The Add list code is similar except I used a lambda expression instead of the C# 2.0 delegate syntax to call SyncItems.

addView.IsPullToRefreshEnabled = true;
addView.Refreshing += (object sender, EventArgs e) => Device.StartTimer(TimeSpan.FromSeconds(5), SyncItems;

For both lists the SyncItems calls the SyncItems method in ItemDatabase (which will perform the actual database syncing), sets IsRefreshing to false to end the refresh state, and then returns false to prevent the timer from recurring.

internal bool SyncItems()
	addView.IsRefreshing = false;

	return false;

Here’s how manual refreshing looks on the iPhone.


Since I’m using Xamarin Forms I get an Android-specific manual refresh indicator without any additional coding.


This entry was posted in Side Projects and tagged , , . Bookmark the permalink.