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); catalog = new Catalog (); catalog.Name = Intent.GetStringExtra ("Name"); catalog.Id = Intent.GetIntExtra ("Id", -1); SetContentView (Resource.Layout.CheckinsFragment); listViewMovies = FindViewById<ListView> (Resource.Id.listViewMovies); adapter = new MovieCatalogAdapter (this); listViewMovies.Adapter = adapter; movies = new CheckinShared.MovieDB (); moviexcatalogs = new CheckinShared.MoviexCatalogDB (); listViewMovies.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { Movie movie = movies.Get (adapter.GetMovie (e.Position).IdMovie); Intent intent = new Intent (this, typeof(MovieActivity)); intent.PutExtra ("movieId", movie.Id); intent.PutExtra ("mode", "info"); StartActivity (intent); }; ActualizarLista (); ActionBar.SetDisplayHomeAsUpEnabled (true); ActionBar.SetDisplayShowTitleEnabled (true); ActionBar.SetDisplayShowHomeEnabled (true); }