package com.bytedance.android.livesdk.actionhandler;

import X.0UN;
import X.0aP;
import X.0b0;
import X.0cm;
import X.0yx;
import X.1JF;
import X.1c5;
import X.C1313Fz8;
import X.C1939GMa;
import X.C2992Gl7;
import X.C3259GpQ;
import X.C3439GsK;
import X.C3440GsL;
import X.C3459Gse;
import X.C3480Gsz;
import X.C3598Gut;
import X.H13;
import X.HBB;
import X.HBD;
import X.HBF;
import X.HBG;
import X.HBI;
import X.HBK;
import X.HBL;
import X.HBM;
import X.HBN;
import X.HBO;
import X.HBP;
import X.HBQ;
import X.HBR;
import X.HBS;
import X.M12;
import X.Mk2;
import X.Mk3;
import X.PhE;
import X.PlI;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import com.bytedance.android.live.actionhandler.IActionHandlerService;
import com.bytedance.android.live.browser.IBrowserService;
import com.bytedance.android.livesdk.livesetting.roomfunction.LiveRouterOptimizeSetting;
import com.bytedance.android.livesdkapi.depend.model.report.ReportCommitData;
import com.bytedance.android.livesdkapi.host.IHostAction;
import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ActionHandlerService implements IActionHandlerService {
    public HBB optimizeActionHandler = new HBB();
    public List<HBQ> schemaHandlers = new ArrayList();
    public C2992Gl7 userProfileActionHandler;

    static {
        Covode.recordClassIndex(11255);
    }

    public void onInit() {
    }

    public ActionHandlerService() {
        C3439GsK gsK = new C3439GsK();
        this.schemaHandlers.add(gsK);
        C2992Gl7 gl7 = new C2992Gl7();
        this.userProfileActionHandler = gl7;
        this.schemaHandlers.add(gl7);
        HBF hbf = new HBF();
        this.schemaHandlers.add(hbf);
        C3440GsL gsL = new C3440GsL();
        this.schemaHandlers.add(gsL);
        H13 h13 = new H13();
        this.schemaHandlers.add(h13);
        C3459Gse gse = new C3459Gse();
        this.schemaHandlers.add(gse);
        C3259GpQ gpQ = new C3259GpQ();
        this.schemaHandlers.add(gpQ);
        HBI hbi = new HBI();
        this.schemaHandlers.add(hbi);
        C3480Gsz gsz = new C3480Gsz();
        this.schemaHandlers.add(gsz);
        C1939GMa gMa = new C1939GMa();
        this.schemaHandlers.add(gMa);
        if (LiveRouterOptimizeSetting.INSTANCE.getValue()) {
            this.optimizeActionHandler.LIZ(new HBK(gsK));
            this.optimizeActionHandler.LIZ(new HBP(this.userProfileActionHandler));
            this.optimizeActionHandler.LIZ(new HBN(gse));
            this.optimizeActionHandler.LIZ(new HBM(gsz));
            this.optimizeActionHandler.LIZ(new HBO(gMa));
            this.optimizeActionHandler.LIZ(new HBL(h13));
            this.optimizeActionHandler.LIZ(new HBD(hbf, hbi, gsL, gpQ));
        }
    }

    public boolean showUserProfile(long j) {
        return this.userProfileActionHandler.LIZ(j, (String) null, (Map<String, String>) null);
    }

    private boolean canHandleLegacy(Uri uri) {
        for (HBQ LIZ : this.schemaHandlers) {
            if (LIZ.LIZ(uri)) {
                return true;
            }
        }
        return false;
    }

    private HBQ getHandler(Uri uri) {
        for (HBQ next : this.schemaHandlers) {
            if (next.LIZ(uri)) {
                return next;
            }
        }
        return null;
    }

    public static final /* synthetic */ void lambda$postReportReason$1$ActionHandlerService(Throwable th) {
        if (th instanceof 1JF) {
            C1313Fz8.LIZ(0b0.LJ(), ((1JF) th).getErrorMsg(), 0);
            0aP.LIZ("ALogger", th);
        }
    }

    public static final /* synthetic */ void lambda$postReportReason$0$ActionHandlerService(1c5 r3) {
        if (r3 != null && r3.data != null && !TextUtils.isEmpty(((ReportCommitData) r3.data).desc)) {
            C1313Fz8.LIZ(0b0.LJ(), ((ReportCommitData) r3.data).desc, 0);
        }
    }

    public boolean canHandle(Uri uri) {
        if (!LiveRouterOptimizeSetting.INSTANCE.getValue()) {
            return canHandleLegacy(uri);
        }
        HBB hbb = this.optimizeActionHandler;
        M12.LIZ(uri);
        HBG hbg = hbb.LIZ.get(uri.getHost());
        if (hbg == null || !hbg.LIZ(uri)) {
            return false;
        }
        return true;
    }

    public boolean handle(Context context, Uri uri) {
        return handleSchema(context, uri, true);
    }

    public boolean handle(Context context, String str) {
        return handleSchema(context, Uri.parse(str), true);
    }

    public boolean handleWithoutHost(Context context, String str) {
        return handleSchema(context, Uri.parse(str), false);
    }

    public boolean handleWithoutHost(Context context, Uri uri, Map<String, String> map) {
        return handleSchema(context, uri, false, map);
    }

    public boolean showUserProfile(long j, String str, Map<String, String> map) {
        return this.userProfileActionHandler.LIZ(j, str, map);
    }

    private boolean handleSchema(Context context, Uri uri, boolean z) {
        if (LiveRouterOptimizeSetting.INSTANCE.getValue()) {
            return this.optimizeActionHandler.LIZ(context, uri, z, (Map<String, String>) null);
        }
        if ((TextUtils.equals(uri.getScheme(), "http") || TextUtils.equals(uri.getScheme(), "https")) && z) {
            0cm.LIZ(IBrowserService.class).webViewManager().LIZ(context, C3598Gut.LIZIZ(uri.toString()));
            0UN.LIZ(uri, "handler_type_legacy", "handler_path_live");
            return true;
        }
        HBQ handler = getHandler(uri);
        if (handler != null) {
            0UN.LIZ(uri, "handler_type_legacy", "handler_path_live");
            return handler.LIZ(context, uri);
        } else if (!z || !0cm.LIZ(IHostAction.class).handleSchema(context, uri.toString(), new Bundle())) {
            return false;
        } else {
            return true;
        }
    }

    public void postReportReason(long j, long j2, long j3, String str) {
        ((ActionHandlerApi) 0yx.LIZ().LIZ(ActionHandlerApi.class)).postReportReasons(j, j2, j3, str).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(Mk2.LIZ(Mk3.LIZ)).LIZ(HBR.LIZ, HBS.LIZ);
    }

    private boolean handleSchema(Context context, Uri uri, boolean z, Map<String, String> map) {
        if (LiveRouterOptimizeSetting.INSTANCE.getValue()) {
            return this.optimizeActionHandler.LIZ(context, uri, z, map);
        }
        if ((TextUtils.equals(uri.getScheme(), "http") || TextUtils.equals(uri.getScheme(), "https")) && z) {
            0cm.LIZ(IBrowserService.class).webViewManager().LIZ(context, C3598Gut.LIZIZ(uri.toString()));
            0UN.LIZ(uri, "handler_type_legacy", "handler_path_live");
            return true;
        }
        HBQ handler = getHandler(uri);
        if (handler != null) {
            0UN.LIZ(uri, "handler_type_legacy", "handler_path_live");
            return handler.LIZ(context, uri, map);
        } else if (!z || !0cm.LIZ(IHostAction.class).handleSchema(context, uri.toString(), new Bundle())) {
            return false;
        } else {
            return true;
        }
    }
}
