コード例 #1
0
		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);
		}
コード例 #2
0
		public override bool OnOptionsItemSelected (IMenuItem item)
		{
			if (item.ItemId == 1) {
				MoviexCatalog moviexcatalog = new MoviexCatalog ();
				movies = new CheckinShared.MovieDB ();
				moviexcatalogs = new CheckinShared.MoviexCatalogDB ();
				catalogs = new CheckinShared.CatalogDB ();

				Intent intent = new Intent ();
				movie.Poster = Camera.bitmap;
				movie = movies.Insert (movie);
				moviexcatalog.IdMovie = movie.Id;

				if (idCatalog != -1) {
					Catalog catalog = new Catalog ();
					moviexcatalog.IdCatalog = idCatalog;
					moviexcatalogs.Insert (moviexcatalog);
					catalog = catalogs.Get (idCatalog);
					catalog.Quantity += 1;
					catalogs.Update (catalog);

					intent.PutExtra ("movieId", movie.Id);
				}
				SetResult (Result.Ok, intent);
				Finish ();
			}
			return base.OnOptionsItemSelected (item);
		}