summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3319.xaml.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3319.xaml.cs')
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3319.xaml.cs264
1 files changed, 264 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3319.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3319.xaml.cs
new file mode 100644
index 00000000..d2f54cd0
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3319.xaml.cs
@@ -0,0 +1,264 @@
+´╗┐using System;
+using System.Collections.Generic;
+
+using Xamarin.Forms;
+using System.Threading.Tasks;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using Xamarin.Forms.CustomAttributes;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls
+{
+ [Preserve (AllMembers = true)]
+ [Issue (IssueTracker.Github, 3319, "[iOS] Clear and adding rows exception")]
+ public partial class Issue3319 : TestContentPage
+ {
+ #if UITEST
+ [Test]
+ public void Issue3319Test ()
+ {
+ RunningApp.WaitForElement (q => q.Marked ("Will this repo work?"));
+
+ }
+ #endif
+
+ FavoritesViewModel ViewModel {
+ get { return BindingContext as FavoritesViewModel; }
+ }
+
+ public Issue3319 ()
+ {
+ #if APP
+ InitializeComponent ();
+ BindingContext = new FavoritesViewModel ();
+
+ listView.SeparatorVisibility = SeparatorVisibility.Default;
+ listView.SeparatorColor = Color.FromHex ("#ababab");
+
+ listView.ItemTapped += (sender, args) => {
+ if (listView.SelectedItem == null)
+ return;
+
+ //do nothing anyway
+ return;
+ };
+ #endif
+
+ }
+
+ protected override void Init ()
+ {
+
+ }
+
+ public async void OnDelete (object sender, EventArgs e)
+ {
+ var mi = ((MenuItem)sender);
+ if (mi.CommandParameter == null)
+ return;
+
+ var articlelistingitem = mi.CommandParameter;
+
+ if (articlelistingitem != null)
+ DisplayAlert ("Alert", "I'm not deleting just refreshing...", "Ok");
+ ViewModel.LoadFavoritesCommand.Execute (null);
+ }
+
+
+ protected override void OnAppearing ()
+ {
+ base.OnAppearing ();
+ if (ViewModel == null || !ViewModel.CanLoadMore || ViewModel.IsBusy)
+ return;
+
+ Device.BeginInvokeOnMainThread (() => {
+ ViewModel.LoadFavoritesCommand.Execute (null);
+ });
+ }
+
+ [Preserve (AllMembers = true)]
+ public class FavoritesViewModel :BaseViewModelF
+ {
+ public ObservableCollection<ArticleListing> FavoriteArticles { get; set; }
+
+ public FavoritesViewModel ()
+ {
+ Title = "Favorites";
+ FavoriteArticles = new ObservableCollection<ArticleListing> ();
+ }
+
+ Command _loadFavoritesCommand;
+
+ public Command LoadFavoritesCommand {
+ get {
+ return _loadFavoritesCommand ??
+ (_loadFavoritesCommand = new Command (async () => {
+ await ExecuteFavoritesCommand ();
+ }, () => {
+ return !IsBusy;
+ }));
+ }
+ }
+
+ public async Task ExecuteFavoritesCommand ()
+ {
+ if (IsBusy)
+ return;
+
+ IsBusy = true;
+ LoadFavoritesCommand.ChangeCanExecute ();
+ FavoriteArticles.Clear ();
+ var articles = new ObservableCollection<ArticleListing> {
+ new ArticleListing {
+ ArticleTitle = "Will this repo work?",
+ AuthorString = "Ben Crispin",
+ FormattedPostedDate = "7-28-2015"
+ },
+ new ArticleListing {
+ ArticleTitle = "Xamarin Forms BugZilla",
+ AuthorString = "Some Guy",
+ FormattedPostedDate = "7-28-2015"
+ }
+ };
+ var templist = new ObservableCollection<ArticleListing> ();
+ foreach (var article in articles) {
+ //templist.Add(article);
+ FavoriteArticles.Add (article);
+ }
+ //FavoriteArticles = templist;
+ OnPropertyChanged ("FavoriteArticles");
+ IsBusy = false;
+ LoadFavoritesCommand.ChangeCanExecute ();
+ }
+
+ }
+ }
+
+ public class BaseViewModelF : INotifyPropertyChanged
+ {
+ public BaseViewModelF ()
+ {
+ }
+
+ string _title = string.Empty;
+ public const string TitlePropertyName = "Title";
+
+ /// <summary>
+ /// Gets or sets the "Title" property
+ /// </summary>
+ /// <value>The title.</value>
+ public string Title {
+ get { return _title; }
+ set { SetProperty (ref _title, value, TitlePropertyName); }
+ }
+
+ string _subTitle = string.Empty;
+ /// <summary>
+ /// Gets or sets the "Subtitle" property
+ /// </summary>
+ public const string SubtitlePropertyName = "Subtitle";
+
+ public string Subtitle {
+ get { return _subTitle; }
+ set { SetProperty (ref _subTitle, value, SubtitlePropertyName); }
+ }
+
+ string _icon = null;
+ /// <summary>
+ /// Gets or sets the "Icon" of the viewmodel
+ /// </summary>
+ public const string IconPropertyName = "Icon";
+
+ public string Icon {
+ get { return _icon; }
+ set { SetProperty (ref _icon, value, IconPropertyName); }
+ }
+
+ bool _isBusy;
+ /// <summary>
+ /// Gets or sets if the view is busy.
+ /// </summary>
+ public const string IsBusyPropertyName = "IsBusy";
+
+ public bool IsBusy {
+ get { return _isBusy; }
+ set { SetProperty (ref _isBusy, value, IsBusyPropertyName); }
+ }
+
+ bool _canLoadMore = true;
+ /// <summary>
+ /// Gets or sets if we can load more.
+ /// </summary>
+ public const string CanLoadMorePropertyName = "CanLoadMore";
+
+ public bool CanLoadMore {
+ get { return _canLoadMore; }
+ set { SetProperty (ref _canLoadMore, value, CanLoadMorePropertyName); }
+ }
+
+ protected void SetProperty<T> (
+ ref T backingStore, T value,
+ string propertyName,
+ Action onChanged = null)
+ {
+
+ if (EqualityComparer<T>.Default.Equals (backingStore, value))
+ return;
+
+ backingStore = value;
+
+ if (onChanged != null)
+ onChanged ();
+
+ OnPropertyChanged (propertyName);
+ }
+
+ #region INotifyPropertyChanged implementation
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ #endregion
+
+ public void OnPropertyChanged (string propertyName)
+ {
+ if (PropertyChanged == null)
+ return;
+
+ PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
+ }
+
+ }
+
+ [Preserve (AllMembers = true)]
+ public class ArticleListing
+ {
+ public ArticleListing ()
+ {
+ }
+
+ public string ArticleTitle { get; set; }
+
+ public string ShortArticleTitle { get; set; }
+
+ public string AuthorString { get; set; }
+
+ public string FormattedPostedDate { get; set; }
+
+ public string KickerName { get; set; }
+
+ public string ArticleUrl { get; set; }
+ }
+
+ public class YearOloArticleList
+ {
+ public string Year { get; set; }
+
+ public List<ArticleListing> ListArticleListing { get; set; }
+ }
+}
+