导航菜单

页面标题

页面副标题

Top浏览器 v4.6.16 - DownloadDialog.java 源代码

正在查看: Top浏览器 v4.6.16 应用的 DownloadDialog.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.pocket.common.download;

import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.core.content.FileProvider;
import c.h.a.e.d;
import c.h.b.i.c;
import c.t.a.d.n;
import c.t.a.i.y;
import c.t.a.i.z;
import c.t.a.k.f;
import c.t.a.w.k;
import c.t.a.w.l0;
import com.google.android.exoplayer2.source.rtsp.RtspHeaders;
import com.pocket.common.R$id;
import com.pocket.common.R$layout;
import com.pocket.common.R$style;
import com.pocket.common.base.BaseDialogFragment;
import com.pocket.common.dialog.confirm.ConfirmDialog;
import com.pocket.common.download.DownloadDialog;
import h.b0.d.g;
import h.b0.d.l;
import h.b0.d.m;
import h.i0.s;
import h.i0.t;
import h.u;
import java.io.File;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

public final class DownloadDialog extends BaseDialogFragment {

    public static final a f760p = new a(null);

    public GradientDrawable f761q;

    public GradientDrawable f762r;
    public h.b0.c.a<u> s;
    public String u;

    @SuppressLint({RtspHeaders.RANGE})
    public final ActivityResultLauncher<Intent> w;
    public int t = c.e("download_index", 0);
    public String v = "";

    public static final class a {
        public a() {
        }

        public a(g gVar) {
            this();
        }

        public final DownloadDialog a(String str, String str2) {
            l.f(str, "name");
            l.f(str2, IjkMediaPlayer.OnNativeInvokeListener.ARG_URL);
            DownloadDialog downloadDialog = new DownloadDialog();
            Bundle bundle = new Bundle();
            bundle.putString("name", str);
            bundle.putString(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, str2);
            downloadDialog.setArguments(bundle);
            return downloadDialog;
        }
    }

    public static final class b extends m implements h.b0.c.a<u> {

        public static final class a implements c.t.a.i.c0.a {
            public final DownloadDialog a;

            public a(DownloadDialog downloadDialog) {
                this.a = downloadDialog;
            }

            @Override
            public void a(c.t.a.i.b0.b bVar) {
            }

            @Override
            public void b(c.t.a.i.b0.b bVar, String str) {
            }

            @Override
            public void c(c.t.a.i.b0.b bVar) {
            }

            @Override
            public void d(c.t.a.i.b0.b bVar) {
            }

            @Override
            public void e(c.t.a.i.b0.b bVar) {
                if (bVar == null) {
                    return;
                }
                DownloadDialog downloadDialog = this.a;
                String d = bVar.d();
                l.e(d, "task.fullPath");
                downloadDialog.w(d);
            }

            @Override
            public void f(c.t.a.i.b0.b bVar) {
            }

            @Override
            public void g(c.t.a.i.b0.b bVar) {
            }
        }

        public b() {
            super(0);
        }

        public Object invoke() {
            m62invoke();
            return u.a;
        }

        public final void m62invoke() {
            z zVar = new z();
            zVar.m(c.t.a.w.z.a());
            zVar.n("/storage/emulated/0/Download/");
            zVar.l("idm+.apk");
            zVar.p("https://file.zhenxiangpa.com/browser/IDM.apk");
            y.r().i(zVar, new a(DownloadDialog.this));
            d.c("开始下载,请在下载管理查看");
            c.h.b.c.a.a("download_update").h(0);
        }
    }

