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
package com.mirhoseini.marvel.util;
import javax.inject.Inject;
import rx.Scheduler;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class AppSchedulerProvider implements SchedulerProvider {
@Inject
@Override
public void doSearch(boolean isConnected, String query, long timestamp) {
if (null != view) {
view.showProgress();
}
subscription = interactor.loadCharacter(query, Constants.PRIVATE_KEY, Constants.PUBLIC_KEY, timestamp)
// check if result code is OK
.map(charactersResponse -> {
if (Constants.CODE_OK == charactersResponse.getCode())
package com.mirhoseini.marvel.domain;
/*...*/
@Module
public class ApiModule {
@Provides
@Singleton
public MarvelApi provideMarvelApi(Retrofit retrofit) {
package com.mirhoseini.stylight.domain;
/*...*/
@Module
public class ClientModule {
/*...*/
@Singleton
@Provides
@Singleton
@Provides
@Named("retryInterceptor")
public Interceptor provideRetryInterceptor(@Named("retryCount") int retryCount) {
return chain -> {
Request request = chain.request();
Response response = null;
IOException exception = null;
int tryCount = 0;
@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();
}
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 {
<?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.character.search;
import dagger.Subcomponent;
@Search
@Subcomponent(modules = {
AppSearchModule.class
})
public interface SearchSubComponent {
package com.mirhoseini.marvel;
/*...*/
@Singleton
@Component(modules = {
AndroidModule.class,
ApplicationModule.class,
ApiModule.class,
DatabaseModule.class,
ClientModule.class