Back to project page UpcomingMoviesMVP.
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.
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); } }