From 76757595688eab055586c1dfeff1b3e26b733a43 Mon Sep 17 00:00:00 2001 From: Nathaniel Nunes Date: Sat, 13 Apr 2019 13:41:33 +0530 Subject: [PATCH] Expandable collection view sample, tested on android --- .../CollectionViewChallenge.Android.csproj | 9 +++- .../Resources/drawable/down_arrow.png | Bin 0 -> 285 bytes .../CollectionViewChallenge.iOS.csproj | 5 ++- .../Resources/down_arrow.png | Bin 0 -> 285 bytes .../CollectionViewChallenge.csproj | 1 - .../CollectionViewChallenge/Models/Event.cs | 32 ++++++++++++++ .../Views/CollectionViewChallengePage.xaml | 41 ++++++++++++------ .../Views/CollectionViewChallengePage.xaml.cs | 38 ++++++++++++++-- 8 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 CollectionViewChallenge/CollectionViewChallenge.Android/Resources/drawable/down_arrow.png create mode 100644 CollectionViewChallenge/CollectionViewChallenge.iOS/Resources/down_arrow.png create mode 100644 CollectionViewChallenge/CollectionViewChallenge/Models/Event.cs diff --git a/CollectionViewChallenge/CollectionViewChallenge.Android/CollectionViewChallenge.Android.csproj b/CollectionViewChallenge/CollectionViewChallenge.Android/CollectionViewChallenge.Android.csproj index b56a767..416df70 100644 --- a/CollectionViewChallenge/CollectionViewChallenge.Android/CollectionViewChallenge.Android.csproj +++ b/CollectionViewChallenge/CollectionViewChallenge.Android/CollectionViewChallenge.Android.csproj @@ -30,7 +30,11 @@ DEBUG; prompt 4 - None + SdkOnly + false + false + false + true @@ -106,5 +110,8 @@ CollectionViewChallenge + + + \ No newline at end of file diff --git a/CollectionViewChallenge/CollectionViewChallenge.Android/Resources/drawable/down_arrow.png b/CollectionViewChallenge/CollectionViewChallenge.Android/Resources/drawable/down_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..ce04ee0446010ad480c0b03b5dc9fc37a7a77527 GIT binary patch literal 285 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3EX7WqAsj$Z!;#Vf4nJ zFlm7><8~#>*+4Fm;uVBh{@M(44dFZ^=4 z6{b;5=FY_*o~>YIU#9nh&yG?3!ChY8f{WjIKV0G0y1z%%U;lmeOa2&~nae74EI a%`PXOy(|5n-A4 false x86_64 - None + SdkOnly true @@ -143,4 +143,7 @@ CollectionViewChallenge + + + \ No newline at end of file diff --git a/CollectionViewChallenge/CollectionViewChallenge.iOS/Resources/down_arrow.png b/CollectionViewChallenge/CollectionViewChallenge.iOS/Resources/down_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..ce04ee0446010ad480c0b03b5dc9fc37a7a77527 GIT binary patch literal 285 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3EX7WqAsj$Z!;#Vf4nJ zFlm7><8~#>*+4Fm;uVBh{@M(44dFZ^=4 z6{b;5=FY_*o~>YIU#9nh&yG?3!ChY8f{WjIKV0G0y1z%%U;lmeOa2&~nae74EI a%`PXOy(|5n-A - \ No newline at end of file diff --git a/CollectionViewChallenge/CollectionViewChallenge/Models/Event.cs b/CollectionViewChallenge/CollectionViewChallenge/Models/Event.cs new file mode 100644 index 0000000..7e3bebd --- /dev/null +++ b/CollectionViewChallenge/CollectionViewChallenge/Models/Event.cs @@ -0,0 +1,32 @@ +using System; +using System.ComponentModel; + +namespace CollectionViewChallenge.Models +{ + public class Event : INotifyPropertyChanged + { + public int ID { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public DateTime StartDate { get; set; } + public DateTime EndDate { get; set; } + public DateTime SubmittedOn { get; set; } + public int Points { get; set; } + + private bool _DropDownVisible; + public bool DropDownVisible + { + get { return _DropDownVisible; } + set + { + if(_DropDownVisible != value) + { + _DropDownVisible = value; + PropertyChanged(this, new PropertyChangedEventArgs("DropDownVisible")); + } + } + } + + public event PropertyChangedEventHandler PropertyChanged; + } +} diff --git a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml index e934760..c7af034 100644 --- a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml +++ b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml @@ -1,25 +1,40 @@  + x:Class="CollectionViewChallenge.Views.CollectionViewChallengePage" + BackgroundColor="#40407a"> - - - - This is a CollectionView! - Your feedback on the experience of converting a ListView to a CollectionView is incredibly appreciated. - Here are three general questions: - 1. How was the experience of converting your existing ListView to a CollectionView? - 2. How is the performance compared to the ListView? - 3. Is there a specific piece of functionality that you'd like to see? - - + - diff --git a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml.cs b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml.cs index 701124f..4ac4f54 100644 --- a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml.cs +++ b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml.cs @@ -1,8 +1,8 @@ -using System; +using CollectionViewChallenge.Models; +using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; using Xamarin.Forms; using Xamarin.Forms.Xaml; @@ -12,9 +12,41 @@ namespace CollectionViewChallenge.Views [XamlCompilation(XamlCompilationOptions.Compile)] public partial class CollectionViewChallengePage : ContentPage { + ObservableCollection obsEvents = new ObservableCollection(); + public CollectionViewChallengePage() { InitializeComponent(); + LoadCollectionView(); + cvEvents.SelectionChanged += CvEvents_SelectionChanged; + } + + private void CvEvents_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + var eventItem = (e.CurrentSelection.FirstOrDefault() as Event); + + if (eventItem is null) + return; + + //Hack to reflect the DropDownVisible changes on selected item + var iSelectedIndex = obsEvents.IndexOf(eventItem); + obsEvents.Remove(eventItem); + eventItem.DropDownVisible = !eventItem.DropDownVisible; + obsEvents.Insert(iSelectedIndex, eventItem); + + //This is required when expanded item is selected again, it should be collapsed + ((CollectionView)sender).SelectedItem = null; + } + + private void LoadCollectionView() + { + var lstEvents = new List(); + for (var i = 1; i <= 20; i++) + { + lstEvents.Add(new Event() { ID = i, Title = "Phasellus ultrices nulla quis nibh", Description = "placerat", StartDate = DateTime.Now, EndDate = DateTime.Now, SubmittedOn = DateTime.Now, Points = 2 }); + } + obsEvents = new ObservableCollection(lstEvents); + cvEvents.ItemsSource = obsEvents; } } } \ No newline at end of file