예제 #1
0
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
      // Read weather condition ID from cursor
      int movieId = data.getInt(COL_MOVIE_DETAIL_ID);

      // Use weather art image
      //            mThumbnail.setImageResource(Utility.getArtResourceForWeatherCondition(movieId));

      String url = null;
      url = "http://image.tmdb.org/t/p/w185" + data.getString(COL_MOVIE_DETAIL_POSTER_PATH);
      Picasso.with(getActivity()).load(url).into(mThumbnail);

      //
      //            // Read date from cursor and update views for day of week and date
      long date = data.getLong(COL_MOVIE_DETAIL_RELEASE_DATE);
      String year = Utility.getYear(getActivity(), date);
      mYear.setText(year);

      String title = data.getString(COL_MOVIE_DETAIL_ORIGINAL_TITLE);
      mTitle.setText(title);
      //
      //            // Read rating from cursor and update view
      String rating = data.getString(COL_MOVIE_DETAIL_VOTE_AVERAGE) + "/10";
      String length = data.getString(COL_MOVIE_DETAIL_RUNTIME) + "min";
      mRating.setText(rating);
      mRuntime.setText(length);

      String overview = data.getString(COL_MOVIE_DETAIL_OVERVIEW);
      mOverview.setText(overview);
      String trailorsStr = data.getString(COL_MOVIE_DETAIL_VIDEOS);
      String[] trailors = null;
      if (trailorsStr != null) {
        trailors = trailorsStr.split(",");
      }
      String reviewsStr = data.getString(COL_MOVIE_DETAIL_REVIEWS);
      if (reviewsStr != null) {
        String[] reviews = reviewsStr.split("REVIEW_SEPARATOR");
        ReviewsAdapter reviewsAdapter =
            new ReviewsAdapter(getActivity(), android.R.layout.simple_list_item_1, reviews);
        mReviews.setAdapter(reviewsAdapter);
      }
      if (trailors != null) {
        TrailorAdapter adapter =
            new TrailorAdapter(getActivity(), android.R.layout.simple_list_item_1, trailors);
        mTrailors.setAdapter(adapter);
        mForecast = "http://www.youtube.com/watch?v=" + trailors[0];
      }
      if (data.getInt(COL_MOVIE_DETAIL_IS_FAVORITE) == 1) {
        mFav.setChecked(true);
      }

      //
      //            // For accessibility, add a content rating to the icon field
      //            mThumbnail.setContentDescription(rating);
      //
      //            // Read high temperature from cursor and update view
      //            boolean isMetric = Utility.isMetric(getActivity());
      //
      //            double high = data.getDouble(COL_WEATHER_MAX_TEMP);
      //            String highString = Utility.formatTemperature(getActivity(), high);
      //            mOverview.setText(highString);
      //
      //            // Read low temperature from cursor and update view
      //            double low = data.getDouble(COL_WEATHER_MIN_TEMP);
      //            String lowString = Utility.formatTemperature(getActivity(), low);
      //            mLowTempView.setText(lowString);
      //
      //            // Read humidity from cursor and update view
      //            float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
      //            mHumidityView.setText(getActivity().getString(R.string.format_humidity,
      // humidity));
      //
      //            // Read wind speed and direction from cursor and update view
      //            float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED);
      //            float windDirStr = data.getFloat(COL_WEATHER_DEGREES);
      //            mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr,
      // windDirStr));
      //
      //            // Read pressure from cursor and update view
      //            float pressure = data.getFloat(COL_WEATHER_PRESSURE);
      //            mPressureView.setText(getActivity().getString(R.string.format_pressure,
      // pressure));
      //
      //            // We still need this for the share intent
      //            mForecast = String.format("%s - %s - %s/%s", dateText, rating, high, low);
      //
      //            // If onCreateOptionsMenu has already happened, we need to update the share
      // intent now.
      //            if (mShareActionProvider != null) {
      //                mShareActionProvider.setShareIntent(createShareForecastIntent());
      //            }
      if (mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(createShareForecastIntent());
      }
    }
  }
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
      long movieId = ContentUris.parseId(mUri);
      title = data.getString(COL_MOVIE_TITLE);
      // fetch meta data from async task
      new TmdbApiTask(getActivity(), textView_runtime).execute(String.valueOf(movieId));

      // fetch trailer list
      new TmdbApiTask(
              getActivity(),
              listView_trailers,
              Constants.FETCH_VIDEOS,
              new TmdbApiTask.AsyncResponse() {
                @Override
                public void processFinish(String result) {
                  listView_trailers.setEmptyView(textView_empty_trailer_list);
                  if (mShareActionProvider != null) {
                    Intent shareIntent = createShareVideoIntent(result);
                    mShareActionProvider.setShareIntent(shareIntent);
                  }
                }
              })
          .execute(String.valueOf(movieId));

      // fetch reviews list
      new TmdbApiTask(
              getActivity(),
              linearListView,
              Constants.FETCH_REVIEWS,
              new TmdbApiTask.AsyncResponse() {
                @Override
                public void processFinish(String str) {
                  progressBar.setVisibility(View.GONE);
                  linearListView.setEmptyView(textView_empty_list_item);
                }
              })
          .execute(String.valueOf(movieId));

      if (getActivity().findViewById(R.id.gridView_tiles) == null) {
        // single pane
        getActivity().setTitle(title);
      }

      String year = data.getString(COL_MOVIE_DATE);

      textView_release_year.setText(title + " \n\n" + Utility.getYear(year));

      String overview = data.getString(COL_MOVIE_SYNOPSIS);
      textView_overview.setText(overview);

      String rating = data.getString(COL_MOVIE_RATING);
      textView_vote_average.setText(rating + "/10");

      String poster = data.getString(COL_MOVIE_POSTER);

      imageView_poster_detail.setContentDescription(title);
      Picasso.with(getContext())
          .load(Utility.getPoster_path(Constants.DEFAULT_POSTER_WIDTH, poster))
          .into(imageView_poster_detail);

      Boolean fav = data.getInt(COL_MOVIE_FAV) > 0;
      if (fav) {
        myFab.setSelected(true);
        myFab.setImageResource(R.drawable.ic_favorite_black_24dp);
      } else {
        myFab.setSelected(false);
        myFab.setImageResource(R.drawable.ic_favorite_border_black_24dp);
      }
    }
  }
