use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Favorites method getFavorites.
public FavData getFavorites(int st, boolean all, Sorting sorting) throws Exception {
FavData data = new FavData();
Uri.Builder builder = new Uri.Builder();
builder.scheme("https").authority("4pda.ru");
builder.appendPath("forum");
builder.appendQueryParameter("act", "fav");
builder.appendQueryParameter("type", "all");
builder.appendQueryParameter("st", Integer.toString(st));
builder.appendQueryParameter(Sorting.Key.HEADER, sorting.getKey());
builder.appendQueryParameter(Sorting.Order.HEADER, sorting.getOrder());
NetworkResponse response = Api.getWebClient().get(builder.build().toString());
Matcher matcher = mainPattern.matcher(response.getBody());
FavItem item;
while (matcher.find()) {
item = new FavItem();
boolean isForum = matcher.group(19) != null;
item.setFavId(Integer.parseInt(matcher.group(1)));
item.setTrackType(matcher.group(2));
item.setPin(matcher.group(3).equals("1"));
if (matcher.group(4) != null) {
item.setInfoColor(matcher.group(4));
}
String tmp;
if (matcher.group(5) != null) {
tmp = matcher.group(5);
item.setNew(tmp.contains("+"));
item.setPoll(tmp.contains("^"));
item.setClosed(tmp.contains("Х"));
}
int iId = Integer.parseInt(matcher.group(6));
if (isForum) {
item.setForumId(iId);
} else {
item.setTopicId(iId);
}
item.setNew(matcher.group(7) != null);
item.setTopicTitle(ApiUtils.fromHtml(matcher.group(8)));
if (isForum) {
item.setDate(matcher.group(19));
item.setLastUserId(Integer.parseInt(matcher.group(20)));
item.setLastUserNick(ApiUtils.fromHtml(matcher.group(21)));
item.setForum(true);
} else {
if (matcher.group(9) != null) {
item.setStParam(Integer.parseInt(matcher.group(9)));
item.setPages((item.getStParam() / 20) + 1);
}
if (matcher.group(10) != null)
item.setDesc(ApiUtils.fromHtml(matcher.group(10)));
item.setForumId(Integer.parseInt(matcher.group(12)));
item.setForumTitle(ApiUtils.fromHtml(matcher.group(13)));
item.setAuthorId(Integer.parseInt(matcher.group(14)));
item.setAuthorUserNick(ApiUtils.fromHtml(matcher.group(15)));
item.setLastUserId(Integer.parseInt(matcher.group(16)));
item.setLastUserNick(ApiUtils.fromHtml(matcher.group(17)));
item.setDate(matcher.group(18));
tmp = matcher.group(22);
if (tmp != null) {
item.setCuratorId(Integer.parseInt(matcher.group(22)));
item.setCuratorNick(ApiUtils.fromHtml(matcher.group(23)));
}
item.setSubType(matcher.group(24).trim().toLowerCase());
}
data.addItem(item);
}
data.setPagination(Pagination.parseForum(response.getBody()));
data.setSorting(Sorting.parse(response.getBody()));
if (all) {
while (true) {
if (data.getPagination().getCurrent() >= data.getPagination().getAll()) {
break;
}
FavData favData = getFavorites(data.getPagination().getPage(data.getPagination().getCurrent()), false, sorting);
data.setPagination(favData.getPagination());
if (favData.getItems().isEmpty()) {
break;
}
for (FavItem favItem : favData.getItems()) {
data.addItem(favItem);
}
}
data.getPagination().setAll(1);
if (data.getSorting().getKey().equals(Sorting.Key.TITLE)) {
if (data.getSorting().getOrder().equals(Sorting.Order.DESC)) {
Collections.sort(data.getItems(), DESC_ORDER);
} else if (data.getSorting().getOrder().equals(Sorting.Order.ASC)) {
Collections.sort(data.getItems(), ASC_ORDER);
}
}
}
return data;
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Favorites method add.
public boolean add(int id, int action, String type) throws Exception {
String url = "https://4pda.ru/forum/index.php?act=fav&type=add&track_type=" + type;
if (action == ACTION_ADD_FORUM) {
url += "&f=";
} else if (action == ACTION_ADD) {
url += "&t=";
}
url += id;
NetworkResponse response = Api.getWebClient().request(new NetworkRequest.Builder().url(url).build());
return checkIsComplete(response.getBody());
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Favorites method editPinState.
public boolean editPinState(String type, int favId) throws Exception {
NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=fav").formHeader("selectedtids", Integer.toString(favId)).formHeader("tact", type);
NetworkResponse response = Api.getWebClient().request(builder.build());
return checkIsComplete(response.getBody());
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Profile method saveNote.
public boolean saveNote(String note) throws Exception {
NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=profile-xhr&action=save-note").formHeader("note", note);
NetworkResponse response = Api.getWebClient().request(builder.build());
return response.getBody().equals("1");
}
use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.
the class Profile method getProfile.
public ProfileModel getProfile(String url) throws Exception {
ProfileModel profile = new ProfileModel();
NetworkResponse response = Api.getWebClient().get(url);
final Matcher mainMatcher = mainPattern.matcher(response.getBody());
if (mainMatcher.find()) {
profile.setAvatar(safe(mainMatcher.group(1)));
profile.setNick(ApiUtils.fromHtml(safe(mainMatcher.group(2))));
profile.setStatus(safe(mainMatcher.group(3)));
profile.setGroup(safe(mainMatcher.group(4)));
Matcher data = info.matcher(mainMatcher.group(5));
while (data.find()) {
String field = data.group(1);
if (field.contains("Рег")) {
profile.addInfo(ProfileModel.InfoType.REG_DATE, safe(ApiUtils.fromHtml(data.group(2))));
} else if (field.contains("Последнее")) {
profile.addInfo(ProfileModel.InfoType.ONLINE_DATE, safe(ApiUtils.fromHtml(data.group(2).trim())));
}
}
String signString = safe(mainMatcher.group(6));
profile.setSign(signString.equals("Нет подписи") ? null : ApiUtils.coloredFromHtml(signString));
data = personal.matcher(mainMatcher.group(7));
while (data.find()) {
String field = data.group(2);
if (field == null || field.isEmpty()) {
profile.addInfo(ProfileModel.InfoType.GENDER, safe(data.group(1)));
continue;
}
field = data.group(1);
if (field.contains("Дата")) {
profile.addInfo(ProfileModel.InfoType.BIRTHDAY, safe(data.group(2)));
} else if (field.contains("Время")) {
profile.addInfo(ProfileModel.InfoType.USER_TIME, safe(data.group(2)));
} else if (field.contains("Город")) {
profile.addInfo(ProfileModel.InfoType.CITY, safe(data.group(2)));
}
}
data = contacts.matcher(mainMatcher.group(8));
while (data.find()) {
ProfileModel.Contact contact = new ProfileModel.Contact();
contact.setUrl(safe(data.group(1)));
String title = safe(data.group(2));
contact.setTitle(title);
ProfileModel.ContactType type;
switch(title) {
case "QMS":
type = ProfileModel.ContactType.QMS;
break;
case "Вебсайт":
type = ProfileModel.ContactType.WEBSITE;
break;
case "ICQ":
type = ProfileModel.ContactType.ICQ;
break;
case "Twitter":
type = ProfileModel.ContactType.TWITTER;
break;
case "Вконтакте":
type = ProfileModel.ContactType.VKONTAKTE;
break;
case "Google+":
type = ProfileModel.ContactType.GOOGLE_PLUS;
break;
case "Facebook":
type = ProfileModel.ContactType.FACEBOOK;
break;
case "Instagram":
type = ProfileModel.ContactType.INSTAGRAM;
break;
case "Jabber":
type = ProfileModel.ContactType.JABBER;
break;
case "Telegram":
type = ProfileModel.ContactType.TELEGRAM;
break;
case "Mail.ru":
type = ProfileModel.ContactType.MAIL_RU;
break;
case "Windows Live":
type = ProfileModel.ContactType.WINDOWS_LIVE;
break;
default:
type = ProfileModel.ContactType.WEBSITE;
}
contact.setType(type);
profile.addContact(contact);
}
data = devices.matcher(mainMatcher.group(9));
while (data.find()) {
ProfileModel.Device device = new ProfileModel.Device();
device.setUrl(safe(data.group(1)));
device.setName(safe(data.group(2)));
device.setAccessory(safe(data.group(3)));
profile.addDevice(device);
}
data = siteStats.matcher(mainMatcher.group(10));
while (data.find()) {
ProfileModel.Stat stat = new ProfileModel.Stat();
stat.setUrl(data.group(2));
stat.setValue(data.group(3));
String field = data.group(1);
ProfileModel.StatType type = null;
if (field.contains("Карма")) {
type = ProfileModel.StatType.SITE_KARMA;
} else if (field.contains("Постов")) {
type = ProfileModel.StatType.SITE_POSTS;
} else if (field.contains("Комментов")) {
type = ProfileModel.StatType.SITE_COMMENTS;
}
stat.setType(type);
profile.addStat(stat);
}
data = forumStats.matcher(mainMatcher.group(11));
while (data.find()) {
ProfileModel.Stat stat = new ProfileModel.Stat();
stat.setUrl(data.group(3));
String value = data.group(4);
if (value == null) {
value = data.group(2);
}
stat.setValue(value);
String field = data.group(1);
ProfileModel.StatType type = null;
if (field.contains("Репу")) {
type = ProfileModel.StatType.FORUM_REPUTATION;
} else if (field.contains("Тем")) {
type = ProfileModel.StatType.FORUM_TOPICS;
} else if (field.contains("Постов")) {
type = ProfileModel.StatType.FORUM_POSTS;
}
stat.setType(type);
profile.addStat(stat);
}
data = note.matcher(response.getBody());
if (data.find()) {
profile.setNote(ApiUtils.fromHtml(data.group(1).replaceAll("\n", "<br></br>")));
}
data = about.matcher(response.getBody());
if (data.find()) {
profile.setAbout(ApiUtils.coloredFromHtml(safe(data.group(1))));
}
data = warnings.matcher(response.getBody());
while (data.find()) {
ProfileModel.Warning warning = new ProfileModel.Warning();
switch(data.group(1)) {
case "pos":
warning.setType(ProfileModel.WarningType.POSITIVE);
break;
case "neg":
warning.setType(ProfileModel.WarningType.NEGATIVE);
break;
}
warning.setDate(data.group(2));
warning.setTitle(ApiUtils.fromHtml(data.group(3)));
warning.setContent(ApiUtils.spannedFromHtml(data.group(4)));
profile.addWarning(warning);
}
}
return profile;
}
Aggregations