-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradlew
160 lines (112 loc) · 5.02 KB
/
gradlew
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.example.dell.moviestage2;
import android.arch.lifecycle.ViewModelProvider;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.dell.moviestage2.Adapter.MovieAdapter;
import com.example.dell.moviestage2.Database.AppDatabase;
import com.example.dell.moviestage2.Model.AddTaskViewModelFactory;
import com.example.dell.moviestage2.Model.MainViewModel;
import com.example.dell.moviestage2.Model.Movie;
import com.example.dell.moviestage2.Utils.SectionLoader;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
public class MovieDetailActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<ArrayList<Movie>> {
private static final String LOG_TAG = MovieDetailActivity.class.getName();
public static final String URL_SCHEME = "https";
public static final String BASE_URL = "www.youtube.com";
public static final String PATH2 = "/watch";
private boolean isFavourite = false;
private AppDatabase database;
private TextView vote_average_view, release_date_view, synopsis_view;
private ImageView poster;
private ImageButton favourite;
private Context context;
private String release_date, synopsis, vote_average, movie_poster;
private int id;
private static final int LOADER_ID = 2;
private static final String PATH = "videos";
private RecyclerView recyclerView;
private MovieAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_detail);
context = getApplicationContext();
recyclerView = findViewById(R.id.recyclerView);
vote_average_view = (TextView)findViewById(R.id.detailAverage);
release_date_view = findViewById(R.id.detailRelease);
synopsis_view = findViewById(R.id.detailOverview);
poster = findViewById(R.id.detailImage);
favourite = findViewById(R.id.imageButton);
database = AppDatabase.getsInstance(getApplicationContext());
LoaderManager loaderManager = LoaderManager.getInstance(this);
loaderManager.initLoader(LOADER_ID, null, this);
}
private String buildUrlWithId(int id) {
Uri.Builder builder = new Uri.Builder();
builder.scheme(MainActivity.URL_SCHEME).authority(MainActivity.BASE_URL).path(MainActivity.PATH);
builder.appendPath(String.valueOf(id));
builder.appendEncodedPath(PATH);
builder.appendQueryParameter("api_key", MainActivity.api_key);
return builder.toString();
}
public void showTrailers(View view){
Intent intent = new Intent(this, TrailerActivity.class);
startActivity(intent);
}
@NonNull
@Override
public Loader<ArrayList<Movie>> onCreateLoader(int i, @Nullable Bundle bundle) {
Intent intent = getIntent();
Movie movie = intent.getParcelableExtra("result");
getSupportActionBar().setTitle(movie.getTitle());
String url = "http://image.tmdb.org/t/p/w185/";
Picasso.with(context).load(url+movie.getMovie_poster()).into(poster);
favourite.setImageResource(R.drawable.ic_favorite_border_black_24dp);
id = movie.getId();
if(movie.getRelease_date() == null) {
release_date_view.setText(R.string.not_known);
}else{
release_date = movie.getRelease_date();
release_date_view.setText(release_date);
}
if(movie.getSynopsis() == null) {
synopsis_view.setText(R.string.not_known);
}else{
synopsis = movie.getSynopsis();
synopsis_view.setText(synopsis);
}
vote_average = String.valueOf(movie.getVote_average());
vote_average_view.setText(vote_average);
String baseUrl = buildUrlWithId(id);
return new SectionLoader(context, baseUrl, LOADER_ID);
}
@Override
public void onLoadFinished(@NonNull Loader<ArrayList<Movie>> loader, ArrayList<Movie> movies) {
Log.e(LOG_TAG, String.valueOf(movies));
adapter = new MovieAdapter(context, movies);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setAdapter(adapter);
}
@Override
public void onLoaderReset(@NonNull Loader<ArrayList<Movie>> loader) {
}
public void favouriteClicked(View view){
if(isFavourite == false) {
favourite.setImageResource(R.drawable.ic_favorite_black_24dp);
isF