Example #1
0
  private void transformCursorData(Cursor data) {

    mMovie = new Movies().new Result();
    mMovie.setOverview(data.getString(COL_OVERVIEW));
    mMovie.setReleaseDate(data.getString(COL_DATE));
    mMovie.setPosterPath(data.getString(COL_POSTER_PATH));
    mMovie.setTitle(data.getString(COL_TITLE));
    mMovie.setVoteAverage(data.getDouble(COL_VOTE_AVG));
    if (data.getInt(COL_FAVORITE) == 1) {
      mMovie.setFavorite(1);
      Log.d(LOG_TAG, "Movie is Favorite!");
    } else mMovie.setFavorite(0);

    try {
      String reviewJson = data.getString(COL_REVIEWS);
      Type listType = new TypeToken<ArrayList<Reviews.Result>>() {}.getType();
      if (reviewJson != null) {
        if (reviewJson.length() > 3) mReviews = new Gson().fromJson(reviewJson, listType);
      } else mReviews = null;

    } catch (JsonParseException e) {
      Log.e(LOG_TAG, "Parse Exception");
    }

    try {
      String videosJson = data.getString(COL_VIDEOS);
      Type listType = new TypeToken<ArrayList<Videos.Result>>() {}.getType();
      if (videosJson != null) {
        if (videosJson.length() > 3) mVideos = new Gson().fromJson(videosJson, listType);
      } else mVideos = null;

    } catch (JsonParseException e) {
      Log.e(LOG_TAG, "Parse Exception");
    }
  }
Example #2
0
 private void favoriteStar() {
   ContentValues cv = new ContentValues();
   int toggle;
   if (mMovie.getFavorite() == 1) toggle = 0;
   else toggle = 1;
   cv.put(COLUMN_FAVORITE, toggle);
   getContext().getContentResolver().update(mUri, cv, null, null);
   // Toast could be added here.
 }
Example #3
0
  private void fillUI() {
    // add logic in order not to set twice values, loader get's called twice.
    Picasso.with(getContext()).load(mMovie.getPosterUri()).into(mImageView);
    mTitle.setText(mMovie.getTitle());
    mDate.setText(mMovie.getReleaseDate().trim().substring(0, 4));
    if (mMovie.getVoteAverage() != null)
      mVote.setText(String.valueOf(mMovie.getVoteAverage()) + "/10");
    mPlot.setText(mMovie.getOverview());

    if (!(mReviews == null || mReviews.isEmpty())) {
      for (Reviews.Result review : mReviews) {
        TextView textView = new TextView(getContext());
        textView.setLayoutParams(
            new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        textView.setText(
            getResources().getString(R.string.icon_video) + "\n" + review.getContent());
        textView.setTypeface(mFont);
        textView.setPadding(2, 2, 2, 2);
        // textView.setTextAppearance(R.s);
        mReviewsll.addView(textView);
      }
    }

    if (!(mVideos == null || mVideos.isEmpty())) {
      for (final Videos.Result video : mVideos) {
        Button button = new Button(getActivity());
        button.setLayoutParams(
            new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        button.setText(getResources().getString(R.string.icon_youtube));
        button.setTypeface(mFont);
        button.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (mVideos != null) {
                  startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(video.getUri())));
                }
              }
            });
        button.setPadding(2, 2, 2, 2);
        mTrailersll.addView(button);
      }
    }

    Log.d(LOG_TAG, getActivity().getLocalClassName().trim());

    if (getActivity().getLocalClassName().equalsIgnoreCase("DetailActivity")) {
      Log.d(LOG_TAG, "insidePhone");
      Resources r = getResources();
      float width =
          TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 185, r.getDisplayMetrics());
      float height =
          TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 262, r.getDisplayMetrics());
      mImageView.setLayoutParams(
          new LinearLayout.LayoutParams(new ViewGroup.LayoutParams((int) width, (int) height)));
    }
  }