Created
December 15, 2014 13:39
-
-
Save edBaev/08664ee583110752a8b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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