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); }
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); }