protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); CheckinShared.MovieDB movies = new CheckinShared.MovieDB (); this.ActionBar.Title = "Agregar película a " + Intent.GetStringExtra ("Name"); SetContentView (Resource.Layout.AddMovie); this.SetProgressBarIndeterminateVisibility (false); this.SetProgressBarVisibility (false); ProgressBar progressbarSearch = FindViewById<ProgressBar> (Resource.Id.progressBar1); progressbarSearch.Visibility = ViewStates.Gone; SearchView searchViewMovie = FindViewById<SearchView> (Resource.Id.searchView1); ListView listViewMovies = FindViewById<ListView> (Resource.Id.listView2); MoviesAdapter adapter = new MoviesAdapter (this); listViewMovies.Adapter = adapter; listViewMovies.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e) { Intent intent = new Intent (this, typeof(AddMovieToCatalogDetailActivity)); Movie movie = adapter.GetMovie(e.Position); int count = movies.All().Where(m => m.ApiId.Equals(movie.ApiId)).Count(); if (count == 0) { movies.Insert(movie); } else { movie = movies.All().Where(m => m.ApiId.Equals(movie.ApiId)).First(); } intent.PutExtra ("Name",Intent.GetStringExtra ("Name")); intent.PutExtra ("movieId", movie.Id); intent.PutExtra ("Id",Intent.GetIntExtra("Id",-1)); StartActivityForResult (intent, 30); }; searchViewMovie.QueryTextSubmit += async delegate(object sender, SearchView.QueryTextSubmitEventArgs e) { Console.WriteLine(searchViewMovie.Query); progressbarSearch.Visibility = ViewStates.Visible; Console.WriteLine("searchViewMovie.QueryTextSubmit"); TMDB api = new TMDB(); Task<object> resultsTask = api.SearchMovies(searchViewMovie.Query); JObject results = await resultsTask as JObject; JArray moviesArray = (JArray)results["results"]; Console.WriteLine(moviesArray.Count + " movies count"); adapter.Clear(); foreach (var movieJSON in moviesArray) { Movie movie = new Movie(); movie.Title = movieJSON["title"].ToString(); movie.Year = movieJSON["release_date"].ToString().Split(new char[]{ '-' })[0]; movie.PosterPath = "http://image.tmdb.org/t/p/w154" + movieJSON["poster_path"].ToString(); movie.ApiId = movieJSON["id"].ToString(); adapter.Add(movie); } /*foreach (var movieJSON in moviesArray) { Movie movie = new Movie(); movie.Title = movieJSON["title"].ToString(); movie.Year = movieJSON["release_date"].ToString().Split(new char[]{ '-' })[0]; movie.PosterPath = "http://image.tmdb.org/t/p/w154" + movieJSON["poster_path"].ToString(); movie.ApiId = movieJSON["id"].ToString(); if (movie.Overview == null) { JObject movieOverviewJSON = await api.Find (movie.ApiId) as JObject; movie.Overview = movieOverviewJSON ["overview"].ToString (); } if (movie.Director == null) { JObject movieCreditsJSON = await api.GetCredits (movie.ApiId) as JObject; if (movieCreditsJSON ["crew"].Count () > 0) { movie.Director = movieCreditsJSON ["crew"] [0] ["name"].ToString (); } movie.Cast = ""; for (var i = 0; i < movieCreditsJSON ["cast"].Count (); i++) { movie.Cast += movieCreditsJSON ["cast"] [i] ["name"].ToString () + "\n"; } } adapter.Add(movie); }*/ progressbarSearch.Visibility = ViewStates.Gone; }; searchViewMovie.Close += delegate(object sender, SearchView.CloseEventArgs e) { progressbarSearch.Visibility = ViewStates.Gone; }; ActionBar.SetDisplayHomeAsUpEnabled (true); ActionBar.SetDisplayShowTitleEnabled (true); ActionBar.SetDisplayShowHomeEnabled (true); }
async protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); movies = new CheckinShared.MovieDB (); catalogs = new CheckinShared.CatalogDB (); SetContentView (Resource.Layout.AddMovieToCatalog); idCatalog = Intent.GetIntExtra ("Id", -1); int movieId = this.Intent.GetIntExtra ("movieId", 0); movie = movies.Get (movieId); TMDB api = new TMDB (); if (movie.Overview == null) { JObject movieJSON = await api.Find (movie.ApiId) as JObject; movie.Overview = movieJSON ["overview"].ToString (); movies.Update (movie); } JObject movieCreditsJSON = await api.GetCredits (movie.ApiId) as JObject; if (movie.Director == "" || movie.Director == null) { if (movieCreditsJSON ["crew"].Count () > 0) { for (var i = 0; i < movieCreditsJSON ["crew"].Count (); i++) { var credit = movieCreditsJSON ["crew"] [i]; if (credit ["job"].ToString () == "Director") { movie.Director = credit ["name"].ToString (); break; } } } movies.Update (movie); } if (movie.Cast == "" || movie.Cast == null) { movie.Cast = ""; for (var i = 0; i < movieCreditsJSON ["cast"].Count (); i++) { movie.Cast += movieCreditsJSON ["cast"] [i] ["name"].ToString () + "\n"; } movies.Update (movie); } movie.SaveToParse (); EditText textNombre = FindViewById<EditText> (Resource.Id.txtNombrePelicula); textNombre.Text += movie.Title; EditText textDirector = FindViewById<EditText> (Resource.Id.txtDirectorPelicula); textDirector.Text += movie.Director; EditText textFecha = FindViewById<EditText> (Resource.Id.txtAñoEstrenoPelicula); if (movie.Year != null) { textFecha.Text += movie.Year; } EditText textDescripcion = FindViewById<EditText> (Resource.Id.txtDescripcion); textDescripcion.Text += movie.Overview; imgFoto = FindViewById<ImageView> (Resource.Id.imgFoto); if (movie.PosterPath != null) { Koush.UrlImageViewHelper.SetUrlDrawable (imgFoto, movie.PosterPath); } Spinner spinnerMovieType = FindViewById<Spinner> (Resource.Id.spinnerMovieType); Button btnGuardar = FindViewById<Button> (Resource.Id.btnGuardarPelicula); Button btnCancelar = FindViewById<Button> (Resource.Id.btnCancelarPelicula); btnGuardar.Click += (object sender, EventArgs e) => { moviexcatalog = new MoviexCatalog (); movies = new CheckinShared.MovieDB (); moviexcatalogs = new CheckinShared.MoviexCatalogDB (); catalogs = new CheckinShared.CatalogDB (); Intent intent = new Intent (); movie = movies.Insert (movie); moviexcatalog.IdMovie = movie.Id; if (spinnerMovieType.SelectedItemPosition == 0) { moviexcatalog.MovieType = "Physical"; } else { moviexcatalog.MovieType = "Digital"; } if (Camera._file != null) { moviexcatalog.PhotoPath = Camera._file.Path; } else { moviexcatalog.PhotoPath = movie.PosterPath; } if (idCatalog != -1) { Catalog catalog = new Catalog (); moviexcatalog.IdCatalog = idCatalog; catalog = catalogs.Get (idCatalog); catalog.Quantity += 1; catalogs.Update (catalog); intent.PutExtra ("movieId", movie.Id); } moviexcatalogs.Insert (moviexcatalog); moviexcatalog.SaveToParse (); if (idCatalog != -1) { catalogs.Get (idCatalog).SaveToParse (); } System.Console.WriteLine (moviexcatalog.PhotoPath); intent.PutExtra ("moviexCatalogId", moviexcatalog.Id); SetResult (Result.Ok, intent); Finish (); }; btnCancelar.Click += (object sender, EventArgs e) => { Intent intent = new Intent (); SetResult (Result.Canceled, intent); Finish (); }; imgFoto.Click += (object sender, EventArgs e) => { if (IsThereAnAppToTakePictures ()) { CreateDirectoryForPictures (); TakeAPicture (sender, e); } }; ActionBar.SetDisplayHomeAsUpEnabled (true); ActionBar.SetDisplayShowTitleEnabled (true); ActionBar.SetDisplayShowHomeEnabled (true); }
async protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Movie); movies = new CheckinShared.MovieDB (); checkins = new CheckinShared.CheckinDB (); int movieId = this.Intent.GetIntExtra ("movieId", 0); mode = this.Intent.GetStringExtra ("mode"); movie = movies.Get (movieId); TMDB api = new TMDB (); if (mode != "info") { InitMapFragment (); } if (movie.Overview == null) { JObject movieJSON = await api.Find (movie.ApiId) as JObject; movie.Overview = movieJSON ["overview"].ToString (); movies.Update (movie); } if (movie.Director == null) { JObject movieCreditsJSON = await api.GetCredits (movie.ApiId) as JObject; if (movieCreditsJSON ["crew"].Count () > 0) { movie.Director = movieCreditsJSON ["crew"] [0] ["name"].ToString (); } movie.Cast = ""; for (var i = 0; i < movieCreditsJSON ["cast"].Count (); i++) { movie.Cast += movieCreditsJSON ["cast"] [i] ["name"].ToString () + "\n"; } movies.Update (movie); } movie.SaveToParse (); TextView textViewMovieTitle = FindViewById<TextView> (Resource.Id.textViewMovieTitle); TextView textViewMovieDescription = FindViewById<TextView> (Resource.Id.textViewMovieDescription); TextView textViewMovieDirector = FindViewById<TextView> (Resource.Id.textViewMovieDirector); TextView textViewMovieYear = FindViewById<TextView> (Resource.Id.textViewMovieYear); TextView textViewMovieCast = FindViewById<TextView> (Resource.Id.textViewMovieCast); ImageView imageViewMoviePoster = FindViewById<ImageView> (Resource.Id.imageViewMoviePoster); Button buttonCheckin = FindViewById<Button> (Resource.Id.buttonCheckin); Button buttonShareFacebook = FindViewById<Button> (Resource.Id.buttonShareFacebook); Button buttonShareTwitter = FindViewById<Button> (Resource.Id.buttonShareTwitter); if (mode == "info") { buttonCheckin.Visibility = ViewStates.Gone; if (mapFragment != null && mapFragment.View != null) { mapFragment.View.Visibility = ViewStates.Gone; } } textViewMovieTitle.Text = movie.Title; textViewMovieYear.Text = movie.Year; textViewMovieDescription.Text = movie.Overview; if (movie.Director != null) { textViewMovieDirector.Text = movie.Director; } else { textViewMovieDirector.Visibility = ViewStates.Gone; } if (movie.Cast != null) { textViewMovieCast.Text = movie.Cast; } else { textViewMovieCast.Visibility = ViewStates.Gone; } if (movie.Poster != null) { imageViewMoviePoster.SetImageBitmap ((Android.Graphics.Bitmap)movie.Poster); } else { Koush.UrlImageViewHelper.SetUrlDrawable (imageViewMoviePoster, movie.PosterPath); movie.Poster = Koush.UrlImageViewHelper.GetCachedBitmap (movie.PosterPath); } var self = this; buttonCheckin.Click += (object sender, EventArgs e) => { Checkin checkin = new Checkin (); checkin.MovieId = movie.Id; checkin.UserId = AppHelper.GetCurrentUser(this).Id; checkin.CreatedAt = DateTime.UtcNow; if (currentLocation != null) { checkin.Latitude = currentLocation.Latitude; checkin.Longitude = currentLocation.Longitude; } checkins.Insert (checkin); checkin.SaveToParse(); Intent intent = new Intent (); intent.PutExtra ("checkinId", checkin.Id); intent.PutExtra ("movieId", movie.Id); SetResult (Result.Ok, intent); Finish (); }; var sharedPreferences = GetSharedPreferences ("CheckinAppPreferences", FileCreationMode.WorldWriteable); buttonShareFacebook.Click += async (object sender, EventArgs e) => { var facebookClient = new CheckinShared.Facebook ("1492339931014967", "7ae094df0f071a1972ed7c7354943f9a"); facebookClient.UserToken = sharedPreferences.GetString ("Facebook:token", ""); if (facebookClient.UserToken != "") { try { string result = await facebookClient.PublishFeed (new { message = "Estoy viendo " + movie.Title, link = "https://www.themoviedb.org/movie/" + movie.ApiId, picture = movie.PosterPath, name = movie.Title, caption = movie.Year, description = movie.Overview }) as string; Console.WriteLine ("result: " + result); Toast.MakeText (self, "Película compartida en Facebook", ToastLength.Short).Show (); } catch (Exception ex) { Console.WriteLine ("ex.StackTrace"); Console.WriteLine (ex.StackTrace); Console.WriteLine ("ex.StackTrace"); Toast.MakeText (self, "Hubo un error al compartir la película: " + ex.Source, ToastLength.Long).Show (); } } else { Intent intent = new Intent (this, typeof(AuthActivity)); intent.PutExtra ("authService", "Facebook"); StartActivityForResult (intent, (int)RequestsConstants.AuthRequest); } }; buttonShareTwitter.Click += async (object sender, EventArgs e) => { var twitterClient = new CheckinShared.Twitter ("IO0mSObd1KnbSOkZXBvGchomD", "JiCrmSCOp0AR2m0zIjoY8Cq1STTbcjEPupMdpOkEihmHViQ5Lh"); twitterClient.UserToken = sharedPreferences.GetString ("Twitter:token", ""); twitterClient.UserSecret = sharedPreferences.GetString ("Twitter:secret", ""); if (twitterClient.UserToken != "" && twitterClient.UserSecret != "") { try { string result = await twitterClient.UpdateStatus (new { status = "Estoy viendo " + movie.Title + " (" + "https://www.themoviedb.org/movie/" + movie.ApiId + ")" }) as string; Console.WriteLine ("result: " + result); Toast.MakeText (self, "Película compartida en Twitter", ToastLength.Short).Show (); } catch (Exception ex) { Console.WriteLine ("ex.Message"); Console.WriteLine (ex.Message); Console.WriteLine ("ex.Message"); Toast.MakeText (self, "Hubo un error al compartir la película: " + ex.Source, ToastLength.Long).Show (); } } else { Intent intent = new Intent (this, typeof(AuthActivity)); intent.PutExtra ("authService", "Twitter"); StartActivityForResult (intent, (int)RequestsConstants.AuthRequest); } }; ActionBar.SetDisplayHomeAsUpEnabled (true); ActionBar.SetDisplayShowTitleEnabled (true); ActionBar.SetDisplayShowHomeEnabled (true); ActionBar.SetDisplayUseLogoEnabled (false); Window.SetTitle (movie.Title); }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); movies = new CheckinShared.MovieDB (); SetContentView (Resource.Layout.AddMovie); this.SetProgressBarIndeterminateVisibility (false); this.SetProgressBarVisibility (false); ProgressBar progressbarSearch = FindViewById<ProgressBar> (Resource.Id.progressBar1); progressbarSearch.Visibility = ViewStates.Gone; SearchView searchViewMovie = FindViewById<SearchView> (Resource.Id.searchView1); ListView listViewMovies = FindViewById<ListView> (Resource.Id.listView2); MoviesAdapter adapter = new MoviesAdapter (this); listViewMovies.Adapter = adapter; listViewMovies.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e) { Movie movie = adapter.GetMovie(e.Position); int count = movies.All().Where(m => m.ApiId.Equals(movie.ApiId)).Count(); if (count == 0) { movies.Insert(movie); } else { movie = movies.All().Where(m => m.ApiId.Equals(movie.ApiId)).First(); } Console.WriteLine("Movie count: " + count); Intent intent = new Intent (this, typeof(MovieActivity)); intent.PutExtra("movieId", movie.Id); StartActivityForResult (intent, (int) RequestsConstants.MovieInfoRequest); /*Movie movie = adapter.GetMovie(e.Position); movies.Insert(movie); Intent intent = new Intent(); intent.PutExtra("movieId", movie.Id); SetResult(Result.Ok, intent); Finish();*/ }; searchViewMovie.QueryTextSubmit += async delegate(object sender, SearchView.QueryTextSubmitEventArgs e) { Console.WriteLine(searchViewMovie.Query); progressbarSearch.Visibility = ViewStates.Visible; TMDB api = new TMDB(); Task<object> resultsTask = api.SearchMovies(searchViewMovie.Query); JObject results = await resultsTask as JObject; JArray moviesArray = (JArray)results["results"]; Console.WriteLine(moviesArray.Count + " movies count"); adapter.Clear(); foreach (var movieJSON in moviesArray) { Movie movie = new Movie(); movie.Title = movieJSON["title"].ToString(); movie.Year = movieJSON["release_date"].ToString().Split(new char[]{ '-' })[0]; movie.PosterPath = "http://image.tmdb.org/t/p/w154" + movieJSON["poster_path"].ToString(); movie.ApiId = movieJSON["id"].ToString(); adapter.Add(movie); } progressbarSearch.Visibility = ViewStates.Gone; }; searchViewMovie.Close += delegate(object sender, SearchView.CloseEventArgs e) { progressbarSearch.Visibility = ViewStates.Gone; }; ActionBar.SetDisplayHomeAsUpEnabled (true); ActionBar.SetDisplayShowTitleEnabled (true); ActionBar.SetDisplayShowHomeEnabled (true); }