Skip to content

Instantly share code, notes, and snippets.

@edBaev
Created December 15, 2014 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edBaev/08664ee583110752a8b6 to your computer and use it in GitHub Desktop.
Save edBaev/08664ee583110752a8b6 to your computer and use it in GitHub Desktop.
package com.blacksquared.changers.api.task.statistic;
import com.blacksquared.changers.App;
import com.blacksquared.changers.Constants;
import com.blacksquared.changers.api.ApiSettings;
import com.blacksquared.changers.api.request.StatisticsApi;
import com.blacksquared.changers.api.task.ApiTask;
import com.blacksquared.changers.event.rank.RankCityEvent;
import com.blacksquared.changers.model.dto.statistic.StatisticRankCitiesDTO;
import java.util.ArrayList;
import de.greenrobot.event.EventBus;
import retrofit.client.Response;
/**
* Created by Ed
*/
public class GetCityRankTask extends ApiTask<StatisticsApi, StatisticRankCitiesDTO> {
private String username;
private boolean isRefresh;
private int limit;
private String offset;
public GetCityRankTask(StatisticsApi api, String username, boolean isRefresh, String offset) {
super(api, null);
this.username = username;
this.isRefresh = isRefresh;
this.limit = Constants.PAGE_LIMIT;
this.offset = offset;
}
@Override
public void run() {
api.getRankCities(ApiSettings.STATISTIC.METHOD_STATISTIC_RANK_CITY, limit, offset, username, ApiSettings.API_KEY_VALUE,
App.dataManager.getToken(), this);
}
@Override
public void onSuccess(StatisticRankCitiesDTO statisticRankCitiesDTO, Response response) {
if (statisticRankCitiesDTO != null) {
App.dataManager.setCities(new ArrayList<>(statisticRankCitiesDTO.getCityMap().values()), true);
}
if (isRefresh) {
EventBus.getDefault().postSticky(new RankCityEvent(statisticRankCitiesDTO != null));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment