diff options
author | Vitaly Takmazov | 2013-04-01 12:05:02 +0400 |
---|---|---|
committer | Vitaly Takmazov | 2013-04-01 12:05:02 +0400 |
commit | 0623943dccad5c44831b2ad4a803eab2436e45e6 (patch) | |
tree | df9ea217f9dbfef53a82b4a7e7fc98117d1c11b3 /Juick/ViewModels | |
parent | 4c92def17fef70c35e578ffb2c5e6acde3b9247d (diff) |
Using WPToolkit LongListSelector
Diffstat (limited to 'Juick/ViewModels')
-rw-r--r-- | Juick/ViewModels/ViewModelBase.cs | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/Juick/ViewModels/ViewModelBase.cs b/Juick/ViewModels/ViewModelBase.cs index 2427a80..80d3d8b 100644 --- a/Juick/ViewModels/ViewModelBase.cs +++ b/Juick/ViewModels/ViewModelBase.cs @@ -9,6 +9,10 @@ using System.Windows.Media.Imaging; using Juick.Classes; using JuickApi; using RestSharp; +using System.Diagnostics; +using System.Windows.Navigation; +using Microsoft.Phone.Controls; +using System.Windows.Controls; namespace Juick.ViewModels { @@ -21,11 +25,14 @@ namespace Juick.ViewModels { Items = new ObservableCollection<PostItem>(); LoadMessagesPageCommand = new DelegateCommand(LoadData, () => !IsDataLoading); + NavigateNextCommand = new DelegateCommand(NavigateToThread, () => true); } public string RestUri { get; set; } public virtual string Caption { get { return "juick"; } } + public string SelectedId { get; set; } + /// <summary> /// A collection for MessageViewModel objects. /// </summary> @@ -33,6 +40,8 @@ namespace Juick.ViewModels public DelegateCommand LoadMessagesPageCommand { get; private set; } + public DelegateCommand NavigateNextCommand { get; private set; } + public bool IsDataLoading { get { return isDataLoading; } @@ -44,16 +53,36 @@ namespace Juick.ViewModels } } + public void NavigateToThread(object param) + { + var selectionChangedEventArgs = param as SelectionChangedEventArgs; + if (param != null) + { + ((App)App.Current).NavigateTo(new Uri(string.Format("/ThreadView.xaml?mid={0}", ((PostItem)selectionChangedEventArgs.AddedItems[0]).MID), UriKind.Relative)); + } + + } + /// <summary> /// Creates and adds a few MessageViewModel objects into the Items collection. /// </summary> - public void LoadData() + public void LoadData(object EventArgs) { - if (IsDataLoading) { + const int offset = 5; + if (IsDataLoading) + { return; } + if (EventArgs != null) + { + var item = (EventArgs as LinkUnlinkEventArgs).ContentPresenter.Content; + if (!item.Equals(Items[Items.Count - offset])) { + return; + } + } - const int PageSize = 1; + int count = Items.Count; + if (string.IsNullOrEmpty(RestUri)) { @@ -65,12 +94,12 @@ namespace Juick.ViewModels else if (RestUri.StartsWith("/home?", StringComparison.InvariantCulture) && Items.Count > 0) { var lastItem = Items[Items.Count - 1]; - RestUri = string.Format("/home?before_mid={0}&page={1}", lastItem.MID, PageSize); + RestUri = string.Format("/home?before_mid={0}", lastItem.MID); } else if (RestUri.StartsWith("/messages?", StringComparison.InvariantCulture) && Items.Count > 0) { var lastItem = Items[Items.Count - 1]; - RestUri = string.Format("/messages?before_mid={0}&page={1}", lastItem.MID, PageSize); + RestUri = string.Format("/messages?before_mid={0}", lastItem.MID); } var request = new RestRequest(RestUri + "&rnd=" + Environment.TickCount); @@ -90,7 +119,6 @@ namespace Juick.ViewModels //Items.Clear(); response.Data.Select(x => new PostItem(x)).ToList().ForEach(i => Items.Add(i)); - } |