fixed scrollview
This commit is contained in:
@@ -19,9 +19,6 @@ import net.headlezz.udacityproject1.tmdbapi.TMDBApi;
|
|||||||
*/
|
*/
|
||||||
public class MovieDetailsFragment extends Fragment {
|
public class MovieDetailsFragment extends Fragment {
|
||||||
|
|
||||||
// TODO make me pretty
|
|
||||||
// TODO not scrolling to the end
|
|
||||||
|
|
||||||
public static final String TAG = MovieDetailsFragment.class.getSimpleName();
|
public static final String TAG = MovieDetailsFragment.class.getSimpleName();
|
||||||
public static final String BUNDLE_ARG_MOVIE = "movie";
|
public static final String BUNDLE_ARG_MOVIE = "movie";
|
||||||
|
|
||||||
@@ -69,7 +66,7 @@ public class MovieDetailsFragment extends Fragment {
|
|||||||
TMDBApi.loadPoster(ivPoster, mMovie);
|
TMDBApi.loadPoster(ivPoster, mMovie);
|
||||||
tvTitle.setText(mMovie.getTitle());
|
tvTitle.setText(mMovie.getTitle());
|
||||||
tvOverview.setText(mMovie.getOverview());
|
tvOverview.setText(mMovie.getOverview());
|
||||||
String formatedDate = DateUtils.formatDateTime(tvReleaseDate.getContext(), mMovie.getReleaseDate(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_YEAR);
|
String formatedDate = DateUtils.formatDateTime(tvReleaseDate.getContext(), mMovie.getReleaseDate().getTime(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_YEAR);
|
||||||
tvReleaseDate.setText(getString(R.string.movie_release_date, formatedDate));
|
tvReleaseDate.setText(getString(R.string.movie_release_date, formatedDate));
|
||||||
tvRating.setText(getString(R.string.movie_rating, mMovie.getAvRating()));
|
tvRating.setText(getString(R.string.movie_rating, mMovie.getAvRating()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.headlezz.udacityproject1.tmdbapi.Movie;
|
import net.headlezz.udacityproject1.tmdbapi.Movie;
|
||||||
@@ -29,9 +30,6 @@ import retrofit.Call;
|
|||||||
*/
|
*/
|
||||||
public class MovieListFragment extends Fragment {
|
public class MovieListFragment extends Fragment {
|
||||||
|
|
||||||
// TODO fix restore
|
|
||||||
// TODO show progressbar while loading
|
|
||||||
|
|
||||||
public static final String TAG = MovieListFragment.class.getSimpleName();
|
public static final String TAG = MovieListFragment.class.getSimpleName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +44,7 @@ public class MovieListFragment extends Fragment {
|
|||||||
private int mSortingOrder = TMDBApi.SORT_ORDER_MOST_POPULAR;
|
private int mSortingOrder = TMDBApi.SORT_ORDER_MOST_POPULAR;
|
||||||
|
|
||||||
RecyclerView mMovieGridView;
|
RecyclerView mMovieGridView;
|
||||||
|
ProgressBar mProgressBar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holding a reference to running api calls. This makes it possible to cancel them if
|
* Holding a reference to running api calls. This makes it possible to cancel them if
|
||||||
@@ -63,6 +62,7 @@ public class MovieListFragment extends Fragment {
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_movie_list, container, false);
|
View view = inflater.inflate(R.layout.fragment_movie_list, container, false);
|
||||||
mMovieGridView = (RecyclerView) view.findViewById(R.id.movie_list_grid);
|
mMovieGridView = (RecyclerView) view.findViewById(R.id.movie_list_grid);
|
||||||
|
mProgressBar = (ProgressBar) view.findViewById(R.id.movie_list_progressBar);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,6 +70,9 @@ public class MovieListFragment extends Fragment {
|
|||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
mMovieGridView.setLayoutManager(new GridLayoutManager(getActivity(), getNumColumns()));
|
mMovieGridView.setLayoutManager(new GridLayoutManager(getActivity(), getNumColumns()));
|
||||||
|
|
||||||
|
if(savedInstanceState != null)
|
||||||
|
mSortingOrder = savedInstanceState.getInt("sort_order");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,17 +121,21 @@ public class MovieListFragment extends Fragment {
|
|||||||
* mSortingOrder will be used to determine the sorting
|
* mSortingOrder will be used to determine the sorting
|
||||||
*/
|
*/
|
||||||
private void loadMovieList() {
|
private void loadMovieList() {
|
||||||
|
mProgressBar.setVisibility(View.VISIBLE);
|
||||||
stopLoadingMovies(); // stop any running query before starting a new one
|
stopLoadingMovies(); // stop any running query before starting a new one
|
||||||
MovieListCallback cb = new MovieListCallback() {
|
MovieListCallback cb = new MovieListCallback() {
|
||||||
@Override
|
@Override
|
||||||
protected void onResponse(MovieList movies) {
|
protected void onResponse(MovieList movies) {
|
||||||
setListToGrid(movies.getList());
|
setListToGrid(movies.getList());
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable t) {
|
public void onFailure(Throwable t) {
|
||||||
Log.d(TAG, t.getMessage());
|
Log.d(TAG, t.getClass().getSimpleName() + " " + t.getMessage());
|
||||||
Toast.makeText(getActivity(), "Somethig went wrong", Toast.LENGTH_SHORT).show();
|
mProgressBar.setVisibility(View.GONE);
|
||||||
|
if(!t.getMessage().equals("Canceled") && getActivity() != null)
|
||||||
|
Toast.makeText(getActivity(), t.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mMovieListCall = TMDBApi.discoverMovies(mSortingOrder, getString(R.string.api_key));
|
mMovieListCall = TMDBApi.discoverMovies(mSortingOrder, getString(R.string.api_key));
|
||||||
@@ -161,4 +168,10 @@ public class MovieListFragment extends Fragment {
|
|||||||
if(!(context instanceof MovieNavigation))
|
if(!(context instanceof MovieNavigation))
|
||||||
throw new RuntimeException("Activity must implement " + MovieNavigation.class.getSimpleName());
|
throw new RuntimeException("Activity must implement " + MovieNavigation.class.getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putInt("sort_order", mSortingOrder);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package net.headlezz.udacityproject1.tmdbapi;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data object to represent a single movie
|
* Data object to represent a single movie
|
||||||
* Only required data from the api is stored to save memory
|
* Only required data from the api is stored to save memory
|
||||||
@@ -13,10 +17,17 @@ public class Movie implements Parcelable {
|
|||||||
public Movie() {}
|
public Movie() {}
|
||||||
|
|
||||||
String title;
|
String title;
|
||||||
|
|
||||||
|
@SerializedName("poster_path")
|
||||||
String posterPath;
|
String posterPath;
|
||||||
|
|
||||||
String overview;
|
String overview;
|
||||||
|
|
||||||
|
@SerializedName("vote_average")
|
||||||
double avRating;
|
double avRating;
|
||||||
long releaseDate;
|
|
||||||
|
@SerializedName("release_date")
|
||||||
|
Date releaseDate;
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
@@ -34,7 +45,7 @@ public class Movie implements Parcelable {
|
|||||||
return avRating;
|
return avRating;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getReleaseDate() {
|
public Date getReleaseDate() {
|
||||||
return releaseDate;
|
return releaseDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +62,7 @@ public class Movie implements Parcelable {
|
|||||||
dest.writeString(posterPath);
|
dest.writeString(posterPath);
|
||||||
dest.writeString(overview);
|
dest.writeString(overview);
|
||||||
dest.writeDouble(avRating);
|
dest.writeDouble(avRating);
|
||||||
dest.writeLong(releaseDate);
|
dest.writeLong(releaseDate.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<Movie> CREATOR = new Parcelable.Creator<Movie>() {
|
public static final Parcelable.Creator<Movie> CREATOR = new Parcelable.Creator<Movie>() {
|
||||||
@@ -69,7 +80,7 @@ public class Movie implements Parcelable {
|
|||||||
posterPath = src.readString();
|
posterPath = src.readString();
|
||||||
overview = src.readString();
|
overview = src.readString();
|
||||||
avRating = src.readDouble();
|
avRating = src.readDouble();
|
||||||
releaseDate = src.readLong();
|
releaseDate = new Date(src.readLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package net.headlezz.udacityproject1.tmdbapi;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper class for list of movies
|
||||||
|
*/
|
||||||
public class MovieList {
|
public class MovieList {
|
||||||
|
|
||||||
public MovieList(List<Movie> movieList) {
|
public MovieList(List<Movie> movieList) {
|
||||||
|
|||||||
@@ -1,37 +1,27 @@
|
|||||||
package net.headlezz.udacityproject1.tmdbapi;
|
package net.headlezz.udacityproject1.tmdbapi;
|
||||||
|
|
||||||
import android.util.Log;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonDeserializer;
|
import com.google.gson.JsonDeserializer;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gson deserializer for movie lists
|
||||||
|
*/
|
||||||
public class MovieListDeserializer implements JsonDeserializer<MovieList> {
|
public class MovieListDeserializer implements JsonDeserializer<MovieList> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MovieList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public MovieList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-DD").create();
|
||||||
List<Movie> movieList = new ArrayList<>();
|
List<Movie> movieList = new ArrayList<>();
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD");
|
|
||||||
for(JsonElement elem : json.getAsJsonObject().getAsJsonArray("results")) {
|
for(JsonElement elem : json.getAsJsonObject().getAsJsonArray("results")) {
|
||||||
try { // TODO fix this and remove try/catch
|
movieList.add(gson.fromJson(elem, Movie.class));
|
||||||
JsonObject jsonObj = elem.getAsJsonObject();
|
|
||||||
Movie m = new Movie();
|
|
||||||
m.title = jsonObj.get("title").getAsString();
|
|
||||||
m.overview = jsonObj.get("overview").getAsString();
|
|
||||||
m.avRating = jsonObj.get("vote_average").getAsDouble();
|
|
||||||
m.posterPath = jsonObj.get("poster_path").getAsString();
|
|
||||||
m.releaseDate = sdf.parse(jsonObj.get("release_date").getAsString()).getTime();
|
|
||||||
movieList.add(m);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(MovieListDeserializer.class.getSimpleName(), e.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new MovieList(movieList);
|
return new MovieList(movieList);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 102 KiB |
@@ -7,7 +7,7 @@
|
|||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/movie_details_tvTitle"
|
android:id="@+id/movie_details_tvTitle"
|
||||||
@@ -19,12 +19,11 @@
|
|||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/movie_details_ivPoster"
|
android:id="@+id/movie_details_ivPoster"
|
||||||
android:layout_width="150dp"
|
android:layout_width="150dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="223dp"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_below="@+id/movie_details_tvTitle"
|
android:layout_below="@+id/movie_details_tvTitle"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true" />
|
||||||
tools:src="@drawable/chappie_ver4" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivityFragment">
|
tools:context=".MainActivityFragment">
|
||||||
@@ -9,4 +9,12 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
<ProgressBar
|
||||||
|
android:visibility="gone"
|
||||||
|
android:id="@+id/movie_list_progressBar"
|
||||||
|
android:indeterminate="true"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
<string name="app_name">UdacityProject1</string>
|
<string name="app_name">UdacityProject1</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="movie_release_date">Release: %1$s</string>
|
<string name="movie_release_date">Release: %1$s</string>
|
||||||
<string name="movie_rating">Rating: %1$s/10</string>
|
<string name="movie_rating">Rating: %1$s/10.0</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user