package d3;

import V2.Q2;
import android.app.Activity;
import android.content.Context;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager;
import androidx.compose.runtime.DisposableEffectResult;
import androidx.compose.runtime.MutableState;
import androidx.media3.exoplayer.ExoPlayer;
import com.debridstream.tv.PlayerViewModel;
import java.util.concurrent.atomic.AtomicBoolean;

/* JADX INFO: loaded from: classes.dex */
public final class h2 implements DisposableEffectResult {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ AtomicBoolean f15668a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ PlayerViewModel f15669b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ Context f15670c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ MutableState f15671d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ MutableState f15672e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ kotlin.jvm.internal.y f15673f;

    public h2(AtomicBoolean atomicBoolean, PlayerViewModel playerViewModel, Context context, MutableState mutableState, MutableState mutableState2, kotlin.jvm.internal.y yVar) {
        this.f15668a = atomicBoolean;
        this.f15669b = playerViewModel;
        this.f15670c = context;
        this.f15671d = mutableState;
        this.f15672e = mutableState2;
        this.f15673f = yVar;
    }

    @Override // androidx.compose.runtime.DisposableEffectResult
    public final void dispose() {
        Integer num;
        Display display;
        Window window;
        this.f15668a.set(true);
        MutableState mutableState = this.f15671d;
        ExoPlayer exoPlayer = (ExoPlayer) mutableState.getValue();
        PlayerViewModel playerViewModel = this.f15669b;
        Q2 q22 = (Q2) playerViewModel.getUiState().getValue();
        Context context = this.f15670c;
        if (exoPlayer != null && q22.f7502g != null) {
            long duration = exoPlayer.getDuration();
            Long lValueOf = Long.valueOf(duration);
            if (duration <= 0) {
                lValueOf = null;
            }
            long jLongValue = lValueOf != null ? lValueOf.longValue() : 0L;
            if (jLongValue > 0) {
                long currentPosition = exoPlayer.getCurrentPosition();
                long j4 = currentPosition >= 0 ? currentPosition : 0L;
                a5.c cVar = g3.p.f16541a;
                Context applicationContext = context.getApplicationContext();
                kotlin.jvm.internal.o.g(applicationContext, "getApplicationContext(...)");
                g3.p.b(applicationContext, playerViewModel, j4, jLongValue, "player_dispose");
            }
        }
        if (exoPlayer != null) {
            v2.E0(exoPlayer);
        }
        mutableState.setValue(null);
        this.f15672e.setValue(Boolean.FALSE);
        Activity activityB0 = W.b.b0(context);
        if (activityB0 != null && (window = activityB0.getWindow()) != null && this.f15673f.f20130a) {
            window.clearFlags(128);
        }
        Activity activityB02 = W.b.b0(context);
        if (activityB02 != null && (num = W.c.f8379m) != null) {
            int iIntValue = num.intValue();
            try {
                Window window2 = activityB02.getWindow();
                if (window2 != null && (display = window2.getDecorView().getDisplay()) != null) {
                    if (display.getMode().getModeId() == iIntValue) {
                        W.c.f8379m = null;
                    } else {
                        W.c.f8377j = null;
                        W.c.f8376i = null;
                        W.c.f8378k = null;
                        W.c.l = null;
                        WindowManager.LayoutParams attributes = window2.getAttributes();
                        if (attributes == null) {
                            attributes = null;
                        }
                        if (attributes != null) {
                            attributes.preferredDisplayModeId = iIntValue;
                            window2.setAttributes(attributes);
                        }
                        W.c.f8379m = null;
                    }
                }
            } catch (Exception unused) {
            }
        }
        W.c.f8377j = null;
        W.c.f8376i = null;
        W.c.f8378k = null;
        W.c.l = null;
    }
}
