Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4c7e871
Make use of the Target field of RadioSelectionAttribute so you can ha…
csteeg Mar 30, 2011
8589a36
Make shouldReturn work if you have more then 2 elements on your form …
csteeg Mar 30, 2011
b204745
Sometimes the element might get disposed, before the entry object is …
csteeg Apr 6, 2011
cf435da
Makes the target property of RadioSelectionAttribute actually do some…
csteeg Apr 6, 2011
1fe7ae6
Oops, messed up line endings. Set them to LF again
csteeg Apr 6, 2011
e898f8c
Merge remote branch 'migueldeicaza/master'
csteeg Apr 8, 2011
01bf306
Merge branch 'master' of https://github.com/migueldeicaza/MonoTouch.D…
csteeg Apr 19, 2011
0305f7c
Fix line endings
csteeg Apr 21, 2011
7332eb2
Fix line endings
csteeg Apr 21, 2011
5bccee1
Merge branch 'master' of github.com:csteeg/MonoTouch.Dialog
csteeg Apr 21, 2011
120a34b
Hmm, csproj file updates suck... reverting
csteeg Apr 21, 2011
82c6490
Converted back to MemberAndInstance due to reported issue.
csteeg Apr 21, 2011
8c999fd
Let MultiLineElement also check the Detailtextlabel height, and pick …
csteeg Apr 28, 2011
1d2d07b
Added a table footer view which mimics the 'pull to refresh' but acts…
csteeg Apr 28, 2011
4ab1500
Remove debugline
csteeg Apr 28, 2011
5b94ea2
Use default font, as font is not available here yet
csteeg Apr 28, 2011
e9e685f
Some improvements I need
csteeg Aug 22, 2011
2320f5d
merged with Miguel's master again
csteeg Aug 22, 2011
84c9ebd
Merge branch 'master' of https://github.com/migueldeicaza/MonoTouch.D…
csteeg Aug 22, 2011
887bd22
Fix entry elements having a wrong size after scrolling
csteeg Aug 22, 2011
7beab4f
Shouldn't have been there
csteeg Aug 22, 2011
f5ad49f
I'll stick to this version, sorry
csteeg Aug 22, 2011
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
*~
*.userprefs
*.pidb

