2020-11-01 06:02:54 +00:00
|
|
|
package awais.instagrabber.webservices;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
2020-11-01 11:34:42 +00:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
2020-11-01 06:02:54 +00:00
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
import awais.instagrabber.repositories.DiscoverRepository;
|
2021-01-07 12:36:33 +00:00
|
|
|
import awais.instagrabber.repositories.responses.discover.TopicalExploreFeedResponse;
|
2020-11-01 06:02:54 +00:00
|
|
|
import awais.instagrabber.utils.TextUtils;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
|
|
|
|
2021-06-08 23:46:34 +00:00
|
|
|
public class DiscoverService {
|
2020-11-01 06:02:54 +00:00
|
|
|
|
|
|
|
private static final String TAG = "DiscoverService";
|
|
|
|
|
|
|
|
private final DiscoverRepository repository;
|
|
|
|
|
|
|
|
private static DiscoverService instance;
|
|
|
|
|
|
|
|
private DiscoverService() {
|
2021-05-28 16:30:01 +00:00
|
|
|
repository = RetrofitFactory.INSTANCE
|
2021-03-22 11:59:08 +00:00
|
|
|
.getRetrofit()
|
|
|
|
.create(DiscoverRepository.class);
|
2020-11-01 06:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static DiscoverService getInstance() {
|
|
|
|
if (instance == null) {
|
|
|
|
instance = new DiscoverService();
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2021-07-25 20:34:05 +00:00
|
|
|
public void topicalExplore(final String maxId,
|
2021-01-07 12:36:33 +00:00
|
|
|
final ServiceCallback<TopicalExploreFeedResponse> callback) {
|
2020-11-01 11:34:42 +00:00
|
|
|
final ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder()
|
2020-11-01 06:02:54 +00:00
|
|
|
.put("module", "explore_popular");
|
2021-07-25 20:34:05 +00:00
|
|
|
if (!TextUtils.isEmpty(maxId)) {
|
|
|
|
builder.put("max_id", maxId);
|
2020-11-01 06:02:54 +00:00
|
|
|
}
|
2021-01-07 12:36:33 +00:00
|
|
|
final Call<TopicalExploreFeedResponse> req = repository.topicalExplore(builder.build());
|
|
|
|
req.enqueue(new Callback<TopicalExploreFeedResponse>() {
|
2020-11-01 06:02:54 +00:00
|
|
|
@Override
|
2021-01-07 12:36:33 +00:00
|
|
|
public void onResponse(@NonNull final Call<TopicalExploreFeedResponse> call,
|
|
|
|
@NonNull final Response<TopicalExploreFeedResponse> response) {
|
|
|
|
if (callback == null) return;
|
|
|
|
final TopicalExploreFeedResponse feedResponse = response.body();
|
|
|
|
if (feedResponse == null) {
|
2020-11-01 06:02:54 +00:00
|
|
|
callback.onSuccess(null);
|
|
|
|
return;
|
|
|
|
}
|
2021-01-07 12:36:33 +00:00
|
|
|
callback.onSuccess(feedResponse);
|
2020-11-01 06:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-07 12:36:33 +00:00
|
|
|
public void onFailure(@NonNull final Call<TopicalExploreFeedResponse> call, @NonNull final Throwable t) {
|
2020-11-01 06:02:54 +00:00
|
|
|
callback.onFailure(t);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|