Search in sources :

Example 1 with ProxyModel

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);
}
Also used : ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) OnLoadViewListener(com.helper.loadviewhelper.help.OnLoadViewListener) ProxyAdapter(com.dante.adapter.ProxyAdapter) LoadViewHelper(com.helper.loadviewhelper.load.LoadViewHelper) ProxyModel(com.dante.data.model.ProxyModel)

Example 2 with ProxyModel

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;
}
Also used : BaseResult(com.dante.data.model.BaseResult) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) ProxyModel(com.dante.data.model.ProxyModel)

Aggregations

ProxyModel (com.dante.data.model.ProxyModel)2 ArrayList (java.util.ArrayList)2 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 BindView (butterknife.BindView)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1 ProxyAdapter (com.dante.adapter.ProxyAdapter)1 BaseResult (com.dante.data.model.BaseResult)1 OnLoadViewListener (com.helper.loadviewhelper.help.OnLoadViewListener)1 LoadViewHelper (com.helper.loadviewhelper.load.LoadViewHelper)1 List (java.util.List)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1