use of com.esoxjem.movieguide.Movie in project MovieGuide by esoxjem.
the class MoviesListingParser method parse.
@NonNull
public static List<Movie> parse(String json) throws JSONException {
List<Movie> movies = new ArrayList<>(24);
JSONObject response = new JSONObject(json);
if (!response.isNull(RESULTS)) {
JSONArray results = response.getJSONArray(RESULTS);
for (int i = 0; i < results.length(); i++) {
movies.add(getMovie(results.getJSONObject(i)));
}
} else {
// No results
}
return movies;
}
use of com.esoxjem.movieguide.Movie in project MovieGuide by esoxjem.
the class MovieDetailsFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (getArguments() != null) {
Movie movie = (Movie) getArguments().get(Constants.MOVIE);
if (movie != null) {
this.movie = movie;
movieDetailsPresenter.setView(this);
movieDetailsPresenter.showDetails((movie));
movieDetailsPresenter.showFavoriteButton(movie);
}
}
}
use of com.esoxjem.movieguide.Movie in project MovieGuide by esoxjem.
the class FavoritesStore method setFavorite.
public void setFavorite(Movie movie) {
SharedPreferences.Editor editor = pref.edit();
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<Movie> jsonAdapter = moshi.adapter(Movie.class);
String movieJson = jsonAdapter.toJson(movie);
editor.putString(movie.getId(), movieJson);
editor.apply();
}
use of com.esoxjem.movieguide.Movie in project MovieGuide by esoxjem.
the class MovieDetailsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_details);
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey(Constants.MOVIE)) {
Movie movie = extras.getParcelable(Constants.MOVIE);
if (movie != null) {
MovieDetailsFragment movieDetailsFragment = MovieDetailsFragment.getInstance(movie);
getSupportFragmentManager().beginTransaction().add(R.id.movie_details_container, movieDetailsFragment).commit();
}
}
}
}
use of com.esoxjem.movieguide.Movie in project MovieGuide by esoxjem.
the class FavoritesStore method getFavorites.
public List<Movie> getFavorites() throws IOException {
Map<String, ?> allEntries = pref.getAll();
ArrayList<Movie> movies = new ArrayList<>(24);
Moshi moshi = new Moshi.Builder().build();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
String movieJson = pref.getString(entry.getKey(), null);
if (!TextUtils.isEmpty(movieJson)) {
JsonAdapter<Movie> jsonAdapter = moshi.adapter(Movie.class);
Movie movie = jsonAdapter.fromJson(movieJson);
movies.add(movie);
} else {
// Do nothing;
}
}
return movies;
}
Aggregations