    public DownloadDialog() {
        ActivityResultLauncher<Intent> registerForActivityResult = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                DownloadDialog.s(DownloadDialog.this, (ActivityResult) obj);
            }
        });
        l.e(registerForActivityResult, "registerForActivityResul…        }\n        }\n    }");
        this.w = registerForActivityResult;
        f(R$style.BottomEnterAnimation);
        n(true);
        o(true);
        m(0);
        p(-1, -2);
    }

    public static final void D(DownloadDialog downloadDialog, View view) {
        l.f(downloadDialog, "this$0");
        downloadDialog.w.launch(new Intent("android.intent.action.OPEN_DOCUMENT_TREE"));
    }

    public static final void E(DownloadDialog downloadDialog, View view) {
        l.f(downloadDialog, "this$0");
        c.k("download_index", 0);
        downloadDialog.J(0);
    }

    public static final void F(DownloadDialog downloadDialog, View view) {
        l.f(downloadDialog, "this$0");
        c.k("download_index", 1);
        downloadDialog.J(1);
    }

    public static final void G(DownloadDialog downloadDialog, View view) {
        l.f(downloadDialog, "this$0");
        downloadDialog.dismiss();
    }

    public static final void H(DownloadDialog downloadDialog, View view) {
        l.f(downloadDialog, "this$0");
        downloadDialog.t();
    }

    public static final void s(DownloadDialog downloadDialog, ActivityResult activityResult) {
        Intent data;
        Uri data2;
        l.f(downloadDialog, "this$0");
        if (activityResult.getResultCode() != -1 || (data = activityResult.getData()) == null || (data2 = data.getData()) == null) {
            return;
        }
        String m2 = l.m(l0.a(data2), "/");
        c.m("downloadLocation", m2);
        c.m("download_tree_path", data2.toString());
        Log.e("=====", data2.toString());
        View view = downloadDialog.getView();
        ((TextView) (view == null ? null : view.findViewById(R$id.tv_download_path))).setText(m2);
    }

    public final void I(h.b0.c.a<u> aVar) {
        this.s = aVar;
    }

    public final void J(int i) {
        this.t = i;
        if (i == 0) {
            View view = getView();
            ((TextView) (view == null ? null : view.findViewById(R$id.tv_default_download))).setBackground(v());
            View view2 = getView();
            ((TextView) (view2 != null ? view2.findViewById(R$id.tv_idm_download) : null)).setBackground(u());
            return;
        }
        if (i != 1) {
            return;
        }
        View view3 = getView();
        ((TextView) (view3 == null ? null : view3.findViewById(R$id.tv_default_download))).setBackground(u());
        View view4 = getView();
        ((TextView) (view4 != null ? view4.findViewById(R$id.tv_idm_download) : null)).setBackground(v());
    }

    public final boolean K(String str, String str2) {
        try {
            Intent intent = new Intent();
            intent.setType("text/plain");
            intent.setAction("android.intent.action.SEND");
            intent.putExtra("android.intent.extra.TEXT", str2);
            intent.putExtra("title", str);
            intent.setComponent(new ComponentName("idm.internet.download.manager.plus", "idm.internet.download.manager.UrlHandlerDownloader"));
            Context context = getContext();
            if (context != null) {
                context.startActivity(intent);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return true;
        }
    }

    @Override
    public n getDataBindingConfig() {
        return new n(R$layout.common_dialog_download, 0, null);
    }

    @Override
    public void initViewModel() {
    }

    @Override
    public void onViewCreated(View view, Bundle bundle) {
        l.f(view, "view");
        super.onViewCreated(view, bundle);
        Bundle arguments = getArguments();
        this.u = arguments == null ? null : arguments.getString(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL);
        Bundle arguments2 = getArguments();
        String string = arguments2 == null ? null : arguments2.getString("name");
        if (string != null && t.L(string, ".", false, 2, (Object) null)) {
            int i = -1;
            int length = string.length() - 1;
            while (true) {
                if (length < 0) {
                    break;
                }
                if (string.charAt(length) == '.') {
                    i = length;
                    break;
                }
                length--;
            }
            View view2 = getView();
            View findViewById = view2 == null ? null : view2.findViewById(R$id.et_file_name);
            String substring = string.substring(0, i);
            l.e(substring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
            ((EditText) findViewById).setText(s.A(substring, ":", "", false, 4, (Object) null));
            String substring2 = string.substring(i);
            l.e(substring2, "(this as java.lang.String).substring(startIndex)");
            this.v = substring2;
        }
        View view3 = getView();
        ((EditText) (view3 == null ? null : view3.findViewById(R$id.et_file_name))).setHighlightColor(Color.parseColor("#A4CDC9"));
        View view4 = getView();
        ((TextView) (view4 == null ? null : view4.findViewById(R$id.tv_download_path))).setText("/storage/emulated/0/Download/");
        View view5 = getView();
        ((LinearLayout) (view5 == null ? null : view5.findViewById(R$id.ll_download_path))).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view6) {
                DownloadDialog.D(DownloadDialog.this, view6);
            }
        });
        View view6 = getView();
        ((TextView) (view6 == null ? null : view6.findViewById(R$id.tv_default_download))).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view7) {
                DownloadDialog.E(DownloadDialog.this, view7);
            }
        });
        View view7 = getView();
        ((TextView) (view7 == null ? null : view7.findViewById(R$id.tv_idm_download))).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view8) {
                DownloadDialog.F(DownloadDialog.this, view8);
            }
        });
        View view8 = getView();
        ((TextView) (view8 == null ? null : view8.findViewById(R$id.tv_cancel))).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view9) {
                DownloadDialog.G(DownloadDialog.this, view9);
            }
        });
        View view9 = getView();
        ((TextView) (view9 != null ? view9.findViewById(R$id.tv_confirm) : null)).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view10) {
                DownloadDialog.H(DownloadDialog.this, view10);
            }
        });
        J(this.t);
    }

    public final void t() {
        String str = this.u;
        if (str == null || str.length() == 0) {
            d.c("下载链接异常");
            return;
        }
        StringBuilder sb = new StringBuilder();
        View view = getView();
        Editable text = ((EditText) (view == null ? null : view.findViewById(R$id.et_file_name))).getText();
        l.e(text, "et_file_name.text");
        sb.append((Object) t.M0(text));
        sb.append(this.v);
        String sb2 = sb.toString();
        int i = this.t;
        if (i != 0) {
            if (i == 1) {
                if (!k.f()) {
                    new ConfirmDialog.a().v("注意").r("手机没有安装IDM+,确认下载安装IDM+吗?").m(new b()).a().q(getParentFragmentManager());
                    return;
                }
                String str2 = this.u;
                l.d(str2);
                K(sb2, str2);
                return;
            }
            return;
        }
        z zVar = new z();
        zVar.m(c.t.a.w.z.a());
        zVar.n("/storage/emulated/0/Download/");
        zVar.l(s.A(s.A(s.A(sb2, " ", "", false, 4, (Object) null), "\\u3000", "", false, 4, (Object) null), "\t", "", false, 4, (Object) null));
        zVar.p(this.u);
        if (t.L(sb2, ".m3u8", false, 2, (Object) null)) {
            y.r().j(zVar);
        } else {
            y.r().h(zVar);
        }
        h.b0.c.a<u> aVar = this.s;
        if (aVar == null) {
            d.c("开始下载,请在下载管理查看");
        } else if (aVar != null) {
            aVar.invoke();
        }
        c.h.b.c.a.a("download_update").h(0);
        dismiss();
    }

    public final GradientDrawable u() {
        if (this.f762r == null) {
            GradientDrawable gradientDrawable = new GradientDrawable();
            this.f762r = gradientDrawable;
            l.d(gradientDrawable);
            gradientDrawable.setCornerRadius(f.a(12));
            GradientDrawable gradientDrawable2 = this.f762r;
            l.d(gradientDrawable2);
            gradientDrawable2.setStroke(f.a(1), Color.parseColor(c.t.a.u.a.a.b() ? "#333333" : "#cccccc"), 0.0f, 0.0f);
        }
        GradientDrawable gradientDrawable3 = this.f762r;
        l.d(gradientDrawable3);
        return gradientDrawable3;
    }

    public final GradientDrawable v() {
        if (this.f761q == null) {
            GradientDrawable gradientDrawable = new GradientDrawable();
            this.f761q = gradientDrawable;
            l.d(gradientDrawable);
            gradientDrawable.setCornerRadius(f.a(12));
            GradientDrawable gradientDrawable2 = this.f761q;
            l.d(gradientDrawable2);
            gradientDrawable2.setStroke(f.a(1), Color.parseColor(c.t.a.u.a.a.b() ? "#cccccc" : "#333333"), 0.0f, 0.0f);
        }
        GradientDrawable gradientDrawable3 = this.f761q;
        l.d(gradientDrawable3);
        return gradientDrawable3;
    }

    public final void w(String str) {
        File file = new File(str);
        if (file.exists()) {
            Intent intent = new Intent("android.intent.action.VIEW");
            if (Build.VERSION.SDK_INT >= 24) {
                intent.setFlags(1);
                intent.addFlags(268435456);
                try {
                    intent.setDataAndType(FileProvider.getUriForFile(this.b.getApplication(), "com.pocket.topbrowser.fileprovider", file), "application/vnd.android.package-archive");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                intent.addFlags(268468224);
                intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
            }
            try {
                this.b.startActivity(intent);
            } catch (ActivityNotFoundException e2) {
                e2.printStackTrace();
            }
        }
    }
}