Permalink
Browse files

Fixes and added background task action to MonoMobile application

  • Loading branch information...
1 parent 8db8abc commit 17b7195e17646c870c3ea5522bb35d61a04da9c2 @RobertKozak committed Feb 16, 2012
@@ -137,6 +137,14 @@ public override void ReceivedLocalNotification(UIApplication application, UILoca
if (MonoMobileApplication.ReceivedLocalNoticiationAction != null)
MonoMobileApplication.ReceivedLocalNoticiationAction(notification);
}
+
+ public override void DidEnterBackground(UIApplication application)
+ {
+ if (MonoMobileApplication.DidEnterBackgroundAction != null)
+ {
+ MonoMobileApplication.DidEnterBackgroundAction(application);
+ }
+ }
}
}
@@ -52,6 +52,7 @@ public class MonoMobileApplication : UIApplication
public static string Title { get; set; }
public static Action ResumeFromBackgroundAction { get; set; }
+ public static Action<UIApplication> DidEnterBackgroundAction { get; set; }
public static Action<UILocalNotification> ReceivedLocalNoticiationAction { get; set; }
public override bool NetworkActivityIndicatorVisible
@@ -118,15 +119,17 @@ public static void PushView(object view)
public static void PushView(object view, bool animated)
{
- var dvc = CreateDialogViewController(view, false, true);
-
- NavigationController.PushViewController(dvc, animated);
+ PushView(view, true, true);
}
public static void PushView(object view, bool animated, bool pushing)
{
var dvc = CreateDialogViewController(view, false, pushing);
-
+ var intializable = view as IInitializable;
+ if (intializable != null)
+ {
+ intializable.Initialize();
+ }
NavigationController.PushViewController(dvc, animated);
}
@@ -10,7 +10,7 @@
using System.Security.Cryptography;
// code based on Redth's UrlImageStore, but not using the not very stable NSOperationQueue under MonoTouch but rather
-// the Parallels taks library
+// the Parallels tasks library
// original one: https://gist.github.com/405923
namespace MonoTouch.UrlImageStore
@@ -194,23 +194,9 @@ internal void AddToCache(string id, UIImage img)
public class UrlImageStoreRequest
{
- public string Id
- {
- get;
- set;
- }
-
- public string Url
- {
- get;
- set;
- }
-
- public IUrlImageUpdated Notify
- {
- get;
- set;
- }
+ public string Id { get; set; }
+ public string Url { get; set; }
+ public IUrlImageUpdated Notify { get; set; }
}
/// <summary>
@@ -36,7 +36,8 @@ namespace MonoMobile.Views
public partial class UIBorderedView : UIView
{
private UIActivityIndicatorView _ActivityIndicatorView;
-
+
+ public UIImageView ImageView { get; set; }
public int CornerRadius { get; set; }
public UIColor ShadowColor { get; set; }
public float ShadowOpacity { get; set; }
@@ -56,28 +57,41 @@ public UIBorderedView(RectangleF frame) : base(frame)
CreateCurveAndShadow();
}
+ protected override void Dispose (bool disposing)
+ {
+ if (disposing)
+ {
+ if (ImageView != null)
+ {
+ ImageView.Dispose();
+ }
+ }
+
+ base.Dispose(disposing);
+ }
+
public void AddImage(UIImage image, bool animate)
{
if (image != null)
{
InvokeOnMainThread(() =>
{
var bounds = Bounds;
- var imageView = new UIImageView(new RectangleF(BorderWidth, BorderWidth, Bounds.Width - (BorderWidth * 2), Bounds.Height - (BorderWidth * 2)));
- imageView.Layer.CornerRadius = 5.0f;
- imageView.Layer.MasksToBounds = true;
- imageView.Layer.BorderWidth = 1;
- imageView.Layer.BorderColor = UIColor.LightGray.CGColor;
- imageView.Image = image;
- imageView.Alpha = 0f;
+ ImageView = new UIImageView(new RectangleF(BorderWidth, BorderWidth, Bounds.Width - (BorderWidth * 2), Bounds.Height - (BorderWidth * 2)));
+ ImageView.Layer.CornerRadius = 5.0f;
+ ImageView.Layer.MasksToBounds = true;
+ ImageView.Layer.BorderWidth = 1;
+ ImageView.Layer.BorderColor = UIColor.LightGray.CGColor;
+ ImageView.Image = image;
+ ImageView.Alpha = 0f;
- Add(imageView);
+ Add(ImageView);
_ActivityIndicatorView.StopAnimating();
UIView.BeginAnimations("fadeIn");
UIView.SetAnimationDuration(animate ? 0.6f : 0f);
- imageView.Alpha = 1.0f;
+ ImageView.Alpha = 1.0f;
UIView.CommitAnimations();
});
}
@@ -136,11 +136,11 @@ public void HandleNotifyCollectionChanged(object sender, NotifyCollectionChanged
{
if (Controller == MonoMobileApplication.CurrentViewController)
{
- Controller.TableView.ReloadSections(NSIndexSet.FromIndex(Section.Index), UITableViewRowAnimation.Automatic);
+ InvokeOnMainThread(()=> Controller.TableView.ReloadSections(NSIndexSet.FromIndex(Section.Index), UITableViewRowAnimation.Automatic));
}
else if (Controller.TableView != null)
{
- Controller.TableView.ReloadData();
+ InvokeOnMainThread(()=> Controller.TableView.ReloadData());
}
}
}
@@ -172,7 +172,7 @@ private void AddRow(Section section, int row, object item, UITableViewRowAnimati
if (Controller == MonoMobileApplication.CurrentViewController)
{
var indexPaths = new NSIndexPath[] { NSIndexPath.FromRowSection(row, section.Index) };
- Controller.TableView.InsertRows(indexPaths, animation);
+ InvokeOnMainThread(()=> Controller.TableView.InsertRows(indexPaths, animation));
}
}
@@ -185,7 +185,7 @@ private void InsertRow(Section section, int row, object item, UITableViewRowAnim
if (Controller == MonoMobileApplication.CurrentViewController)
{
var indexPaths = new NSIndexPath[] { NSIndexPath.FromRowSection(row, section.Index) };
- Controller.TableView.InsertRows(indexPaths, animation);
+ InvokeOnMainThread(()=> Controller.TableView.InsertRows(indexPaths, animation));
}
}
@@ -199,7 +199,7 @@ private void RemoveRow(Section section, object item, UITableViewRowAnimation ani
if (Controller == MonoMobileApplication.CurrentViewController)
{
var indexPaths = new NSIndexPath[] { NSIndexPath.FromRowSection(row, section.Index) };
- Controller.TableView.DeleteRows(indexPaths, animation);
+ InvokeOnMainThread(()=> Controller.TableView.DeleteRows(indexPaths, animation));
}
}
@@ -215,7 +215,7 @@ private void ReplaceRow(Section section, object oldItem, object newItem, UITable
if (Controller == MonoMobileApplication.CurrentViewController)
{
var indexPaths = new NSIndexPath[] { NSIndexPath.FromRowSection(row, section.Index) };
- Controller.TableView.ReloadRows(indexPaths, animation);
+ InvokeOnMainThread(()=> Controller.TableView.ReloadRows(indexPaths, animation));
}
}
}
Oops, something went wrong.

0 comments on commit 17b7195

Please sign in to comment.