Exemplo n.º 1
0
        public async Task Carregar()
        {
            try
            {
                using (var Dialog = UserDialogs.Instance.Loading("Carregando Pokemons", null, null, true, MaskType.Black))
                {
                    var existingList = Barrel.Current.Get <List <Pokemon> >(_key) ?? new List <Pokemon>();
                    Pokemons.Clear();


                    if (existingList.Count == 0 && !IsNotConnected)
                    {
                        await GravarPokemons();
                    }
                    else
                    {
                        foreach (var pokemon in existingList)
                        {
                            Pokemons.Add(pokemon);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
        }
        async Task GetPokemons()
        {
            if (!IsBusy)
            {
                Exception Error = null;
                try
                {
                    IsBusy = true;

                    var repository = new Repository();
                    var items      = await repository.GetPokemons();

                    Pokemons.Clear();
                    foreach (var pokemon in items)
                    {
                        Pokemons.Add(pokemon);
                    }
                }
                catch (Exception ex)
                {
                    Error = ex;
                }
                finally
                {
                    IsBusy = false;
                }

                if (Error != null)
                {
                    await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Error", Error.Message, "OK");
                }
            }
            return;
        }
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            try
            {
                Pokemons.Clear();
                var pokemons = await DataStore.GetPokemonsAsync();

                foreach (var pokemon in pokemons)
                {
                    Pokemons.Add(pokemon);
                }
                Search();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemplo n.º 4
0
        private async Task CarregarPaginaHttpExtension()
        {
            try
            {
                Ocupado = true;

                _ApiService = new HttpExtensionService();

                var pokemons = await _ApiService.GetPokemonsAsync();

                Pokemons.Clear();

                foreach (var pokemon in pokemons)
                {
                    pokemon.Image = GetImageStreamFromUrl(pokemon.Sprites.FrontDefault.AbsoluteUri);
                    Pokemons.Add(pokemon);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                _ApiService = null;
                Ocupado     = false;
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Clears all script storage.
 /// </summary>
 public static void Clear()
 {
     Pokemons.Clear();
     Strings.Clear();
     Integers.Clear();
     Booleans.Clear();
     Items.Clear();
     Singles.Clear();
     Doubles.Clear();
 }
Exemplo n.º 6
0
        private async Task RefreshCommandExecute()
        {
            if (PokemonType == null)
            {
                await LoadTypesPokemons();
            }

            Pokemons.Clear();
            offset = 0;
            await Pokemons.LoadMoreAsync();
        }
Exemplo n.º 7
0
        public async Task LoadData(PokeType type)
        {
            IsLoading = true;
            var pokemons = await Api.GetAllPokemonsFromType(type.url);

            Pokemons.Clear();

            foreach (var p in pokemons)
            {
                Pokemons.Add(p);
            }
            IsLoading = false;
        }
Exemplo n.º 8
0
        private async Task LoadPokemon()
        {
            if (_IsVisibleAllPokemon)
            {
                var result = await _pokemonService.GetPokemonAsync(_restClient, _nextPage);

                if (string.IsNullOrEmpty(_nextPage))
                {
                    Pokemons.Clear();
                    Pokemons.AddRange(result.Results);
                }
                else
                {
                    Pokemons.AddRange(result.Results);
                }

                _nextPage = result.Next;
                SetTitleAll();
            }
        }
Exemplo n.º 9
0
        private async Task GravarPokemons()
        {
            IsBusy = true;

            var pokemons = await _PokemonService.GetPokemonsAsync();

            if (pokemons != null && pokemons.Count > 0)
            {
                Pokemons.Clear();

                var existingList = Barrel.Current.Get <List <Pokemon> >(_key) ?? new List <Pokemon>();

                foreach (var pokemon in pokemons)
                {
                    var isExist = existingList.Any(e => e.Id == pokemon.Id);

                    pokemon.Image = ImageHelpers.GetImageStreamFromUrl(pokemon.Sprites.FrontDefault.AbsoluteUri);

                    pokemon.ImageBack = ImageHelpers.GetImageStreamFromUrl(pokemon.Sprites.BackDefault.AbsoluteUri);

                    pokemon.AllTypes = String.Join(",", pokemon.Types.Select(p => p.Type.Name));

                    if (!isExist)
                    {
                        existingList.Add(pokemon);
                    }

                    Pokemons.Add(pokemon);
                }

                existingList = existingList.OrderBy(e => e.Id).ToList();

                Barrel.Current.Add(_key, existingList, TimeSpan.FromDays(30));
            }

            IsBusy = false;
        }
Exemplo n.º 10
0
        private async Task CarregarPaginaRefit()
        {
            try
            {
                Ocupado = true;
                Pokemons.Clear();

                for (int i = 1; i < 20; i++)
                {
                    var pokemon = await _ApiServiceRefit.GetPokemonAsync(i);

                    pokemon.Image = GetImageStreamFromUrl(pokemon.Sprites.FrontDefault.AbsoluteUri);

                    Pokemons.Add(pokemon);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                Ocupado = false;
            }
        }