Android Open Source - iwannawatch-android App Module






From Project

Back to project page iwannawatch-android.

License

The source code is released under:

MIT License

If you think the Android project iwannawatch-android 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.meoyawn.iwannawatch;
//from  w  w  w  .j a  va2s. c o m
import android.content.Context;
import android.net.ConnectivityManager;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.meoyawn.iwannawatch.doers.TheMovieDbApi;
import com.meoyawn.iwannawatch.models.Movie;
import com.meoyawn.iwannawatch.qualifiers.Delete;
import com.meoyawn.iwannawatch.qualifiers.Done;
import com.squareup.okhttp.HttpResponseCache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.OkHttpDownloader;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import retrofit.RestAdapter;
import retrofit.client.OkClient;
import retrofit.converter.JacksonConverter;
import rx.subjects.PublishSubject;
import timber.log.Timber;

/**
 * Created by adel on 3/1/14
 */
@Module(injects = {MainFragment.class, MovieView.class})
public class AppModule {
    final Context context;

    public AppModule(Context context) { this.context = context;}

    @Provides Context provideContext() { return context; }

    @Provides @Singleton OkHttpClient provideOkHttpClient(Context context) {
        OkHttpClient okHttpClient = new OkHttpClient();
        try {
            File cacheDir = new File(App.getCacheDir(context), "http");
            okHttpClient.setResponseCache(new HttpResponseCache(cacheDir, 20 * 1024 * 1024));
        } catch (IOException ignored) {

        }
        return okHttpClient;
    }

    @Provides @Singleton Picasso providePicasso(Context context, OkHttpClient okHttpClient) {
        return new Picasso.Builder(context)
                .downloader(new OkHttpDownloader(okHttpClient))
                .build();
    }

    @Provides @Singleton ObjectMapper provideObjectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        return objectMapper;
    }

    @Provides Locale provideLocale() { return Locale.getDefault(); }

    @Provides @Singleton
    TheMovieDbApi provideImdbApi(OkHttpClient okHttpClient, ObjectMapper objectMapper, Locale locale) {
        return new RestAdapter.Builder()
                .setClient(new OkClient(okHttpClient))
                .setConverter(new JacksonConverter(objectMapper))
                .setEndpoint("http://api.themoviedb.org/3")
                .setRequestInterceptor(request -> {
                    request.addQueryParam("api_key", "35e896e1458276fd5592905cd455f375");
                    request.addQueryParam("language", locale.getISO3Language().substring(0, 2));
                })
                .setLogLevel(RestAdapter.LogLevel.BASIC)
                .setLog(s -> Timber.d(s))
                .build()
                .create(TheMovieDbApi.class);
    }

    @Provides @Singleton @Done PublishSubject<Movie> provideMoviePublishSubject() {
        return PublishSubject.create();
    }

    @Provides ConnectivityManager provideConnectivityManager(Context context) {
        return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    }

    @Provides @Singleton @Delete PublishSubject<Movie> provideDeleteSubject() {
        return PublishSubject.create();
    }
}




Java Source Code List

com.meoyawn.iwannawatch.AppModule.java
com.meoyawn.iwannawatch.App.java
com.meoyawn.iwannawatch.CrashReportingTree.java
com.meoyawn.iwannawatch.DynamicHeightImageView.java
com.meoyawn.iwannawatch.MainActivity.java
com.meoyawn.iwannawatch.MainFragment.java
com.meoyawn.iwannawatch.MovieView.java
com.meoyawn.iwannawatch.adapters.BaseMoviesAdapter.java
com.meoyawn.iwannawatch.adapters.CursorMoviesAdapter.java
com.meoyawn.iwannawatch.adapters.DynamicMoviesAdapter.java
com.meoyawn.iwannawatch.doers.DatabaseHelper.java
com.meoyawn.iwannawatch.doers.TheMovieDbApi.java
com.meoyawn.iwannawatch.models.Movie.java
com.meoyawn.iwannawatch.models.Search.java
com.meoyawn.iwannawatch.qualifiers.Delete.java
com.meoyawn.iwannawatch.qualifiers.Done.java