use of forpdateam.ru.forpda.api.news.models.DetailsPage in project ForPDA by RadiationX.
the class NewsApi method parseArticle.
private DetailsPage parseArticle(String response) throws Exception {
long time = System.currentTimeMillis();
Matcher matcher = detailsPattern.matcher(response);
DetailsPage page = new DetailsPage();
if (matcher.find()) {
Log.e("TIME", "Article found: " + (System.currentTimeMillis() - time));
page.setId(Integer.parseInt(matcher.group(1)));
page.setImgUrl(matcher.group(3));
page.setTitle(ApiUtils.fromHtml(matcher.group(4)));
page.setDate(matcher.group(5));
page.setAuthorId(Integer.parseInt(matcher.group(6)));
page.setAuthor(ApiUtils.fromHtml(matcher.group(7)));
page.setCommentsCount(Integer.parseInt(matcher.group(8)));
parseTags(page.getTags(), matcher.group(9));
page.setHtml(matcher.group(10));
parseMaterials(page.getMaterials(), matcher.group(11));
page.setNavId(matcher.group(12));
parseKarma(page.getKarmaMap(), response);
String comments = matcher.group(14);
comments = excludeFormCommentPattern.matcher(comments).replaceFirst("");
page.setCommentsSource(comments);
/*Comment commentTree = parseComments(page.getKarmaMap(), page.getCommentsSource());
page.setCommentTree(commentTree);*/
} else {
throw new Exception("Not found article by pattern");
}
Log.e("TIME", "Article: " + (System.currentTimeMillis() - time));
return page;
}
use of forpdateam.ru.forpda.api.news.models.DetailsPage in project ForPDA by RadiationX.
the class NewsApi method replyComment.
public Comment replyComment(DetailsPage article, int commentId, String comment) throws Exception {
try {
comment = URLEncoder.encode(comment, "Windows-1251");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/wp-comments-post.php").formHeader("comment_post_ID", Integer.toString(article.getId())).formHeader("comment_reply_ID", Integer.toString(commentId)).formHeader("comment_reply_dp", commentId == 0 ? "0" : "1").formHeader("comment", comment, true);
NetworkResponse response = Api.getWebClient().request(builder.build());
DetailsPage newArticle = parseArticle(response.getBody());
return updateComments(article, newArticle);
}
use of forpdateam.ru.forpda.api.news.models.DetailsPage in project ForPDA by RadiationX.
the class ArticleContentFragment method sendPoll.
@JavascriptInterface
public void sendPoll(String id, String answer, String from) {
if (getContext() == null)
return;
webView.runInUiThread(() -> {
int pollId = Integer.parseInt(id);
String[] answers = answer.split(",");
int[] answersId = new int[answers.length];
for (int i = 0; i < answers.length; i++) {
answersId[i] = Integer.parseInt(answers[i]);
}
NewsDetailsFragment fragment = ((NewsDetailsFragment) getParentFragment());
fragment.subscribe(RxApi.NewsList().sendPoll(from, pollId, answersId), page -> {
article.setHtml(page.getHtml());
loadHtml();
}, new DetailsPage());
});
}
use of forpdateam.ru.forpda.api.news.models.DetailsPage in project ForPDA by RadiationX.
the class NewsDetailsFragment method loadData.
@Override
public boolean loadData() {
if (!super.loadData()) {
return false;
}
// webViewContainer.setRefreshing(true);
progressBar.setVisibility(View.VISIBLE);
loadCoverImage();
Observable<DetailsPage> observable = null;
if (newsUrl != null) {
observable = RxApi.NewsList().getDetails(newsUrl);
} else {
observable = RxApi.NewsList().getDetails(newsId);
}
subscribe(observable, this::onLoadArticle, new DetailsPage(), v -> loadData());
return true;
}
Aggregations