use of com.dante.data.model.ProxyModel in project 91Pop by DanteAndroid.
the class ProxySettingActivity method init.
private void init() {
testAlertDialog = DialogUtils.initLodingDialog(this, "测试中,请稍候...");
String proxyHost = dataManager.getProxyIpAddress();
int port = dataManager.getProxyPort();
etDialogProxySettingIpAddress.setIpAddressStr(proxyHost);
etDialogProxySettingPort.setText(port == 0 ? "" : String.valueOf(port));
List<ProxyModel> data = new ArrayList<>();
proxyAdapter = new ProxyAdapter(R.layout.item_proxy, data);
recyclerViewProxySetting.setLayoutManager(new LinearLayoutManager(this));
recyclerViewProxySetting.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
View view = getLayoutInflater().inflate(R.layout.item_proxy, recyclerViewProxySetting, false);
proxyAdapter.setHeaderView(view);
proxyAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
@Override
public void onLoadMoreRequested() {
presenter.parseXiCiDaiLi(false);
}
}, recyclerViewProxySetting);
proxyAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
ProxyModel proxyModel = (ProxyModel) adapter.getItem(position);
if (proxyModel == null) {
showMessage("数据出错了", TastyToast.WARNING);
return;
}
proxyAdapter.setClickPosition(position);
if (proxyModel.getType() != ProxyModel.TYPE_SOCKS) {
etDialogProxySettingIpAddress.setIpAddressStr(proxyModel.getProxyIp());
etDialogProxySettingPort.setText(proxyModel.getProxyPort());
} else {
showMessage("暂不支持socket代理", TastyToast.INFO);
}
}
});
recyclerViewProxySetting.setAdapter(proxyAdapter);
helper = new LoadViewHelper(recyclerViewProxySetting);
helper.setListener(new OnLoadViewListener() {
@Override
public void onRetryClick() {
presenter.parseXiCiDaiLi(false);
}
});
presenter.parseXiCiDaiLi(false);
}
use of com.dante.data.model.ProxyModel in project 91Pop by DanteAndroid.
the class ParseProxy method parseXiCiDaiLi.
public static BaseResult<List<ProxyModel>> parseXiCiDaiLi(String html, int page) {
BaseResult<List<ProxyModel>> baseResult = new BaseResult<>();
baseResult.setTotalPage(1);
Document doc = Jsoup.parse(html);
Element ipList = doc.getElementById("ip_list");
Elements trs = ipList.select("tr");
int trSize = trs.size();
List<ProxyModel> proxyModelList = new ArrayList<>();
for (int i = 0; i < trSize; i++) {
// 第一是标题,跳过
if (i == 0) {
continue;
}
// tr里的td
Elements tds = trs.get(i).select("td");
ProxyModel proxyModel = new ProxyModel();
for (int j = 0; j < tds.size(); j++) {
Element td = tds.get(j);
switch(j) {
case 0:
// 国家
break;
case 1:
// ip
String ip = td.text();
proxyModel.setProxyIp(ip);
break;
case 2:
// 端口
String port = td.text();
proxyModel.setProxyPort(port);
break;
case 3:
// 城市
break;
case 4:
// 匿名度
String anonymous = td.text();
proxyModel.setAnonymous(anonymous);
break;
case 5:
// 类型 http https socket
String type = td.text();
if ("http".equalsIgnoreCase(type)) {
proxyModel.setType(ProxyModel.TYPE_HTTP);
} else if ("https".equalsIgnoreCase(type)) {
proxyModel.setType(ProxyModel.TYPE_HTTPS);
} else {
proxyModel.setType(ProxyModel.TYPE_SOCKS);
}
break;
case 6:
// 速度
break;
case 7:
// 连接时间
String responseTime = td.select("div").first().attr("title");
proxyModel.setResponseTime(responseTime);
break;
case 8:
// 存活时间
break;
case 9:
// 验证时间
break;
default:
}
}
proxyModelList.add(proxyModel);
}
baseResult.setData(proxyModelList);
if (page == 1) {
Elements elements = doc.getElementsByClass("pagination").first().select("a");
if (elements.size() > 3) {
String totalPageStr = elements.get(elements.size() - 2).text();
Logger.t(TAG).d(totalPageStr);
if (TextUtils.isDigitsOnly(totalPageStr)) {
baseResult.setTotalPage(Integer.parseInt(totalPageStr));
}
}
}
return baseResult;
}
Aggregations