-
Notifications
You must be signed in to change notification settings - Fork 0
/
MovieDetailsActivity.java
72 lines (51 loc) · 2.55 KB
/
MovieDetailsActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.example.flixster2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.example.flixster2.databinding.ActivityMovieDetailsBinding;
import org.parceler.Parcels;
public class MovieDetailsActivity extends AppCompatActivity {
Movie movie;
// the view objects
TextView tvTitle;
TextView tvOverview;
ImageView ivPoster;
RatingBar rbVoteAverage;
TextView tvPopularity;
ActivityMovieDetailsBinding activityMovieDetailsBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityMovieDetailsBinding = ActivityMovieDetailsBinding.inflate(getLayoutInflater());
// layout of activity is stored in a special property called root
View view = activityMovieDetailsBinding.getRoot();
setContentView(view);
//setContentView(R.layout.activity_movie_details);
// resolve the view objects
// tvTitle = (TextView) findViewById(R.id.tvTitle);
// tvOverview = (TextView) findViewById(R.id.tvOverview);
// rbVoteAverage = (RatingBar) findViewById(R.id.rbVoteAverage);
// ivPoster = (ImageView) findViewById((R.id.ivPoster));
// tvPopularity = (TextView) findViewById(R.id.tvPopularity);
// unwrap the movie passed in via intent, using its simple name as a key
movie = (Movie) Parcels.unwrap(getIntent().getParcelableExtra(Movie.class.getSimpleName()));
Log.d("MovieDetailsActivity", String.format("Showing details for '%s'", movie.getTitle()));
activityMovieDetailsBinding.tvTitle.setText(movie.getTitle());
activityMovieDetailsBinding.tvOverview.setText(movie.getOverview());
// set the title and overview
// tvTitle.setText(movie.getTitle());
// tvOverview.setText(movie.getOverview());
Glide.with(this).load(movie.getBackdropPath()).placeholder(R.drawable.flicks_movie_placeholder).into(activityMovieDetailsBinding.ivPoster);
// vote average is 0..10, convert to 0..5 by dividing by 2
float voteAverage = movie.getVoteAverage().floatValue();
activityMovieDetailsBinding.rbVoteAverage.setRating(voteAverage / 2.0f);
Double pop = movie.getPopularity();
activityMovieDetailsBinding.tvPopularity.setText("Popularity: " + pop);
}
}