Skip to content

Commit

Permalink
Encapsulate Dribbble search in a repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed Jul 17, 2018
1 parent c348720 commit d355ed8
Show file tree
Hide file tree
Showing 35 changed files with 811 additions and 1,502 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/io/plaidapp/ui/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
import io.plaidapp.core.data.DataManager;
import io.plaidapp.core.data.PlaidItem;
import io.plaidapp.core.data.Source;
import io.plaidapp.core.data.api.dribbble.model.Shot;
import io.plaidapp.core.dribbble.data.api.model.Shot;
import io.plaidapp.core.data.pocket.PocketUtils;
import io.plaidapp.core.data.prefs.SourceManager;
import io.plaidapp.core.designernews.DesignerNewsPrefs;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/io/plaidapp/core/data/BaseDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.util.concurrent.atomic.AtomicInteger;

import io.plaidapp.core.BuildConfig;
import io.plaidapp.core.data.api.dribbble.DribbbleSearchConverter;
import io.plaidapp.core.data.api.dribbble.DribbbleSearchService;
import io.plaidapp.core.dribbble.data.search.DribbbleSearchConverter;
import io.plaidapp.core.dribbble.data.search.DribbbleSearchService;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
Expand Down
40 changes: 15 additions & 25 deletions core/src/main/java/io/plaidapp/core/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,21 @@
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.plaidapp.core.data.api.dribbble.DribbbleSearchService;
import io.plaidapp.core.data.api.dribbble.model.Shot;
import io.plaidapp.core.data.api.dribbble.model.User;
import io.plaidapp.core.data.prefs.SourceManager;
import io.plaidapp.core.designernews.Injection;
import io.plaidapp.core.designernews.data.api.DesignerNewsRepository;
import io.plaidapp.core.dribbble.DribbbleInjection;
import io.plaidapp.core.dribbble.data.DribbbleRepository;
import io.plaidapp.core.dribbble.data.api.model.Shot;
import io.plaidapp.core.producthunt.data.api.ProductHuntInjection;
import io.plaidapp.core.producthunt.data.api.ProductHuntRepository;
import io.plaidapp.core.ui.FilterAdapter;
import kotlin.Unit;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Responsible for loading data from the various sources. Instantiating classes are responsible for
Expand All @@ -46,6 +43,7 @@
public abstract class DataManager extends BaseDataManager<List<? extends PlaidItem>>
implements LoadSourceCallback {

private final DribbbleRepository dribbbleRepository;
private final DesignerNewsRepository designerNewsRepository;
private final ProductHuntRepository productHuntRepository;
private final FilterAdapter filterAdapter;
Expand All @@ -54,6 +52,7 @@ public abstract class DataManager extends BaseDataManager<List<? extends PlaidIt

public DataManager(Context context, FilterAdapter filterAdapter) {
super();
dribbbleRepository = DribbbleInjection.provideDribbbleRepository();
designerNewsRepository = Injection.provideDesignerNewsRepository(context);
productHuntRepository = ProductHuntInjection.provideProductHuntRepository();

Expand Down Expand Up @@ -179,24 +178,15 @@ private void loadDesignerNewsSearch(final Source.DesignerNewsSearchSource source
}

private void loadDribbbleSearch(final Source.DribbbleSearchSource source, final int page) {
final Call<List<Shot>> searchCall = getDribbbleSearchApi().search(source.query, page,
DribbbleSearchService.PER_PAGE_DEFAULT, DribbbleSearchService.SORT_RECENT);
searchCall.enqueue(new Callback<List<Shot>>() {
@Override
public void onResponse(Call<List<Shot>> call, Response<List<Shot>> response) {
if (response.isSuccessful()) {
sourceLoaded(response.body(), page, source.key);
} else {
loadFailed(source.key);
}
}

@Override
public void onFailure(Call<List<Shot>> call, Throwable t) {
dribbbleRepository.search(source.query, page, result -> {
if (result instanceof Result.Success) {
Result.Success<List<Shot>> success = (Result.Success<List<Shot>>) result;
sourceLoaded(success.getData(), page, source.key);
} else {
loadFailed(source.key);
}
return Unit.INSTANCE;
});
inflight.put(source.key, searchCall);
}

private void loadProductHunt(final int page) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.util.ArrayList;
import java.util.List;

import io.plaidapp.core.data.api.dribbble.DribbbleSearchService;
import io.plaidapp.core.data.api.dribbble.model.Shot;
import io.plaidapp.core.dribbble.data.search.DribbbleSearchService;
import io.plaidapp.core.dribbble.data.api.model.Shot;
import io.plaidapp.core.designernews.Injection;
import io.plaidapp.core.designernews.data.api.DesignerNewsRepository;
import retrofit2.Call;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d355ed8

Please sign in to comment.