_UpgradeReport_Files/*
*.user
*.suo
MonoTouch.Dialog/obj/**
Sample/obj/**
11 changes: 7 additions & 4 deletions MonoTouch.Dialog.sln
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoTouch.Dialog", "MonoTouch.Dialog\MonoTouch.Dialog.csproj", "{3FFBFFF8-5560-4EDE-82E5-3FFDFBBA8A50}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{F6AEFFC5-4807-49A3-83C5-661E655CB59A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Release|iPhoneSimulator = Release|iPhoneSimulator
Debug|iPhone = Debug|iPhone
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Release|iPhone = Release|iPhone
Release|iPhoneSimulator = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3FFBFFF8-5560-4EDE-82E5-3FFDFBBA8A50}.Debug|iPhone.ActiveCfg = Debug|iPhone
Expand All @@ -30,6 +30,9 @@ Global
{F6AEFFC5-4807-49A3-83C5-661E655CB59A}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{F6AEFFC5-4807-49A3-83C5-661E655CB59A}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Sample\Sample.csproj
EndGlobalSection
Expand Down
225 changes: 172 additions & 53 deletions MonoTouch.Dialog/DialogViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class DialogViewController : UITableViewController
public UITableViewStyle Style = UITableViewStyle.Grouped;
UISearchBar searchBar;
UITableView tableView;
RefreshTableHeaderView refreshView;
protected RefreshTableHeaderView refreshView;
protected LoadMoreTableFooterView loadMoreView;
RootElement root;
bool pushing;
bool dirty;
Expand Down Expand Up @@ -62,8 +63,27 @@ public event EventHandler RefreshRequested {
refreshRequested -= value;
}
}

// If the value is 1, we are enabled, used in the source for quick computation

EventHandler loadMoreRequested;
/// <summary>
/// If you assign a handler to this event before the view is shown, the
/// DialogViewController will have support for pull-to-refresh UI.
/// </summary>
public event EventHandler LoadMoreRequested
{
add
{
if (tableView != null)
throw new ArgumentException("You should set the handler before the controller is shown");
loadMoreRequested += value;
}
remove
{
loadMoreRequested -= value;
}
}

// If the value is 1, we are enabled, used in the source for quick computation
bool enableSearch;
public bool EnableSearch {
get {
Expand Down Expand Up @@ -101,7 +121,7 @@ public void TriggerRefresh ()

void TriggerRefresh (bool showStatus)
{
if (refreshRequested == null)
if (refreshRequested == null)
return;

if (reloading)
Expand All @@ -110,37 +130,92 @@ void TriggerRefresh (bool showStatus)
reloading = true;
if (refreshView != null)
refreshView.SetActivity (true);

refreshRequested (this, EventArgs.Empty);

if (reloading && showStatus && refreshView != null){
if (reloading && showStatus && refreshView != null){
UIView.BeginAnimations ("reloadingData");
UIView.SetAnimationDuration (0.2);
TableView.ContentInset = new UIEdgeInsets (60, 0, 0, 0);
UIView.CommitAnimations ();
}
}

/// <summary>

/// <summary>
/// Invoke this method to trigger a data refresh.
/// </summary>
/// <remarks>
/// This will invoke the RerfeshRequested event handler, the code attached to it
/// should start the background operation to fetch the data and when it completes
/// it should call ReloadComplete to restore the control state.
/// </remarks>
public void TriggerLoadMore()
{
TriggerLoadMore(false);
}


void TriggerLoadMore(bool showStatus)
{
if (loadMoreRequested == null)
return;

if (reloading)
return;

reloading = true;
if (loadMoreView != null)
loadMoreView.SetActivity(true);

loadMoreRequested(this, EventArgs.Empty);

if (reloading && showStatus && loadMoreView != null && !loadMoreView.Hidden)
{
UIView.BeginAnimations("reloadingData");
UIView.SetAnimationDuration(0.2);
TableView.ContentInset = new UIEdgeInsets(0, 0, 65, 0);
UIView.CommitAnimations();
}
}


/// <summary>
/// Invoke this method to signal that a reload has completed, this will update the UI accordingly.
/// </summary>
public void ReloadComplete ()
{
if (refreshView != null)
refreshView.LastUpdate = DateTime.Now;
if (loadMoreView != null)
loadMoreView.LastUpdate = DateTime.Now;

if (!reloading)
return;

reloading = false;
if (refreshView == null)
return;

refreshView.SetActivity (false);
refreshView.Flip (false);
UIView.BeginAnimations ("doneReloading");
UIView.SetAnimationDuration (0.3f);
TableView.ContentInset = new UIEdgeInsets (0, 0, 0, 0);
refreshView.SetStatus (RefreshViewStatus.PullToReload);
UIView.CommitAnimations ();
InvokeOnMainThread(() => {
reloading = false;
if (refreshView != null)
{
refreshView.SetActivity(false);
refreshView.Flip(false);
}
if (loadMoreView != null)
{
loadMoreView.SetActivity(false);
loadMoreView.Flip(false);
loadMoreView.Frame = new RectangleF(loadMoreView.Frame.X, TableView.ContentSize.Height,
loadMoreView.Frame.Width,
loadMoreView.Frame.Height);
}
UIView.BeginAnimations("doneReloading");
UIView.SetAnimationDuration(0.3f);
TableView.ContentInset = new UIEdgeInsets(0, 0, 0, 0);
if (refreshView != null)
refreshView.SetStatus(RefreshViewStatus.PullToReload);
if (loadMoreView != null)
loadMoreView.SetStatus(RefreshViewStatus.PullToReload);
UIView.CommitAnimations();
});
}

/// <summary>
Expand Down Expand Up @@ -287,7 +362,7 @@ public Source (DialogViewController container)
this.Container = container;
Root = container.root;
}

public override int RowsInSection (UITableView tableview, int section)
{
var s = Root.Sections [section];
Expand Down Expand Up @@ -321,7 +396,11 @@ public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Founda

public override void WillDisplay (UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
{
if (Root.NeedColorUpdate){
if (Container.loadMoreView != null)
InvokeOnMainThread(() => { Container.loadMoreView.Frame = new RectangleF(0, Container.TableView.ContentSize.Height, Container.loadMoreView.Frame.Width, Container.loadMoreView.Frame.Height);});

if (Root.NeedColorUpdate)
{
var section = Root.Sections [indexPath.Section];
var element = section.Elements [indexPath.Row];
var colorized = element as IColorizeBackground;
Expand Down Expand Up @@ -364,41 +443,64 @@ public override float GetHeightForFooter (UITableView tableView, int sectionIdx)
}

#region Pull to Refresh support
public override void Scrolled (UIScrollView scrollView)
{
if (!checkForRefresh)
return;
if (Container.reloading)
return;
var view = Container.refreshView;
if (view == null)
return;

var point = Container.TableView.ContentOffset;

if (view.IsFlipped && point.Y > -yboundary && point.Y < 0){
view.Flip (true);
view.SetStatus (RefreshViewStatus.PullToReload);
} else if (!view.IsFlipped && point.Y < -yboundary){
view.Flip (true);
view.SetStatus (RefreshViewStatus.ReleaseToReload);
}
}

public override void DraggingStarted (UIScrollView scrollView)
public override void Scrolled(UIScrollView scrollView)
{
if (Container.reloading)
return;
if (!checkForRefresh)
return;

if (Container.refreshView != null)
{
var point = Container.TableView.ContentOffset;

if (Container.refreshView.IsFlipped && point.Y > -yboundary && point.Y < 0)
{
Container.refreshView.Flip(true);
Container.refreshView.SetStatus(RefreshViewStatus.PullToReload);
}
else if (!Container.refreshView.IsFlipped && point.Y < -yboundary)
{
Container.refreshView.Flip(true);
Container.refreshView.SetStatus(RefreshViewStatus.ReleaseToReload);
}

}
if (Container.loadMoreView != null && !Container.loadMoreView.Hidden)
{
var point = Container.TableView.ContentOffset;
point.Y += Container.TableView.Bounds.Height;
if (Container.loadMoreView.IsFlipped && point.Y > Container.TableView.ContentSize.Height + yboundary)
{
Container.loadMoreView.Flip(true);
Container.loadMoreView.SetStatus(RefreshViewStatus.ReleaseToReload);
}
else if (!Container.loadMoreView.IsFlipped && point.Y < Container.TableView.ContentSize.Height + yboundary)
{
Container.loadMoreView.Flip(true);
Container.loadMoreView.SetStatus(RefreshViewStatus.PullToReload);
}
}
}

public override void DraggingStarted (UIScrollView scrollView)
{
checkForRefresh = true;
}

public override void DraggingEnded (UIScrollView scrollView, bool willDecelerate)
{
if (Container.refreshView == null)
return;

checkForRefresh = false;
if (Container.TableView.ContentOffset.Y > -yboundary)
return;
Container.TriggerRefresh (true);
checkForRefresh = false;
if (Container.refreshView != null && (Container.TableView.ContentOffset.Y < -yboundary))
{
Container.TriggerRefresh(true);
}
if ((Container.loadMoreView != null)
&& (Container.TableView.ContentOffset.Y + Container.TableView.Bounds.Height > Container.TableView.ContentSize.Height + yboundary)
&& !Container.loadMoreView.Hidden)
{
Container.TriggerLoadMore(true);
}
}
#endregion
}
Expand Down Expand Up @@ -513,14 +615,30 @@ void ConfigureTableView ()
refreshView.SetActivity (true);
TableView.AddSubview (refreshView);
}
}
if (loadMoreRequested != null)
{
// The dimensions should be large enough so that even if the user scrolls, we render the
// whole are with the background color.
var bounds = View.Bounds;

loadMoreView = MakeLoadMoreTableFooterView(new RectangleF(0, Math.Max(TableView.ContentSize.Height, bounds.Height), bounds.Width, bounds.Height));
if (reloading)
loadMoreView.SetActivity(true);
TableView.AddSubview(loadMoreView);
}
}

public virtual RefreshTableHeaderView MakeRefreshTableHeaderView (RectangleF rect)
{
return new RefreshTableHeaderView (rect);
}

public override void ViewWillAppear (bool animated)
public virtual LoadMoreTableFooterView MakeLoadMoreTableFooterView(RectangleF rect)
{
return new LoadMoreTableFooterView(rect);
}

public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear (animated);
if (AutoHideSearch){
Expand Down Expand Up @@ -554,10 +672,9 @@ void UpdateSource ()
{
if (root == null)
return;

TableSource = CreateSizingSource (root.UnevenRows);
tableView.Source = TableSource;
}
}

public void ReloadData ()
{
Expand Down Expand Up @@ -596,6 +713,7 @@ public DialogViewController (RootElement root) : base (UITableViewStyle.Grouped)
public DialogViewController (UITableViewStyle style, RootElement root) : base (style)
{
PrepareRoot (root);
Style = style;
}

/// <summary>
Expand All @@ -618,6 +736,7 @@ public DialogViewController (RootElement root, bool pushing) : base (UITableView
public DialogViewController (UITableViewStyle style, RootElement root, bool pushing) : base (style)
{
this.pushing = pushing;
Style = style;
PrepareRoot (root);
}
}
Expand Down
Loading