use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Qms method getChat.
public QmsChatModel getChat(final int userId, final int themeId) throws Exception {
NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=qms&mid=" + userId + "&t=" + themeId).formHeader("xhr", "body");
NetworkResponse response = Api.getWebClient().request(builder.build());
return parseChat(response.getBody());
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Qms method findUser.
public List<ForumUser> findUser(final String nick) throws Exception {
String encodedNick = URLEncoder.encode(nick, "UTF-8");
NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=qms-xhr&action=autocomplete-username&q=" + encodedNick);
List<ForumUser> list = new ArrayList<>();
Matcher m = findUserPattern.matcher(response.getBody());
while (m.find()) {
ForumUser user = new ForumUser();
user.setId(Integer.parseInt(m.group(1)));
user.setNick(ApiUtils.fromHtml(m.group(2)));
String avatar = m.group(3);
if (avatar.substring(0, 2).equals("//")) {
avatar = "https:".concat(avatar);
} else if (avatar.substring(0, 1).equals("/")) {
avatar = "https://4pda.ru".concat(avatar);
}
user.setAvatar(avatar);
list.add(user);
}
return list;
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Qms method sendNewTheme.
public QmsChatModel sendNewTheme(String nick, String title, String mess) throws Exception {
NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=qms&action=create-thread&xhr=body&do=1").formHeader("username", nick).formHeader("title", title).formHeader("message", mess);
NetworkResponse response = Api.getWebClient().request(builder.build());
return parseChat(response.getBody());
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class IntentHandler method redirectDownload.
private static void redirectDownload(String fileName, String url) {
Toast.makeText(App.getContext(), String.format(App.get().getString(R.string.perform_request_link), fileName), Toast.LENGTH_SHORT).show();
Observable.fromCallable(() -> Client.get().request(new NetworkRequest.Builder().url(url).withoutBody().build())).onErrorReturn(throwable -> new NetworkResponse(null)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(response -> {
if (response.getUrl() == null) {
Toast.makeText(App.getContext(), R.string.error_occurred, Toast.LENGTH_SHORT).show();
return;
}
try {
Activity activity = App.getActivity();
if (!Preferences.Main.isSystemDownloader(null) || activity == null) {
externalDownloader(response.getRedirect());
} else {
Runnable checkAction = () -> {
Toast.makeText(App.getContext(), String.format(App.get().getString(R.string.perform_request_link), fileName), Toast.LENGTH_SHORT).show();
try {
systemDownloader(fileName, response.getRedirect());
} catch (Exception exception) {
Toast.makeText(App.getContext(), R.string.perform_loading_error, Toast.LENGTH_SHORT).show();
externalDownloader(response.getRedirect());
}
};
App.get().checkStoragePermission(checkAction, activity);
}
} catch (Exception ex) {
ACRA.getErrorReporter().handleException(ex);
}
});
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class UpdateCheckerActivity method refreshInfo.
private void refreshInfo() {
setRefreshing(true);
updateContent.removeAllViews();
Observable.fromCallable(() -> {
NetworkResponse response = Client.get(getApplicationContext()).get(JSON_LINK);
String body;
body = response.getBody();
return body;
}).onErrorReturn(throwable -> "").subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::checkSource);
}
Aggregations