use of com.dante.data.model.BaseResult in project 91Pop by DanteAndroid.
the class Parse91PronVideo method parseSearchVideos.
public static BaseResult<List<UnLimit91PornItem>> parseSearchVideos(String html) {
int totalPage = 1;
List<UnLimit91PornItem> unLimit91PornItemList = new ArrayList<>();
Document doc = Jsoup.parse(html);
Element body = doc.getElementById("fullside");
if (body == null) {
String errorMsg = parseErrorInfo(html);
Logger.t(TAG).d(errorMsg);
BaseResult baseResult = new BaseResult();
baseResult.setCode(BaseResult.ERROR_CODE);
baseResult.setMessage(errorMsg);
return baseResult;
}
Elements listchannel = body.getElementsByClass("listchannel");
for (Element element : listchannel) {
UnLimit91PornItem unLimit91PornItem = new UnLimit91PornItem();
String contentUrl = element.select("a").first().attr("href");
// Logger.d(contentUrl);
contentUrl = contentUrl.substring(0, contentUrl.indexOf("&"));
// Logger.d(contentUrl);
String viewKey = contentUrl.substring(contentUrl.indexOf("=") + 1);
unLimit91PornItem.setViewKey(viewKey);
// Logger.d(viewKey);
String imgUrl = element.select("a").first().select("img").first().attr("src");
// Logger.d(imgUrl);
unLimit91PornItem.setImgUrl(imgUrl);
String title = element.select("span.title").text();
// Logger.d(title);
unLimit91PornItem.setTitle(title);
String duration = element.select("span.duration").text();
unLimit91PornItem.setDuration(duration);
String allInfo = element.text();
int start = allInfo.indexOf("添加时间");
String info = allInfo.substring(start);
unLimit91PornItem.setInfo(info.replace("还未被评分", ""));
// Logger.d(info);
unLimit91PornItemList.add(unLimit91PornItem);
}
// 总页数
Element pagingnav = body.getElementById("paging");
Elements a = pagingnav.select("a");
if (a.size() > 2) {
String ppp = a.get(a.size() - 2).text();
if (TextUtils.isDigitsOnly(ppp)) {
totalPage = Integer.parseInt(ppp);
// Logger.d("总页数:" + totalPage);
}
}
BaseResult<List<UnLimit91PornItem>> baseResult = new BaseResult<>();
baseResult.setTotalPage(totalPage);
baseResult.setData(unLimit91PornItemList);
return baseResult;
}
use of com.dante.data.model.BaseResult in project 91Pop by DanteAndroid.
the class ParseMeiZiTu method parsePicturesOfPost.
public static BaseResult<List<String>> parsePicturesOfPost(String html) {
BaseResult<List<String>> baseResult = new BaseResult<>();
Document doc = Jsoup.parse(html);
Element pageElement = doc.getElementsByClass("pagenavi").first();
Elements aElements = pageElement.select("a");
int totalPage = 1;
if (aElements != null && aElements.size() > 3) {
String pageStr = aElements.get(aElements.size() - 2).text();
if (!TextUtils.isEmpty(pageStr) && TextUtils.isDigitsOnly(pageStr)) {
totalPage = Integer.parseInt(pageStr);
}
}
List<String> imageUrlList = new ArrayList<>();
String imageUrl = doc.getElementsByClass("main-image").first().selectFirst("img").attr("src");
if (totalPage == 1) {
imageUrlList.add(imageUrl);
}
for (int i = 1; i < totalPage + 1; i++) {
String tmp;
if (i < 10) {
tmp = imageUrl.replace("01.", "0" + i + ".");
} else {
tmp = imageUrl.replace("01.", "" + i + ".");
}
imageUrlList.add(tmp);
}
baseResult.setData(imageUrlList);
return baseResult;
}
use of com.dante.data.model.BaseResult in project 91Pop by DanteAndroid.
the class SearchPresenter method searchVideos.
@Override
public void searchVideos(String searchId, String sort, final boolean pullToRefresh) {
String viewType = "basic";
String searchType = "search_videos";
if (pullToRefresh) {
page = 1;
}
dataManager.searchPorn91Videos(viewType, page, searchType, searchId, sort).map(new Function<BaseResult<List<UnLimit91PornItem>>, List<UnLimit91PornItem>>() {
@Override
public List<UnLimit91PornItem> apply(BaseResult<List<UnLimit91PornItem>> baseResult) throws Exception {
if (baseResult.getCode() == BaseResult.ERROR_CODE) {
throw new MessageException(baseResult.getMessage());
}
if (page == 1) {
totalPage = baseResult.getTotalPage();
}
return baseResult.getData();
}
}).retryWhen(new RetryWhenProcess(2)).compose(RxSchedulersHelper.<List<UnLimit91PornItem>>ioMainThread()).compose(provider.<List<UnLimit91PornItem>>bindUntilEvent(Lifecycle.Event.ON_DESTROY)).subscribe(new CallBackWrapper<List<UnLimit91PornItem>>() {
@Override
public void onBegin(Disposable d) {
ifViewAttached(new ViewAction<SearchView>() {
@Override
public void run(@NonNull SearchView view) {
if (page == 1 && pullToRefresh) {
view.showLoading(pullToRefresh);
}
}
});
}
@Override
public void onSuccess(final List<UnLimit91PornItem> unLimit91PornItems) {
ifViewAttached(new ViewAction<SearchView>() {
@Override
public void run(@NonNull SearchView view) {
if (page == 1) {
view.setData(unLimit91PornItems);
view.showContent();
} else {
view.loadMoreDataComplete();
view.setMoreData(unLimit91PornItems);
}
// 已经最后一页了
if (page == totalPage) {
view.noMoreData();
} else {
page++;
}
view.showContent();
}
});
}
@Override
public void onError(final String msg, int code) {
// 首次加载失败,显示重试页
ifViewAttached(new ViewAction<SearchView>() {
@Override
public void run(@NonNull SearchView view) {
if (page == 1) {
view.showError(msg);
} else {
view.loadMoreFailed();
}
}
});
}
});
}
use of com.dante.data.model.BaseResult in project 91Pop by DanteAndroid.
the class AuthorPresenter method authorVideos.
@Override
public void authorVideos(String uid, final boolean pullToRefresh) {
String type = "public";
if (pullToRefresh) {
page = 1;
cleanCache = true;
}
dataManager.loadPorn91authorVideos(uid, type, page, cleanCache).map(new Function<BaseResult<List<UnLimit91PornItem>>, List<UnLimit91PornItem>>() {
@Override
public List<UnLimit91PornItem> apply(BaseResult<List<UnLimit91PornItem>> baseResult) throws Exception {
if (baseResult.getCode() == BaseResult.ERROR_CODE) {
throw new MessageException(baseResult.getMessage());
}
if (page == 1) {
totalPage = baseResult.getTotalPage();
}
return baseResult.getData();
}
}).retryWhen(new RetryWhenProcess(RetryWhenProcess.PROCESS_TIME)).compose(RxSchedulersHelper.<List<UnLimit91PornItem>>ioMainThread()).compose(provider.<List<UnLimit91PornItem>>bindUntilEvent(Lifecycle.Event.ON_DESTROY)).subscribe(new CallBackWrapper<List<UnLimit91PornItem>>() {
@Override
public void onBegin(Disposable d) {
ifViewAttached(new ViewAction<AuthorView>() {
@Override
public void run(@NonNull AuthorView view) {
if (page == 1 && !pullToRefresh) {
view.showLoading(pullToRefresh);
}
}
});
}
@Override
public void onSuccess(final List<UnLimit91PornItem> unLimit91PornItems) {
ifViewAttached(new ViewAction<AuthorView>() {
@Override
public void run(@NonNull AuthorView view) {
if (page == 1) {
view.setData(unLimit91PornItems);
view.showContent();
} else {
view.loadMoreDataComplete();
view.setMoreData(unLimit91PornItems);
}
if (page >= totalPage) {
view.noMoreData();
} else {
page++;
}
view.showContent();
}
});
}
@Override
public void onError(final String msg, int code) {
ifViewAttached(new ViewAction<AuthorView>() {
@Override
public void run(@NonNull AuthorView view) {
if (page == 1) {
view.showError(msg);
} else {
view.loadMoreFailed();
}
}
});
}
});
}
use of com.dante.data.model.BaseResult in project 91Pop by DanteAndroid.
the class Parse91PronVideo method parseAuthorVideos.
/**
* 解析作者更多视频
*
* @param html html
* @return list
*/
public static BaseResult<List<UnLimit91PornItem>> parseAuthorVideos(String html) {
int totalPage = 1;
List<UnLimit91PornItem> unLimit91PornItemList = new ArrayList<>();
Document doc = Jsoup.parse(html);
Element body = doc.getElementById("leftside");
Elements videos = doc.select("div.myvideo");
for (Element element : videos) {
UnLimit91PornItem unLimit91PornItem = new UnLimit91PornItem();
String contentUrl = element.select("a").first().attr("href");
String viewKey = contentUrl.substring(contentUrl.indexOf("=") + 1, contentUrl.length());
unLimit91PornItem.setViewKey(viewKey);
// Logger.t(TAG).d(viewKey);
String title = element.select("strong").first().text();
unLimit91PornItem.setTitle(title);
// Logger.t(TAG).d(title);
String imgUrl = element.select("img").first().attr("src");
unLimit91PornItem.setImgUrl(imgUrl);
// Logger.t(TAG).d(imgUrl);
String allInfo = element.text();
// Logger.t(TAG).d(allInfo);
String duration = allInfo.substring(allInfo.indexOf("时长") + 3, allInfo.indexOf("查看") - 3);
unLimit91PornItem.setDuration(duration);
// Logger.t(TAG).d(duration);
String info = allInfo.substring(allInfo.indexOf("添加时间"), allInfo.length());
unLimit91PornItem.setInfo(info);
// Logger.t(TAG).d(info);
unLimit91PornItemList.add(unLimit91PornItem);
}
// 总页数
Element pagingnav = body.getElementById("paging");
Elements a = pagingnav.select("a");
if (a.size() >= 2) {
String ppp = a.get(a.size() - 2).text();
if (TextUtils.isDigitsOnly(ppp)) {
totalPage = Integer.parseInt(ppp);
// Logger.d("总页数:" + totalPage);
}
}
BaseResult<List<UnLimit91PornItem>> baseResult = new BaseResult<>();
baseResult.setTotalPage(totalPage);
baseResult.setData(unLimit91PornItemList);
return baseResult;
}
Aggregations