Search in sources :

Example 1 with Movie

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;
}
Also used : Movie(com.esoxjem.movieguide.Movie) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) NonNull(android.support.annotation.NonNull)

Example 2 with Movie

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);
        }
    }
}
Also used : Movie(com.esoxjem.movieguide.Movie)

Example 3 with 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();
}
Also used : Movie(com.esoxjem.movieguide.Movie) Moshi(com.squareup.moshi.Moshi) SharedPreferences(android.content.SharedPreferences)

Example 4 with Movie

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();
            }
        }
    }
}
Also used : Movie(com.esoxjem.movieguide.Movie) Bundle(android.os.Bundle)

Example 5 with Movie

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;
}
Also used : Movie(com.esoxjem.movieguide.Movie) Moshi(com.squareup.moshi.Moshi) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

Movie (com.esoxjem.movieguide.Movie)5 Moshi (com.squareup.moshi.Moshi)2 ArrayList (java.util.ArrayList)2 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 Map (java.util.Map)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1