Android Open Source - UpcomingMoviesMVP Mocked Movie Details Api






From Project

Back to project page UpcomingMoviesMVP.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Defi...

If you think the Android project UpcomingMoviesMVP listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jlmd.android.newfilmsmvp.api.mock;
//w w  w  .  ja  va 2 s. c om
import android.content.Context;
import android.os.Handler;

import com.google.gson.Gson;
import com.jlmd.android.newfilmsmvp.api.mapper.Mapper;
import com.jlmd.android.newfilmsmvp.api.moviedetails.MovieDetailsApi;
import com.jlmd.android.newfilmsmvp.api.moviedetails.model.MovieDetailsResult;
import com.jlmd.android.newfilmsmvp.domain.model.MovieDetails;
import com.jlmd.android.newfilmsmvp.utils.Utils;

/**
 * @author jlmd
 */
public class MockedMovieDetailsApi implements MovieDetailsApi {

    private final Mapper movieDetailsMapper;
    private final Context context;
    private final Gson gson;
    private static final String FILE_PATH = "mock/details/";
    private static final int LOAD_DELAY_TIME = 1000;

    public MockedMovieDetailsApi(Context context,
                                 Mapper movieDetailsMapper, Gson gson) {
        this.context = context;
        this.movieDetailsMapper = movieDetailsMapper;
        this.gson = gson;
    }

    @Override
    public void getMovieDetails(int movieId, Callback callback) {
        loadMockedMoviesDelayed(movieId, callback, LOAD_DELAY_TIME);
    }

    private void loadMockedMoviesDelayed(final int movieId, final Callback callback, int delay) {
        Handler handler = new Handler();
        Runnable runnable = new Runnable() {
            public void run() {
                String json = Utils.loadJSONFromAsset(context, FILE_PATH + movieId + ".json");
                MovieDetails movieDetails = (MovieDetails) movieDetailsMapper.
                        map(gson.fromJson(json, MovieDetailsResult.class));
                callback.onFinish(movieDetails);
            }
        };
        handler.postDelayed(runnable, delay);
    }

}




Java Source Code List

com.jlmd.android.newfilmsmvp.ApplicationTest.java
com.jlmd.android.newfilmsmvp.api.mapper.Mapper.java
com.jlmd.android.newfilmsmvp.api.mapper.MovieDetailsMapper.java
com.jlmd.android.newfilmsmvp.api.mapper.UpcomingMoviesMapper.java
com.jlmd.android.newfilmsmvp.api.mock.MockedMovieDetailsApi.java
com.jlmd.android.newfilmsmvp.api.mock.MockedUpcomingMoviesApi.java
com.jlmd.android.newfilmsmvp.api.moviedetails.MovieDetailsApi.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.BelongsToCollection.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.Genre.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.MovieDetailsResult.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.ProductionCompany.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.ProductionCountry.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.SpokenLanguage.java
com.jlmd.android.newfilmsmvp.api.retrofit.moviedetails.MovieDetailsService.java
com.jlmd.android.newfilmsmvp.api.retrofit.moviedetails.RetrofitMovieDetailsApi.java
com.jlmd.android.newfilmsmvp.api.retrofit.upcomingmovies.RetrofitUpcomingMoviesApi.java
com.jlmd.android.newfilmsmvp.api.retrofit.upcomingmovies.UpcomingMoviesService.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.UpcomingMoviesApi.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.Dates.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.Result.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.UpcomingMoviesResult.java
com.jlmd.android.newfilmsmvp.bus.event.MovieSelectedEvent.java
com.jlmd.android.newfilmsmvp.di.AppApplication.java
com.jlmd.android.newfilmsmvp.di.module.ComparatorModule.java
com.jlmd.android.newfilmsmvp.di.module.PresenterModule.java
com.jlmd.android.newfilmsmvp.di.module.RepositoryModule.java
com.jlmd.android.newfilmsmvp.di.module.RootModule.java
com.jlmd.android.newfilmsmvp.domain.comparator.MovieDateComparator.java
com.jlmd.android.newfilmsmvp.domain.comparator.MovieTitleComparator.java
com.jlmd.android.newfilmsmvp.domain.formatter.Formatter.java
com.jlmd.android.newfilmsmvp.domain.formatter.GenresFormatter.java
com.jlmd.android.newfilmsmvp.domain.formatter.RatingFormatter.java
com.jlmd.android.newfilmsmvp.domain.formatter.ReleaseDateFormatter.java
com.jlmd.android.newfilmsmvp.domain.model.Image.java
com.jlmd.android.newfilmsmvp.domain.model.MovieDetails.java
com.jlmd.android.newfilmsmvp.domain.model.Movie.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MovieDetailsPresenterImp.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MovieDetailsPresenter.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MoviesListPresenterImp.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MoviesListPresenter.java
com.jlmd.android.newfilmsmvp.mvp.presenter.Presenter.java
com.jlmd.android.newfilmsmvp.mvp.view.MovieDetailsView.java
com.jlmd.android.newfilmsmvp.mvp.view.MoviesListView.java
com.jlmd.android.newfilmsmvp.mvp.view.View.java
com.jlmd.android.newfilmsmvp.ui.activity.BaseActivity.java
com.jlmd.android.newfilmsmvp.ui.activity.MainActivity.java
com.jlmd.android.newfilmsmvp.ui.activity.MovieDetailsActivity.java
com.jlmd.android.newfilmsmvp.ui.adapter.BaseRecyclerViewHolder.java
com.jlmd.android.newfilmsmvp.ui.adapter.MoviesListRecyclerAdapter.java
com.jlmd.android.newfilmsmvp.ui.fragment.BaseFragment.java
com.jlmd.android.newfilmsmvp.ui.fragment.MovieDetailsFragment.java
com.jlmd.android.newfilmsmvp.ui.fragment.MoviesListFragment.java
com.jlmd.android.newfilmsmvp.ui.view.ClickItemTouchListener.java
com.jlmd.android.newfilmsmvp.ui.view.ClickRecyclerView.java
com.jlmd.android.newfilmsmvp.utils.Constants.java
com.jlmd.android.newfilmsmvp.utils.Utils.java