예제 #3
0
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    Log.d(TAG, "In onLoadFinished");

    if (data != null && data.moveToFirst()) {

      while (data.moveToNext()) {
        final int moiveId = data.getInt(data.getColumnIndex(MovieEntry.COLUMN_MOVIE_ID));
        // 0:false, 1:true
        int hasTrailer = data.getInt(data.getColumnIndex(MovieEntry.COLUMN_MOVIE_HAS_VIDEO));

        if (mMovieId == moiveId) {

          String movieTitle = data.getString(data.getColumnIndex(MovieEntry.COLUMN_MOVIE_TITLE));
          ((TextView) getView().findViewById(R.id.movie_title)).setText(movieTitle);

          String movieDesc = data.getString(data.getColumnIndex(MovieEntry.COLUMN_MOVIE_DESC));
          ((TextView) getView().findViewById(R.id.movie_overview)).setText(movieDesc);

          ((TextView) getView().findViewById(R.id.movie_duration)).setText(Utility.getDuration());

          double movieVote = data.getDouble(data.getColumnIndex(MovieEntry.COLUMN_MOVIE_VOTE));
          ((TextView) getView().findViewById(R.id.movie_vote)).setText(Utility.getVote(movieVote));

          String movieYear =
              data.getString(data.getColumnIndex(MovieEntry.COLUMN_MOVIE_RELEASE_DATE));
          ((TextView) getView().findViewById(R.id.movie_release_year))
              .setText(Utility.getYear(movieYear));

          String icons = data.getString(data.getColumnIndex(MovieEntry.COLUMN_MOVIE_BACKDROP_PATH));

          ImageView iconView = (ImageView) getView().findViewById(R.id.movie_imgIcon);
          Picasso.with(getContext()).load(Utility.sBaseUrl + icons).into(iconView);
          // Log.d(TAG, "Picasso load() is called :" + Utility.sBaseUrl + icons);

          Log.d(TAG, "Movie:  - " + movieTitle + " -  " + movieYear + " - " + hasTrailer);

          mSaveFavoriteButton = (Button) getView().findViewById(R.id.btn_save_favorite);
          mSaveFavoriteButton.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  if (mMovieId != 0) {

                    if (saveFavoriteMovie(mMovieId)) {

                      Toast.makeText(getContext(), R.string.message_ok, Toast.LENGTH_SHORT).show();
                    } else {

                      Toast.makeText(
                              getContext(), R.string.message_already_saved, Toast.LENGTH_SHORT)
                          .show();
                    }

                  } else {

                    Toast.makeText(getContext(), R.string.message_not_ok, Toast.LENGTH_SHORT)
                        .show();
                  }
                }
              });
          // if the previous request indicating that this movie has video,
          // then set trailer play is visible.
          if (hasTrailer == 0) {

            ((TextView) getView().findViewById(R.id.movie_trailer_txt)).setVisibility(View.VISIBLE);
            mPlayTrailerButton = ((Button) getView().findViewById(R.id.btn_play_trailer));
            mPlayTrailerButton.setVisibility(View.VISIBLE);
            mPlayTrailerButton.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    // openBrowserToView(moiveId);
                    // openYourTubeToView(moiveId);
                    FragmentManager fm = getActivity().getSupportFragmentManager();
                    ChooseToPlayFragment dialog = ChooseToPlayFragment.newInstance(moiveId);
                    dialog.show(fm, TAG);
                  }
                });

            /*try{

            }*/
          }

          break;
        }
      }
    }
  }