QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

以下内容为反编译后的 RecommendNovelPresenter.java 源代码,内容仅作参考


package com.tencent.mtt.browser.download.business.ui.card.ad.novel;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import com.google.gson.Gson;
import com.tencent.common.http.HttpHeader;
import com.tencent.common.task.Continuation;
import com.tencent.common.task.QBTask;
import com.tencent.common.utils.FileUtils;
import com.tencent.common.utils.QADID;
import com.tencent.common.utils.UrlUtils;
import com.tencent.mtt.base.skin.MttResources;
import com.tencent.mtt.base.wup.GUIDManager;
import com.tencent.mtt.browser.download.business.ui.card.ad.IAdDataListener;
import com.tencent.mtt.browser.download.business.ui.card.ad.IRecommendAdPresenter;
import com.tencent.mtt.browser.download.engine.DownloadTask;
import com.tencent.mtt.browser.download.engine.utils.DLogger;
import com.tencent.mtt.network.QBUrl;
import com.tencent.mtt.qbinfo.QUAUtils;
import com.tencent.mtt.qbinfo.UserAgentUtils;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.util.Random;
import java.util.concurrent.Callable;

public class RecommendNovelPresenter implements IRecommendAdPresenter {

    private static final int f37205a = MttResources.s(186);

    private final HotNovelCardLayout f37206b;

    public RecommendNovelPresenter(Context context) {
        this.f37206b = new HotNovelCardLayout(context);
    }

    private String a(DownloadTask downloadTask) {
        String addParamsToUrl = UrlUtils.addParamsToUrl("https://entityrcmd.cache.sogou.com/?sourceTag=novel_downloads&retEncoding=utf8", "randNum=" + new Random(System.currentTimeMillis()).nextInt(5));
        String m = downloadTask.m();
        String addParamsToUrl2 = UrlUtils.addParamsToUrl(addParamsToUrl, "queryString=" + a(m));
        DLogger.a("DownloadPage.RecommendAd", "NovelPresenter fileName: " + m);
        return addParamsToUrl2;
    }

    private String a(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        int lastIndexOf = str.lastIndexOf(".txt");
        return (!str.endsWith(".txt") || lastIndexOf == -1) ? "" : str.substring(0, lastIndexOf);
    }

    public Void a(IAdDataListener iAdDataListener, QBTask qBTask) throws Exception {
        if (qBTask.f() != null || qBTask.e() == null) {
            DLogger.a("DownloadPage.RecommendAd", "NovelPresenter requestData task error");
            return null;
        }
        this.f37206b.a(((HotNovelData) qBTask.e()).a());
        if (iAdDataListener != null) {
            iAdDataListener.a();
        }
        return null;
    }

    private QBTask<HotNovelData> b(final String str) {
        return QBTask.a(new Callable() {
            @Override
            public final Object call() {
                HotNovelData d2;
                d2 = RecommendNovelPresenter.this.d(str);
                return d2;
            }
        }, 1);
    }

