Example #1
0
        public void SortButtonClick(object sender, System.EventArgs args)
        {
            sortListPizza++;
            int lastEnumIndex = Enum.GetNames(typeof(E_sort)).Length - 1;

            if ((int)sortListPizza > lastEnumIndex)
            {
                sortListPizza = E_sort.SORT_NONE;
            }
            sortButton.Source         = GetImageSourceFromSort(sortListPizza);
            listViewPizza.ItemsSource = GetPizzaCells(GetPizzasFromSort(sortListPizza, pizzas), favoryPizzas);
            Application.Current.Properties[KEY_SORT] = (int)sortListPizza;
            Application.Current.SavePropertiesAsync();
        }
Example #2
0
 public MainPage()
 {
     InitializeComponent();
     // read favory
     LoadFavList();
     // check sorting mode
     if (Application.Current.Properties.ContainsKey(KEY_SORT))
     {
         sortListPizza     = (E_sort)Application.Current.Properties[KEY_SORT];
         sortButton.Source = GetImageSourceFromSort(sortListPizza);
     }
     // Command for favories buttons
     listViewPizza.RefreshCommand = new Command((obj) =>
     {
         DownloadData((pizzas) =>
         {
             if (pizzas != null)
             {
                 listViewPizza.ItemsSource = GetPizzaCells(GetPizzasFromSort(sortListPizza, pizzas), favoryPizzas);
             }
         });
         listViewPizza.IsRefreshing = false;
     });
     listViewPizza.IsVisible = false;
     waitLayout.IsVisible    = true;
     if (File.Exists(jsonFileName))
     {
         string pizzasJson = File.ReadAllText(jsonFileName);
         if (!String.IsNullOrEmpty(pizzasJson))
         {
             pizzas = JsonConvert.DeserializeObject <List <Pizza> >(pizzasJson);
             listViewPizza.ItemsSource = GetPizzaCells(GetPizzasFromSort(sortListPizza, pizzas), favoryPizzas);
             listViewPizza.IsVisible   = true;
             waitLayout.IsVisible      = false;
         }
     }
     DownloadData((pizzas) =>
     {
         if (pizzas != null)
         {
             listViewPizza.ItemsSource = GetPizzaCells(GetPizzasFromSort(sortListPizza, pizzas), favoryPizzas);
             listViewPizza.IsVisible   = true;
             waitLayout.IsVisible      = false;
         }
     });
 }
Example #3
0
        private List <Pizza> GetPizzasFromSort(E_sort sort, List <Pizza> pizzas)
        {
            if (pizzas == null)
            {
                return(null);
            }
            List <Pizza> ret = new List <Pizza>(pizzas);

            switch (sort)
            {
            case E_sort.SORT_NAME:
            case E_sort.SORT_FAV:
                ret.Sort((p1, p2) => { return(p1.titre.CompareTo(p2.titre)); });
                break;

            case E_sort.SORT_PRICE:
                ret.Sort((p1, p2) => { return(p2.prix.CompareTo(p1.prix)); });
                break;
            }
            return(ret);
        }
Example #4
0
        private string GetImageSourceFromSort(E_sort sort)
        {
            string ret;

            switch (sort)
            {
            case E_sort.SORT_NAME:
                ret = "sort_nom.png";
                break;

            case E_sort.SORT_PRICE:
                ret = "sort_prix.png";
                break;

            case E_sort.SORT_FAV:
                ret = "sort_fav.png";
                break;

            default:
                ret = "sort_none.png";
                break;
            }
            return(ret);
        }