package com.bytedance.android.livesdk.broadcast.interaction.widget.netspeed;

import X.0CB;
import X.0CH;
import X.0aP;
import X.0bI;
import X.0cm;
import X.28M;
import X.6Is;
import X.7AW;
import X.C1313Fz8;
import X.C2164GUr;
import X.C2165GUs;
import X.C2409Gbi;
import X.C2455GcS;
import X.C3491GtA;
import android.app.Activity;
import android.content.Context;
import com.bytedance.android.livesdkapi.host.IHostApp;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import kotlin.h.b.n;

public final class GameLiveNetSpeedMonitorWidget extends NetSpeedMonitorWidget implements 6Is {
    public static final C2165GUs LIZ = new C2165GUs((byte) 0);
    public long LJIIJ = System.currentTimeMillis();
    public long LJIIJJI = System.currentTimeMillis();
    public long LJIIL = System.currentTimeMillis();
    public long LJIILIIL;
    public boolean LJIILJJIL = true;

    static {
        Covode.recordClassIndex(11957);
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public final void LIZ() {
        DataChannel dataChannel = this.dataChannel;
        if (dataChannel != null) {
            dataChannel.LIZ((Object) this, 28M.class, new C2164GUr(this));
        }
    }

    public final void LIZ(int i) {
        boolean z;
        boolean z2;
        boolean z3;
        String str;
        String str2;
        String str3;
        int i2 = i;
        if (C2409Gbi.LJFF) {
            0aP.LIZ(4, "GameLiveNetworkStatus", "onNetworkStatus(). status=".concat(String.valueOf(i2)));
        }
        int i3 = this.LJ;
        super.LIZ(i2);
        String str4 = "back";
        boolean z4 = true;
        if (i3 != this.LIZLLL) {
            int i4 = this.LIZLLL;
            String str5 = "good";
            if (i4 == 2) {
                str2 = "bad";
            } else if (i4 != 3) {
                str2 = str5;
            } else {
                str2 = "stuck";
            }
            if (i3 == 2) {
                str5 = "bad";
            } else if (i3 == 3) {
                str5 = "stuck";
            }
            IHostApp LIZ2 = 0cm.LIZ(IHostApp.class);
            n.LIZIZ(LIZ2, "");
            boolean isAppForeground = LIZ2.isAppForeground();
            if (isAppForeground) {
                str3 = "front";
            } else if (!isAppForeground) {
                str3 = str4;
            } else {
                throw new 7AW();
            }
            C3491GtA LIZ3 = C3491GtA.LJFF.LIZ("livesdk_live_anchor_network_status_show");
            LIZ3.LIZ("current_status", str2);
            LIZ3.LIZ("previous_status", str5);
            LIZ3.LIZ("app_status", str3);
            LIZ3.LIZ(this.dataChannel);
            LIZ3.LIZLLL();
        }
        long currentTimeMillis = System.currentTimeMillis();
        if (this.LJIILJJIL) {
            this.LJIIJ = currentTimeMillis;
            this.LJIIJJI = currentTimeMillis;
            this.LJIIL = currentTimeMillis;
            this.LJIILJJIL = false;
        }
        int i5 = this.LIZLLL;
        if (i5 == 1) {
            this.LJIIJ = currentTimeMillis;
        } else if (i5 == 2) {
            this.LJIIJJI = currentTimeMillis;
        } else if (i5 == 3) {
            this.LJIIL = currentTimeMillis;
        }
        long j = this.LJIIJJI;
        long j2 = this.LJIIJ;
        if (j - j2 > 30000) {
            z = true;
        } else {
            z = false;
        }
        if (this.LJIIL - j2 > 5000) {
            z2 = true;
        } else {
            z2 = false;
        }
        if (System.currentTimeMillis() - this.LJIILIIL >= 1800000) {
            z3 = true;
        } else {
            z3 = false;
        }
        Activity LIZ4 = 0bI.LIZ(getContext());
        if (z3) {
            if (z) {
                str = "good_to_bad";
            } else if (z2) {
                str = "good_to_stuck";
            }
            IHostApp LIZ5 = 0cm.LIZ(IHostApp.class);
            n.LIZIZ(LIZ5, "");
            boolean isAppForeground2 = LIZ5.isAppForeground();
            if (isAppForeground2) {
                str4 = "front";
            } else if (isAppForeground2) {
                throw new 7AW();
            }
            C3491GtA LIZ6 = C3491GtA.LJFF.LIZ("livesdk_live_anchor_network_notification_show");
            LIZ6.LIZ("notification_type", str);
            LIZ6.LIZ("app_status", str4);
            LIZ6.LIZ(this.dataChannel);
            LIZ6.LIZLLL();
            DataChannel dataChannel = this.dataChannel;
            if (dataChannel != null) {
                dataChannel.LIZJ(C2455GcS.class);
            }
            this.LJIILIIL = System.currentTimeMillis();
            if (LIZ4 != null) {
                C1313Fz8.LIZ((Context) LIZ4, LIZ4.getString(2131828779), 3000);
                return;
            }
            return;
        }
        if (C2409Gbi.LJFF) {
            StringBuilder sb = new StringBuilder("not show toast. activity is null: ");
            if (LIZ4 != null) {
                z4 = false;
            }
            sb.append(z4);
            sb.append("; shouldToastAgain=");
            sb.append(z3);
            sb.append("; becomeBadContinueDuration=");
            sb.append(z);
            sb.append("; becomeStuckContinueDuration=");
            sb.append(z2);
            0aP.LIZ(4, "GameLiveNetSpeedMonitorWidget", sb.toString());
        }
    }
}
