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

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


package com.tencent.mtt.browser.homepage.xhome.guide.newuser;

import android.text.TextUtils;
import com.tencent.common.task.QBTask;
import com.tencent.common.utils.FileUtils;
import com.tencent.mtt.base.wup.PreferenceData;
import com.tencent.mtt.browser.download.business.core.BusinessDownloadService;
import com.tencent.mtt.browser.download.core.impl.DownloadServiceManager;
import com.tencent.mtt.browser.download.engine.DownloadErrorDetail;
import com.tencent.mtt.browser.download.engine.DownloadInfo;
import com.tencent.mtt.browser.download.engine.DownloadTask;
import com.tencent.mtt.browser.download.engine.DownloadTaskListener;
import com.tencent.mtt.browser.download.engine.PauseReason;
import com.tencent.mtt.browser.download.engine.RemovePolicy;
import com.tencent.mtt.browser.homepage.fastcut.manager.FastCutGuideManager;
import com.tencent.mtt.browser.homepage.fastcut.report.FastCutReportHelper;
import com.tencent.mtt.browser.window.home.view.HomeTabModeDispather;
import com.tencent.mtt.log.access.Logs;
import com.tencent.mtt.setting.PublicSettingManager;
import java.io.File;
import java.util.concurrent.Callable;
import kotlin.Lazy;
import kotlin.LazyKt;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import org.json.JSONObject;

public final class XHomeGuideVideoDownloader {

    public static final Companion f41509a = new Companion(null);

    private static final Lazy f41510d = LazyKt.lazy(new Function0<XHomeGuideVideoDownloader>() {
        @Override
        public final XHomeGuideVideoDownloader invoke() {
            return new XHomeGuideVideoDownloader();
        }
    });

    private String f41511b;

    private String f41512c;

    public static final class Companion {
        private Companion() {
        }

        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        public final XHomeGuideVideoDownloader a() {
            Lazy lazy = XHomeGuideVideoDownloader.f41510d;
            Companion companion = XHomeGuideVideoDownloader.f41509a;
            return (XHomeGuideVideoDownloader) lazy.getValue();
        }
    }

