Beispiel #1
0
        private async void lista_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                FilmesJson filme = (FilmesJson)e.ClickedItem;
                Debug.WriteLine(filme.Title);
                string data = await GetResponseFromUrl(string.Format("http://www.omdbapi.com/?i={0}&plot=full", filme.ImdbId));

                FilmesJson movie = JsonConvert.DeserializeObject <FilmesJson>(data);
                Bind(movie);
                FilmesJson fjson = (FilmesJson)DataContext;
                bool       x     = await Favorites.IsFavorite(fjson);

                IconFavorito(fjson);
            }
            catch
            {
                bool k = IsInternet();
                if (k == true)
                {
                }
                else
                {
                    NotificacaoNet();
                }
            }
        }
Beispiel #2
0
        public static async Task <bool> UnFavorite(FilmesJson favorite)
        {
            if (favorite == null || string.IsNullOrEmpty(favorite.Title))
            {
                return(false);
            }
            else
            {
                List <FilmesJson> moviesList = new List <FilmesJson>();
                StorageFolder     sfold      = ApplicationData.Current.LocalFolder;
                StorageFile       local      = await sfold.CreateFileAsync("Favorites.json", CreationCollisionOption.OpenIfExists);

                string str = await FileIO.ReadTextAsync(local);

                if (!string.IsNullOrEmpty(str))
                {
                    moviesList = GetFavorites(str);
                }
                favorite = moviesList.FirstOrDefault(p => p.Title == favorite.Title && p.ImdbId == favorite.ImdbId);
                bool resp = false;
                if (favorite != null)
                {
                    resp = moviesList.Remove(favorite);
                    JsonSerializerSettings conf = new JsonSerializerSettings {
                        NullValueHandling = NullValueHandling.Ignore
                    };
                    JArray  arr    = JArray.Parse(JsonConvert.SerializeObject(moviesList, Formatting.None, conf));
                    JObject newFav = new JObject();
                    newFav.Add("Favorites", arr);
                    await FileIO.WriteTextAsync(local, newFav.ToString());
                }
                return(resp);
            }
        }
Beispiel #3
0
 public void Bind(FilmesJson Filme)
 {
     this.DataContext = null;
     this.DataContext = Filme;
     rating.Children.Clear();
     try
     {
         Debug.WriteLine(Filme.Imdbrating);
         float i = (float)Math.Round(Convert.ToDecimal(Filme.Imdbrating)) / 2;
         for (float j = 1; i >= j; i--)
         {
             Image img = new Image();
             img.Source  = new BitmapImage(new Uri("ms-appx:///Assets/star-full-icon.png", UriKind.Absolute));
             img.Width   = 30;
             img.Height  = 30;
             img.Stretch = Stretch.UniformToFill;
             rating.Children.Add(img);
         }
         if (i >= 0.5)
         {
             Image img = new Image();
             img.Source  = new BitmapImage(new Uri("ms-appx:///Assets/star-half-icon.png", UriKind.Absolute));
             img.Width   = 15;
             img.Height  = 30;
             img.Stretch = Stretch.UniformToFill;
             rating.Children.Add(img);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #4
0
 private async void IconFavorito(FilmesJson filme)
 {
     if (await Favorites.IsFavorite(filme))
     {
         Iconfav.Tag     = "";
         Iconfav.Content = "Unfavorite";
     }
     else
     {
         Iconfav.Tag     = "";
         Iconfav.Content = "Favorite";
     }
 }
Beispiel #5
0
        private async void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            FilmesJson fjson = (FilmesJson)DataContext;
            bool       x     = await Favorites.IsFavorite(fjson);

            if (x)
            {
                await Favorites.UnFavorite(fjson);
            }
            else
            {
                await Favorites.AddFavorite(fjson);
            }
            IconFavorito(fjson);
        }
Beispiel #6
0
        private async void BotaoBusca_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                i       = 1;
                season  = SeasonS.Text;
                episode = EpisodeS.Text;
                busca   = BuscaS.Text;
                if (season.Equals("") || episode.Equals(""))
                {
                    data = await GetResponseFromUrl(string.Format("http://www.omdbapi.com/?t={0}&plot=full", busca));
                }
                else
                {
                    data = await GetResponseFromUrl(string.Format("http://www.omdbapi.com/?t={0}&Season={1}&Episode={2}", busca, season, episode));
                }
                FilmesJson movie = JsonConvert.DeserializeObject <FilmesJson>(data);
                Bind(movie);
                data = await GetResponseFromUrl(string.Format("http://www.omdbapi.com/?s={0}", busca));

                string            raw       = JObject.Parse(data).SelectToken("Search").ToString();
                List <FilmesJson> movieList = JsonConvert.DeserializeObject <List <FilmesJson> >(raw);
                lista.ItemsSource = movieList;
                FilmesJson fjson = (FilmesJson)DataContext;
                bool       x     = await Favorites.IsFavorite(fjson);

                paginasmax  = Math.Ceiling(Convert.ToDouble(JObject.Parse(data)["totalResults"].ToString()) / 10);
                Pagina.Text = i + "/" + paginasmax;
                IconFavorito(fjson);
                Voltapag.Visibility = Visibility.Visible;
                Avpag.Visibility    = Visibility.Visible;
                lista.SetValue(Grid.RowSpanProperty, 2);
            }
            catch
            {
                bool k = IsInternet();
                if (k == true)
                {
                }
                else
                {
                    NotificacaoNet();
                }
            }
        }
Beispiel #7
0
        public static async Task <bool> IsFavorite(FilmesJson favorite)
        {
            if (favorite == null || string.IsNullOrEmpty(favorite.Title))
            {
                return(false);
            }
            else
            {
                List <FilmesJson> moviesList = new List <FilmesJson>();
                StorageFolder     sfold      = ApplicationData.Current.LocalFolder;
                StorageFile       local      = await sfold.CreateFileAsync("Favorites.json", CreationCollisionOption.OpenIfExists);

                string str = await FileIO.ReadTextAsync(local);

                if (!string.IsNullOrEmpty(str))
                {
                    moviesList = GetFavorites(str);
                }
                bool resp = moviesList.FirstOrDefault(p => p.Title == favorite.Title && p.ImdbId == favorite.ImdbId) != null;
                return(resp);
            }
        }