    public HotNovelData d(String str) {
        HttpURLConnection httpURLConnection;
        BufferedReader bufferedReader;
        IOException e;
        InputStream inputStream;
        int responseCode;
        InputStream inputStream2 = null;
        inputStream2 = null;
        HttpURLConnection httpURLConnection2 = null;
        try {
            httpURLConnection = (HttpURLConnection) new QBUrl(str).e();
            try {
                httpURLConnection.setRequestProperty("Cache-Control", "no-cache");
                httpURLConnection.setRequestProperty(HttpHeader.REQ.QGUID, GUIDManager.a().f());
                httpURLConnection.setRequestProperty(HttpHeader.REQ.QUA2, QUAUtils.a());
                httpURLConnection.setRequestProperty("User-agent", UserAgentUtils.a(0));
                httpURLConnection.addRequestProperty("QAID", QADID.a());
                httpURLConnection.setDefaultUseCaches(false);
                httpURLConnection.setUseCaches(false);
                httpURLConnection.setReadTimeout(5000);
                httpURLConnection.setConnectTimeout(5000);
                httpURLConnection.connect();
                responseCode = httpURLConnection.getResponseCode();
                DLogger.a("DownloadPage.RecommendAd", "NovelPresenter getNovelJsonData code: " + responseCode);
            } catch (IOException e2) {
                e = e2;
                bufferedReader = null;
                httpURLConnection2 = httpURLConnection;
                inputStream = null;
            } catch (Throwable th) {
                th = th;
                bufferedReader = null;
            }
        } catch (IOException e3) {
            e = e3;
            inputStream = null;
            bufferedReader = null;
        } catch (Throwable th2) {
            th = th2;
            httpURLConnection = null;
            bufferedReader = null;
        }
        if (responseCode != 200) {
            if (httpURLConnection != null) {
                httpURLConnection.disconnect();
            }
            FileUtils.a((Closeable) null);
            FileUtils.a((Closeable) null);
            return new HotNovelData();
        }
        InputStream inputStream3 = httpURLConnection.getInputStream();
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream3));
            try {
                StringBuilder sb = new StringBuilder();
                while (true) {
                    String readLine = bufferedReader.readLine();
                    if (readLine == null) {
                        break;
                    }
                    sb.append(readLine);
                }
                HotNovelData hotNovelData = (HotNovelData) new Gson().fromJson(sb.toString(), HotNovelData.class);
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
                FileUtils.a((Closeable) inputStream3);
                FileUtils.a(bufferedReader);
                return hotNovelData;
            } catch (IOException e4) {
                httpURLConnection2 = httpURLConnection;
                inputStream = inputStream3;
                e = e4;
                try {
                    DLogger.a("DownloadPage.RecommendAd", "NovelPresenter getNovelJsonData error: " + e.getMessage());
                    if (httpURLConnection2 != null) {
                        httpURLConnection2.disconnect();
                    }
                    FileUtils.a((Closeable) inputStream);
                    FileUtils.a(bufferedReader);
                    return new HotNovelData();
                } catch (Throwable th3) {
                    th = th3;
                    HttpURLConnection httpURLConnection3 = httpURLConnection2;
                    inputStream2 = inputStream;
                    httpURLConnection = httpURLConnection3;
                    if (httpURLConnection != null) {
                        httpURLConnection.disconnect();
                    }
                    FileUtils.a((Closeable) inputStream2);
                    FileUtils.a(bufferedReader);
                    throw th;
                }
            } catch (Throwable th4) {
                th = th4;
                inputStream2 = inputStream3;
                if (httpURLConnection != null) {
                }
                FileUtils.a((Closeable) inputStream2);
                FileUtils.a(bufferedReader);
                throw th;
            }
        } catch (IOException e5) {
            httpURLConnection2 = httpURLConnection;
            inputStream = inputStream3;
            e = e5;
            bufferedReader = null;
        } catch (Throwable th5) {
            th = th5;
            bufferedReader = null;
        }
    }

    @Override
    public void a(DownloadTask downloadTask, final IAdDataListener iAdDataListener) {
        String a2 = a(downloadTask);
        if (TextUtils.isEmpty(UrlUtils.getDataFromQbUrl(a2, "queryString"))) {
            DLogger.a("DownloadPage.RecommendAd", "NovelPresenter requestData queryString empty");
        } else {
            b(a2).a(new Continuation() {
                @Override
                public final Object then(QBTask qBTask) {
                    Void a3;
                    a3 = RecommendNovelPresenter.this.a(iAdDataListener, qBTask);
                    return a3;
                }
            }, 6);
        }
    }

    @Override
    public boolean a() {
        return this.f37206b.a();
    }

    @Override
    public View b() {
        return this.f37206b;
    }

    @Override
    public int c() {
        return f37205a;
    }
}