    public XHomeGuideVideoDownloader() {
        String a2 = PreferenceData.a("KEY_XHOME_USER_GUIDE_VIDEO_CONFIG");
        try {
            JSONObject jSONObject = new JSONObject(TextUtils.isEmpty(a2) ? "{\"switch\": \"true\",\"video_is_xhome_tab\": \"https://static.res.qq.com/nav/xhome/xhome_guide_video_has_setting1028.mp4\",\"video_not_xhome_tab\": \"https://static.res.qq.com/nav/xhome/xhome_guide_video_not_setting1028.mp4\"}" : a2);
            String optString = jSONObject.optString("switch", "false");
            if (optString == null || !Boolean.parseBoolean(optString)) {
                return;
            }
            this.f41511b = jSONObject.optString("video_not_xhome_tab", "");
            this.f41512c = jSONObject.optString("video_is_xhome_tab", "");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private final void a(File file, String str, final String str2, final String str3) {
        DownloadInfo downloadInfo = new DownloadInfo();
        downloadInfo.f37604a = str2;
        downloadInfo.f = file.getAbsolutePath();
        downloadInfo.f37606c = str;
        downloadInfo.A = true;
        downloadInfo.j = false;
        downloadInfo.h = false;
        downloadInfo.H |= 32;
        DownloadServiceManager.a().addTaskListener(str2, new DownloadTaskListener() {
            @Override
            public void onTaskCompleted(DownloadTask downloadTask) {
                Logs.c("FASTCUTLOG", "doDownloadVideoAndReport onTaskCompleted " + str2 + " download ok!");
                PublicSettingManager.a().setString(str3, downloadTask != null ? downloadTask.O() : null);
            }

            @Override
            public void onTaskCreated(DownloadTask downloadTask) {
            }

            @Override
            public void onTaskFailed(DownloadTask downloadTask, DownloadErrorDetail downloadErrorDetail) {
            }

            @Override
            public void onTaskPaused(DownloadTask downloadTask, PauseReason pauseReason) {
            }

            @Override
            public void onTaskProgress(DownloadTask downloadTask) {
            }

            @Override
            public void onTaskRemoved(DownloadTask downloadTask) {
            }

            @Override
            public void onTaskStarted(DownloadTask downloadTask) {
            }

            @Override
            public void onTaskWaiting(DownloadTask downloadTask) {
            }
        });
        DownloadServiceManager.a().startDownloadTask(downloadInfo, null, null);
    }

    private final boolean a(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return new File(str).exists();
    }

    private final boolean a(String str, String str2, String str3) {
        DownloadTask downloadTaskByUrl = DownloadServiceManager.a().getDownloadTaskByUrl(str);
        if (downloadTaskByUrl == null) {
            a(n(), str2, str, str3);
            return false;
        }
        if (downloadTaskByUrl.U() == 3) {
            PublicSettingManager.a().setString(str3, downloadTaskByUrl.O());
            return true;
        }
        if (downloadTaskByUrl.U() != 2) {
            BusinessDownloadService.getInstance().a().c(downloadTaskByUrl);
        }
        return false;
    }

    private final String b(String str) {
        String c2 = FileUtils.c(str);
        Intrinsics.checkExpressionValueIsNotNull(c2, "FileUtils.getFileName(downloadUrl)");
        return c2;
    }

    public static final XHomeGuideVideoDownloader k() {
        return f41509a.a();
    }

    public final void l() {
        Logs.c("FASTCUTLOG", "doDownloadVideoAndReport " + this.f41511b + ' ' + this.f41512c);
        m();
        if (TextUtils.isEmpty(this.f41511b) || TextUtils.isEmpty(this.f41512c)) {
            return;
        }
        int i = 0;
        String str = this.f41511b;
        if (str != null && a(str, b(str), "KEY_FILE_NAME_VIDEO_NAME_GUIDE_UN_XHOME")) {
            Logs.c("FASTCUTLOG", "doDownloadVideoAndReport " + this.f41511b + " download ok!");
            i = 1;
        }
        String str2 = this.f41512c;
        if (str2 != null && a(str2, b(str2), "KEY_FILE_NAME_VIDEO_NAME_GUIDE_IS_XHOME")) {
            i++;
            Logs.c("FASTCUTLOG", "doDownloadVideoAndReport " + this.f41512c + " download ok!");
        }
        if (i == 2) {
            FastCutReportHelper.p();
        }
    }

    private final void m() {
        try {
            File file = new File(n(), ".nomedia");
            if (file.exists()) {
                return;
            }
            file.createNewFile();
        } catch (Exception unused) {
        }
    }

    private final File n() {
        File a2 = FileUtils.a(FileUtils.e(), "xhome_guide_mp4");
        Intrinsics.checkExpressionValueIsNotNull(a2, "FileUtils.createDir(File….getDataDir(), VIDEO_DIR)");
        return a2;
    }

    public final String a() {
        return this.f41511b;
    }

    public final String b() {
        return this.f41512c;
    }

    public final void c() {
        Boolean a2 = FastCutGuideManager.f().a();
        if (a2 == null) {
            FastCutGuideManager.f().a(new FastCutGuideManager.OnGuidInfoLoadedListener() {
                @Override
                public final void a(boolean z) {
                    if (z) {
                        XHomeGuideVideoDownloader.this.l();
                    } else {
                        XHomeGuideVideoDownloader.this.i();
                    }
                }
            });
        } else if (a2.booleanValue()) {
            l();
        } else {
            i();
        }
    }

    public final String d() {
        String string = PublicSettingManager.a().getString("KEY_FILE_NAME_VIDEO_NAME_GUIDE_UN_XHOME", "");
        Intrinsics.checkExpressionValueIsNotNull(string, "PublicSettingManager.get…_NAME_GUIDE_UN_XHOME, \"\")");
        return string;
    }

    public final String e() {
        String string = PublicSettingManager.a().getString("KEY_FILE_NAME_VIDEO_NAME_GUIDE_IS_XHOME", "");
        Intrinsics.checkExpressionValueIsNotNull(string, "PublicSettingManager.get…_NAME_GUIDE_IS_XHOME, \"\")");
        return string;
    }

    public final boolean f() {
        return a(d());
    }

    public final boolean g() {
        return a(e());
    }

    public final boolean h() {
        return Intrinsics.areEqual(String.valueOf(117), HomeTabModeDispather.a());
    }

    public final void i() {
        if (Intrinsics.areEqual("false", PublicSettingManager.a().getString("ANDROID_PUBLIC_PREFS_DELETE_GUIDE_VIDEO", "false"))) {
            return;
        }
        QBTask.a(new Callable<TResult>() {
            public final void a() {
                String a2 = XHomeGuideVideoDownloader.this.a();
                if (a2 != null) {
                    DownloadServiceManager.a().removeDownloadTask(a2, RemovePolicy.DELETE_TASK_AND_FILE);
                }
                String b2 = XHomeGuideVideoDownloader.this.b();
                if (b2 != null) {
                    DownloadServiceManager.a().removeDownloadTask(b2, RemovePolicy.DELETE_TASK_AND_FILE);
                }
                Logs.c("FASTCUTLOG", "tryDeleteDownloadVideos  ok!");
            }

            @Override
            public Object call() {
                a();
                return Unit.INSTANCE;
            }
        });
    }
}