public CategoryList(string cname) { InitializeComponent(); DonationAdverts = new ObservableCollection <Advert>(); ExchangeAdverts = new ObservableCollection <Advert>(); BindingContext = advertViewModel; CName = cname; this.CategoryName.Text = CName; var back_tap = new TapGestureRecognizer(); back_tap.Tapped += async(s, e) => { await Navigation.PopAsync(); }; back.GestureRecognizers.Add(back_tap); DonationsListView.ItemsSource = DonationAdverts; ExchangesListView.ItemsSource = ExchangeAdverts; OnAppearing(); DonationsListView.RefreshCommand = new Command(async() => { DonationsListView.RefreshControlColor = Color.FromHex("#1B9101"); DonationsListView.IsRefreshing = true; var donationAdverts = await advertViewModel.GetDonationAdverts(); foreach (var item in donationAdverts) { if ((item.BookCategory.ToString() == CategoryName.Text)) { DonationsListView.ItemsSource = DonationAdverts; } } DonationsListView.IsRefreshing = false; }); ExchangesListView.RefreshCommand = new Command(async() => { ExchangesListView.RefreshControlColor = Color.FromHex("#00B5B9"); ExchangesListView.IsRefreshing = true; var exchangeAdverts = await advertViewModel.GetExchangeAdverts(); foreach (var item in exchangeAdverts) { if ((item.BookCategory.ToString() == CategoryName.Text)) { ExchangesListView.ItemsSource = ExchangeAdverts; } } ExchangesListView.IsRefreshing = false; }); }
public async Task getItems() { var donationAdverts = await advertViewModel.GetDonationAdverts(); //List reversed to show people last adverts. donationAdverts.Reverse(); foreach (var item in donationAdverts) { if (!userAdverts.Any((arg) => arg.AdvertID == item.AdvertID)) { if ((item.ShareType.ToString() == shareName.Text)) { userAdverts.Add(item); } } } //------------------------------------------------------------------------ //-------------- To show Donation Adverts on the main page var exchangeAdverts = await advertViewModel.GetExchangeAdverts(); //List reversed to show people last adverts. exchangeAdverts.Reverse(); foreach (var item in exchangeAdverts) { if (!userAdverts.Any((arg) => arg.AdvertID == item.AdvertID)) { if ((item.ShareType.ToString() == shareName.Text)) { userAdverts.Add(item); } } } howMany.Text = userAdverts.Count().ToString() + " adverts found."; }
public HomePage() { InitializeComponent(); var myadverts_tap = new TapGestureRecognizer(); myadverts_tap.Tapped += async(s, e) => { await Navigation.PushAsync(new MyAdverts());; }; myAdverts.GestureRecognizers.Add(myadverts_tap); Messages = new ObservableCollection <Message>(); DonationAdverts = new ObservableCollection <Advert>(); ExchangeAdverts = new ObservableCollection <Advert>(); BindingContext = advertViewModel; var Categories = new List <Category> { new Category { CategoryName = "TYT AYT", CategoryImage = "Tyt.png" }, new Category { CategoryName = "LGS", CategoryImage = "Lgs.jpg" }, new Category { CategoryName = "YDS TOEFL", CategoryImage = "Toefl.jpg" }, new Category { CategoryName = "Academic Book", CategoryImage = "Academic.png" }, new Category { CategoryName = "Children's Book", CategoryImage = "Children.png" }, new Category { CategoryName = "Novel", CategoryImage = "Novel.jpg" }, new Category { CategoryName = "Poem", CategoryImage = "Poem.png" }, new Category { CategoryName = "Comic Book", CategoryImage = "comicbook.jpg" }, new Category { CategoryName = "Others", CategoryImage = "Others.png" } }; CategoryListView.ItemsSource = Categories; DonationsListView.ItemsSource = DonationAdverts; ExchangesListView.ItemsSource = ExchangeAdverts; MessageListView.ItemsSource = Messages; OnAppearing(); DonationsListView.RefreshCommand = new Command(async() => { DonationsListView.RefreshControlColor = Color.FromHex("#1B9101"); DonationsListView.IsRefreshing = true; var donationAdverts = await advertViewModel.GetDonationAdverts(); foreach (var item in donationAdverts) { if (!DonationAdverts.Any((arg) => arg.AdvertID == item.AdvertID)) { DonationAdverts.Add(item); } } DonationsListView.ItemsSource = DonationAdverts; DonationsListView.IsRefreshing = false; }); ExchangesListView.RefreshCommand = new Command(async() => { ExchangesListView.RefreshControlColor = Color.FromHex("#00B5B9"); ExchangesListView.IsRefreshing = true; var exchangeAdverts = await advertViewModel.GetExchangeAdverts(); foreach (var item in exchangeAdverts) { if (!ExchangeAdverts.Any((arg) => arg.AdvertID == item.AdvertID)) { ExchangeAdverts.Add(item); } } ExchangesListView.ItemsSource = ExchangeAdverts; ExchangesListView.IsRefreshing = false; }); ExchangesListView.RefreshCommand = new Command(async() => { var Mainapp = Application.Current as App; var messages = await advertViewModel.GetMessages(); messages.Reverse(); foreach (var item in messages) { if (!Messages.Any((arg) => arg.Id == item.Id)) { if (!Messages.Any((arg) => item.Sender == arg.Sender && item.SpecialBookName == arg.SpecialBookName)) { if ((item.Receiver.ToString() == Mainapp.Email)) { Messages.Add(item); } } } } }); }