use of com.pokegoapi.main.RequestHandler in project PokeGOAPI-Java by Grover-c13.
the class PokemonGo method initialize.
private void initialize() throws RequestFailedException {
if (requestHandler != null) {
requestHandler.exit();
}
requestHandler = new RequestHandler(this, client);
requestHandler.sendServerRequests(ServerRequestEnvelope.create());
playerProfile.updateProfile();
ServerRequest downloadConfigRequest = new ServerRequest(RequestType.DOWNLOAD_REMOTE_CONFIG_VERSION, CommonRequests.getDownloadRemoteConfigVersionMessageRequest(this));
requestHandler.sendServerRequests(downloadConfigRequest, true);
getAssetDigest();
try {
ByteString configVersionData = downloadConfigRequest.getData();
if (itemTemplates.requiresUpdate(DownloadRemoteConfigVersionResponse.parseFrom(configVersionData))) {
itemTemplates.update(this);
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
playerProfile.getProfile();
try {
LevelUpRewardsMessage rewardsMessage = LevelUpRewardsMessage.newBuilder().setLevel(playerProfile.getStats().getLevel()).build();
ServerRequest request = new ServerRequest(RequestType.LEVEL_UP_REWARDS, rewardsMessage);
ServerRequestEnvelope envelope = ServerRequestEnvelope.createCommons(request, this);
requestHandler.sendServerRequests(envelope);
LevelUpRewardsResponse levelUpRewardsResponse = LevelUpRewardsResponse.parseFrom(request.getData());
if (levelUpRewardsResponse.getResult() == Result.SUCCESS) {
inventories.itemBag.addAwardedItems(levelUpRewardsResponse);
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
ByteString getStoreItems = GetStoreItemsRequest.newBuilder().build().toByteString();
ServerRequestEnvelope envelope = ServerRequestEnvelope.create();
envelope.addPlatform(new ServerPlatformRequest(PlatformRequestType.GET_STORE_ITEMS, getStoreItems));
requestHandler.sendServerRequests(envelope);
try {
FetchAllNewsMessageOuterClass.FetchAllNewsMessage msg = FetchAllNewsMessageOuterClass.FetchAllNewsMessage.newBuilder().build();
ServerRequest request = new ServerRequest(RequestType.FETCH_ALL_NEWS, msg);
envelope = ServerRequestEnvelope.create(request);
requestHandler.sendServerRequests(envelope);
FetchAllNewsResponseOuterClass.FetchAllNewsResponse response = FetchAllNewsResponseOuterClass.FetchAllNewsResponse.parseFrom(request.getData());
if (response.getResult() == FetchAllNewsResponseOuterClass.FetchAllNewsResponse.Result.SUCCESS) {
Log.i(TAG, "FetchAllNewsMessage Success: total News=" + response.getCurrentNews().getNewsArticlesCount());
this.news.setCurrentNews(response.getCurrentNews());
// mark all un-read new to read
this.news.markUnreadNews();
} else {
Log.d(TAG, "FetchAllNewsMessage Failed. Result=" + response.getResult());
}
} catch (Exception e) {
Log.d(TAG, "Exceptions FetchAllNew");
}
List<LoginListener> loginListeners = getListeners(LoginListener.class);
for (LoginListener listener : loginListeners) {
listener.onLogin(this);
}
loggingIn = false;
active = true;
ArrayList<TutorialState> tutorialStates = playerProfile.getTutorialState().getTutorialStates();
if (tutorialStates.isEmpty()) {
playerProfile.activateAccount();
}
if (!tutorialStates.contains(TutorialState.AVATAR_SELECTION)) {
playerProfile.setupAvatar();
}
heartbeat.start();
if (!tutorialStates.contains(TutorialState.POKEMON_CAPTURE)) {
playerProfile.encounterTutorialComplete();
}
int remainingCodenameClaims = playerProfile.getPlayerData().getRemainingCodenameClaims();
if (!tutorialStates.contains(TutorialState.NAME_SELECTION) && remainingCodenameClaims > 0) {
playerProfile.claimCodeName();
}
if (!tutorialStates.contains(TutorialState.FIRST_TIME_EXPERIENCE_COMPLETE)) {
playerProfile.firstTimeExperienceComplete();
}
}
Aggregations