Skip to content

Instantly share code, notes, and snippets.

View mohsenoid's full-sized avatar
:octocat:
What can go wrong?!

Mohsen Mirhoseini mohsenoid

:octocat:
What can go wrong?!
View GitHub Profile
apply plugin: 'java'
/*...*/
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile rootProject.ext.libraries.rxjava
testCompile rootProject.ext.testLibraries.junit
testCompile rootProject.ext.testLibraries.mockito
package com.mirhoseini.marvel.character.cache;
import dagger.Module;
import dagger.Provides;
@Module
class CacheModule {
private CacheView view;
@Singleton
@Provides
public HttpLoggingInterceptor provideHttpLoggingInterceptor() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
return logging;
}
package com.mirhoseini.marvel;
import android.app.Application;
public abstract class MarvelApplication extends Application {
private static ApplicationComponent component;
public static ApplicationComponent getComponent() {
return component;
package com.mirhoseini.marvel;
import timber.log.Timber;
public class MarvelApplicationImpl extends MarvelApplication {
@Override
public void initApplication() {
// initialize Timber in debug version to log
package com.mirhoseini.marvel;
/*...*/
@Singleton
@Component(modules = {
AndroidModule.class,
ApplicationModule.class,
ApiModule.class,
DatabaseModule.class,
ClientModule.class
package com.mirhoseini.marvel.character.search;
import dagger.Subcomponent;
@Search
@Subcomponent(modules = {
AppSearchModule.class
})
public interface SearchSubComponent {
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mirhoseini.marvel">
<!-- *** -->
<application
android:name=".MarvelApplicationImpl"
android:allowBackup="true"
package com.mirhoseini.marvel.domain.client;
import com.mirhoseini.marvel.domain.model.CharactersResponse;
import retrofit2.http.GET;
import retrofit2.http.Query;
import rx.Observable;
public interface MarvelApi {
@Provides
@Singleton
public Cache provideCache(@Named("cacheDir") File cacheDir, @Named("cacheSize") long cacheSize) {
Cache cache = null;
try {
cache = new Cache(new File(cacheDir.getPath(), HTTP_CACHE_PATH), cacheSize);
} catch (Exception e) {
e.printStackTrace();
}