package com.vinfast.companion.core.utils.video;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes15.dex */
@dagger.hilt.android.lifecycle.HiltViewModel
@kotlin.Metadata(d1 = {"\u0000p\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\b\u0011\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0010!\n\u0002\b\u0004\n\u0002\u0010\u0007\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0010\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0010\t\n\u0002\b\u0005\b\u0007\u0018\u00002\u00020\u0001B\t\b\u0007¢\u0006\u0004\b\u0002\u0010\u0003J\u000f\u0010\u0005\u001a\u00020\u0004H\u0002¢\u0006\u0004\b\u0005\u0010\u0003J\u0017\u0010\b\u001a\u00020\u00042\u0006\u0010\u0007\u001a\u00020\u0006H\u0002¢\u0006\u0004\b\b\u0010\tJ/\u0010\u0010\u001a\u00020\u00042\u0016\u0010\r\u001a\u0012\u0012\u0004\u0012\u00020\u000b0\nj\b\u0012\u0004\u0012\u00020\u000b`\f2\b\b\u0002\u0010\u000f\u001a\u00020\u000e¢\u0006\u0004\b\u0010\u0010\u0011J)\u0010\u0016\u001a\u00020\u00042\b\b\u0002\u0010\u0012\u001a\u00020\u00062\u0006\u0010\u0014\u001a\u00020\u00132\b\b\u0002\u0010\u0015\u001a\u00020\u0006¢\u0006\u0004\b\u0016\u0010\u0017J\r\u0010\u0018\u001a\u00020\u0004¢\u0006\u0004\b\u0018\u0010\u0003J\u0015\u0010\u001a\u001a\u00020\u00042\u0006\u0010\u0019\u001a\u00020\u000e¢\u0006\u0004\b\u001a\u0010\u001bJ\r\u0010\u001c\u001a\u00020\u0004¢\u0006\u0004\b\u001c\u0010\u0003J\u0017\u0010\u001f\u001a\u00020\u00042\b\u0010\u001e\u001a\u0004\u0018\u00010\u001d¢\u0006\u0004\b\u001f\u0010 J\u0015\u0010\"\u001a\u00020\u00062\u0006\u0010!\u001a\u00020\u000b¢\u0006\u0004\b\"\u0010#J\r\u0010$\u001a\u00020\u0004¢\u0006\u0004\b$\u0010\u0003J\u0015\u0010&\u001a\u00020\u00042\u0006\u0010%\u001a\u00020\u0006¢\u0006\u0004\b&\u0010\tJ\u0015\u0010(\u001a\u00020\u00042\u0006\u0010'\u001a\u00020\u000e¢\u0006\u0004\b(\u0010\u001bJ\r\u0010)\u001a\u00020\u0004¢\u0006\u0004\b)\u0010\u0003J\u0017\u0010+\u001a\u00020\u00042\b\b\u0002\u0010*\u001a\u00020\u0006¢\u0006\u0004\b+\u0010\tR\u0018\u0010.\u001a\u0004\u0018\u00010\u001d8\u0002@\u0002X\u0083\u000e¢\u0006\u0006\n\u0004\b,\u0010-R*\u00106\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u00130/8\u0006@\u0006X\u0086\u000e¢\u0006\u0012\n\u0004\b0\u00101\u001a\u0004\b2\u00103\"\u0004\b4\u00105R.\u0010;\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u000b070/8\u0006@\u0006X\u0086\u000e¢\u0006\u0012\n\u0004\b8\u00101\u001a\u0004\b9\u00103\"\u0004\b:\u00105R\u001f\u0010?\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010<0/8\u0006¢\u0006\f\n\u0004\b=\u00101\u001a\u0004\b>\u00103R\u001f\u0010B\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u000b0/8\u0006¢\u0006\f\n\u0004\b@\u00101\u001a\u0004\bA\u00103R\u001f\u0010F\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010C0/8\u0006¢\u0006\f\n\u0004\bD\u00101\u001a\u0004\bE\u00103R%\u0010J\u001a\u0010\u0012\f\u0012\n G*\u0004\u0018\u00010\u000e0\u000e0/8\u0006¢\u0006\f\n\u0004\bH\u00101\u001a\u0004\bI\u00103R\u001f\u0010M\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u000e0/8\u0006¢\u0006\f\n\u0004\bK\u00101\u001a\u0004\bL\u00103R\u001f\u0010P\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u00060/8\u0006¢\u0006\f\n\u0004\bN\u00101\u001a\u0004\bO\u00103R%\u0010S\u001a\u0010\u0012\f\u0012\n G*\u0004\u0018\u00010\u000e0\u000e0/8\u0006¢\u0006\f\n\u0004\bQ\u00101\u001a\u0004\bR\u00103R\u001d\u0010Y\u001a\b\u0012\u0004\u0012\u00020\u000e0T8\u0006¢\u0006\f\n\u0004\bU\u0010V\u001a\u0004\bW\u0010XR\u0016\u0010\\\u001a\u00020\u00068\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\bZ\u0010[R\u0016\u0010`\u001a\u00020]8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b^\u0010_R\u0016\u0010\u0019\u001a\u00020\u000e8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\ba\u0010R¨\u0006b"}, d2 = {"Lcom/vinfast/companion/core/utils/video/VideoViewModel;", "Lcom/vinfast/companion/core/base/BaseViewModel;", "<init>", "()V", "", "c0", "", "activityOrientation", "N", "(I)V", "Ljava/util/ArrayList;", "Lcom/vinfast/companion/core/utils/video/model/Video;", "Lkotlin/collections/ArrayList;", "lstVideo", "", "isAdd", "g0", "(Ljava/util/ArrayList;Z)V", "indexToStart", "Landroidx/media3/exoplayer/ExoPlayer;", "simplePlayer", "modeRepeat", "O", "(ILandroidx/media3/exoplayer/ExoPlayer;I)V", "L", "isPlayWhenReady", "e0", "(Z)V", "b0", "Landroidx/media3/ui/PlayerView;", "newPlayerView", "f0", "(Landroidx/media3/ui/PlayerView;)V", "currentVideo", "U", "(Lcom/vinfast/companion/core/utils/video/model/Video;)I", "M", "width", "i0", "isGotoChange", "K", "d0", "orientation", "Q", "m", "Landroidx/media3/ui/PlayerView;", "currentPlayerView", "Landroidx/lifecycle/MutableLiveData;", "n", "Landroidx/lifecycle/MutableLiveData;", "W", "()Landroidx/lifecycle/MutableLiveData;", "setPlayer", "(Landroidx/lifecycle/MutableLiveData;)V", "player", "", "o", "getListVideo", "setListVideo", "listVideo", "", "p", "S", "currentVideoRatio", "q", "R", "currentVideoPlaying", "Landroidx/media3/common/PlaybackException;", "r", "V", "playVideoError", "kotlin.jvm.PlatformType", "s", "X", "videoMuteListener", "t", "a0", "isPlaying", "u", "Y", "widthPlayerNormal", "v", "Z", "isChangeModePlayer", "Lcom/vinfast/companion/core/extensions/SingleLiveData;", "w", "Lcom/vinfast/companion/core/extensions/SingleLiveData;", "T", "()Lcom/vinfast/companion/core/extensions/SingleLiveData;", "exitFullScreen", "x", "I", "indexOfVideoPlaying", "", "y", "J", "oldPosition", "z", "core_release"}, k = 1, mv = {2, 2, 0}, xi = 48)
@kotlin.jvm.internal.SourceDebugExtension
public final class VideoViewModel extends com.vinfast.companion.core.base.BaseViewModel {

    /* JADX INFO: renamed from: m, reason: from kotlin metadata */
    private androidx.media3.ui.PlayerView currentPlayerView;

    /* JADX INFO: renamed from: n, reason: from kotlin metadata */
    private androidx.lifecycle.MutableLiveData player = new androidx.lifecycle.MutableLiveData((java.lang.Object) null);

    /* JADX INFO: renamed from: o, reason: from kotlin metadata */
    private androidx.lifecycle.MutableLiveData listVideo = new androidx.lifecycle.MutableLiveData(new java.util.ArrayList());

    /* JADX INFO: renamed from: p, reason: from kotlin metadata */
    private final androidx.lifecycle.MutableLiveData currentVideoRatio = new androidx.lifecycle.MutableLiveData((java.lang.Object) null);

    /* JADX INFO: renamed from: q, reason: from kotlin metadata */
    private final androidx.lifecycle.MutableLiveData currentVideoPlaying = new androidx.lifecycle.MutableLiveData((java.lang.Object) null);

    /* JADX INFO: renamed from: r, reason: from kotlin metadata */
    private final androidx.lifecycle.MutableLiveData playVideoError = new androidx.lifecycle.MutableLiveData((java.lang.Object) null);

    /* JADX INFO: renamed from: s, reason: from kotlin metadata */
    private final androidx.lifecycle.MutableLiveData videoMuteListener;

    /* JADX INFO: renamed from: t, reason: from kotlin metadata */
    private final androidx.lifecycle.MutableLiveData isPlaying;

    /* JADX INFO: renamed from: u, reason: from kotlin metadata */
    private final androidx.lifecycle.MutableLiveData widthPlayerNormal;

    /* JADX INFO: renamed from: v, reason: from kotlin metadata */
    private final androidx.lifecycle.MutableLiveData isChangeModePlayer;

    /* JADX INFO: renamed from: w, reason: from kotlin metadata */
    private final com.vinfast.companion.core.extensions.SingleLiveData exitFullScreen;

    /* JADX INFO: renamed from: x, reason: from kotlin metadata */
    private int indexOfVideoPlaying;

    /* JADX INFO: renamed from: y, reason: from kotlin metadata */
    private long oldPosition;

    /* JADX INFO: renamed from: z, reason: from kotlin metadata */
    private boolean isPlayWhenReady;

    @javax.inject.Inject
    public VideoViewModel() {
        java.lang.Boolean bool = java.lang.Boolean.FALSE;
        this.videoMuteListener = new androidx.lifecycle.MutableLiveData(bool);
        this.isPlaying = new androidx.lifecycle.MutableLiveData((java.lang.Object) null);
        this.widthPlayerNormal = new androidx.lifecycle.MutableLiveData((java.lang.Object) null);
        this.isChangeModePlayer = new androidx.lifecycle.MutableLiveData(bool);
        this.exitFullScreen = new com.vinfast.companion.core.extensions.SingleLiveData();
    }

    private final void N(int activityOrientation) {
        if (activityOrientation != 0 && activityOrientation != 6) {
            this.listVideo.n(new java.util.ArrayList());
            this.currentVideoRatio.n((java.lang.Object) null);
            this.currentVideoPlaying.n((java.lang.Object) null);
            this.playVideoError.n((java.lang.Object) null);
            this.widthPlayerNormal.n((java.lang.Object) null);
            this.videoMuteListener.n(java.lang.Boolean.FALSE);
            this.currentPlayerView = null;
        }
        androidx.media3.exoplayer.ExoPlayer exoPlayer = (androidx.media3.exoplayer.ExoPlayer) this.player.f();
        long jP = exoPlayer != null ? exoPlayer.P() : 0L;
        this.oldPosition = jP;
        timber.log.Timber.a.a("Get current position " + jP, new java.lang.Object[0]);
        this.player.q((java.lang.Object) null);
        androidx.lifecycle.MutableLiveData mutableLiveData = this.isPlaying;
        java.lang.Boolean bool = java.lang.Boolean.FALSE;
        mutableLiveData.n(bool);
        this.isChangeModePlayer.n(bool);
    }

    public static /* synthetic */ void P(com.vinfast.companion.core.utils.video.VideoViewModel videoViewModel, int i, androidx.media3.exoplayer.ExoPlayer exoPlayer, int i2, int i3, java.lang.Object obj) {
        if ((i3 & 1) != 0) {
            i = -1;
        }
        if ((i3 & 4) != 0) {
            i2 = 0;
        }
        videoViewModel.O(i, exoPlayer, i2);
    }

    private final void c0() {
        androidx.media3.exoplayer.ExoPlayer exoPlayer = (androidx.media3.exoplayer.ExoPlayer) this.player.f();
        if (exoPlayer != null) {
            exoPlayer.release();
        }
    }

    public static /* synthetic */ void h0(com.vinfast.companion.core.utils.video.VideoViewModel videoViewModel, java.util.ArrayList arrayList, boolean z, int i, java.lang.Object obj) {
        if ((i & 2) != 0) {
            z = false;
        }
        videoViewModel.g0(arrayList, z);
    }

    public final void K(boolean isGotoChange) {
        this.isChangeModePlayer.n(java.lang.Boolean.valueOf(isGotoChange));
    }

    public final void L() {
        androidx.media3.exoplayer.ExoPlayer exoPlayer = (androidx.media3.exoplayer.ExoPlayer) this.player.f();
        if (kotlin.jvm.internal.Intrinsics.e(exoPlayer != null ? java.lang.Float.valueOf(exoPlayer.o0()) : null, 0.0f)) {
            androidx.media3.exoplayer.ExoPlayer exoPlayer2 = (androidx.media3.exoplayer.ExoPlayer) this.player.f();
            if (exoPlayer2 != null) {
                exoPlayer2.f(1.0f);
            }
            this.videoMuteListener.n(java.lang.Boolean.FALSE);
            return;
        }
        androidx.media3.exoplayer.ExoPlayer exoPlayer3 = (androidx.media3.exoplayer.ExoPlayer) this.player.f();
        if (exoPlayer3 != null) {
            exoPlayer3.f(0.0f);
        }
        this.videoMuteListener.n(java.lang.Boolean.TRUE);
    }

    public final void M() {
        this.playVideoError.n((java.lang.Object) null);
    }

    public final void O(int indexToStart, androidx.media3.exoplayer.ExoPlayer simplePlayer, int modeRepeat) {
        kotlin.jvm.internal.Intrinsics.l(simplePlayer, "simplePlayer");
        this.player.q(simplePlayer);
        androidx.media3.exoplayer.ExoPlayer exoPlayer = (androidx.media3.exoplayer.ExoPlayer) this.player.f();
        if (exoPlayer != null) {
            exoPlayer.e0(new androidx.media3.common.Player.Listener() { // from class: com.vinfast.companion.core.utils.video.VideoViewModel$createPlayer$1$1$1
                public void I(androidx.media3.common.PlaybackException error) {
                    kotlin.jvm.internal.Intrinsics.l(error, "error");
                    timber.log.Timber.a.c("Play video error: " + error, new java.lang.Object[0]);
                    this.a.getPlayVideoError().n(error);
                }

                public void X(boolean isPlaying) {
                    this.a.getIsPlaying().n(java.lang.Boolean.valueOf(isPlaying));
                }

                public void a(androidx.media3.common.VideoSize videoSize) {
                    kotlin.jvm.internal.Intrinsics.l(videoSize, "videoSize");
                    super.a(videoSize);
                    timber.log.Timber.a.a("onVideoSizeChanged " + videoSize.a + " ---- " + videoSize.b, new java.lang.Object[0]);
                    this.a.getCurrentVideoRatio().n(java.lang.Float.valueOf(((float) videoSize.a) / ((float) videoSize.b)));
                }

                public void f0(androidx.media3.common.MediaItem mediaItem, int reason) {
                    if ((mediaItem != null ? mediaItem.b : null) != null) {
                        androidx.media3.common.MediaItem.LocalConfiguration localConfiguration = mediaItem.b;
                        java.lang.Object obj = localConfiguration != null ? localConfiguration.i : null;
                        com.vinfast.companion.core.utils.video.model.Video video = obj instanceof com.vinfast.companion.core.utils.video.model.Video ? (com.vinfast.companion.core.utils.video.model.Video) obj : null;
                        if (video != null) {
                            com.vinfast.companion.core.utils.video.VideoViewModel videoViewModel = this.a;
                            videoViewModel.getCurrentVideoPlaying().n(video);
                            videoViewModel.indexOfVideoPlaying = videoViewModel.U(video);
                        }
                    }
                }
            });
            exoPlayer.setRepeatMode(modeRepeat);
            exoPlayer.C(exoPlayer.p0(), true);
            exoPlayer.c0(true);
            java.util.List<com.vinfast.companion.core.utils.video.model.Video> list = (java.util.List) this.listVideo.f();
            if (list == null || list.isEmpty()) {
                return;
            }
            java.util.ArrayList arrayList = new java.util.ArrayList(kotlin.collections.CollectionsKt.z(list, 10));
            for (com.vinfast.companion.core.utils.video.model.Video video : list) {
                arrayList.add(new androidx.media3.common.MediaItem.Builder().k(video.getUrl()).i(video).a());
            }
            exoPlayer.z0(arrayList);
            if (indexToStart >= 0) {
                this.indexOfVideoPlaying = indexToStart;
            }
            exoPlayer.l0(this.indexOfVideoPlaying, 0L);
            this.currentVideoPlaying.n(list.get(this.indexOfVideoPlaying));
            exoPlayer.prepare();
            exoPlayer.Y(this.isPlayWhenReady);
            timber.log.Timber.a.a("Seek to old position:  " + this.oldPosition, new java.lang.Object[0]);
            exoPlayer.seekTo(this.oldPosition);
            this.oldPosition = 0L;
        }
    }

    public final void Q(int orientation) {
        N(orientation);
        c0();
    }

    /* JADX INFO: renamed from: R, reason: from getter */
    public final androidx.lifecycle.MutableLiveData getCurrentVideoPlaying() {
        return this.currentVideoPlaying;
    }

    /* JADX INFO: renamed from: S, reason: from getter */
    public final androidx.lifecycle.MutableLiveData getCurrentVideoRatio() {
        return this.currentVideoRatio;
    }

    /* JADX INFO: renamed from: T, reason: from getter */
    public final com.vinfast.companion.core.extensions.SingleLiveData getExitFullScreen() {
        return this.exitFullScreen;
    }

    public final int U(com.vinfast.companion.core.utils.video.model.Video currentVideo) {
        kotlin.jvm.internal.Intrinsics.l(currentVideo, "currentVideo");
        java.util.List<com.vinfast.companion.core.utils.video.model.Video> list = (java.util.List) this.listVideo.f();
        if (list != null) {
            for (com.vinfast.companion.core.utils.video.model.Video video : list) {
                if (kotlin.jvm.internal.Intrinsics.g(video.getId(), currentVideo.getId())) {
                    return list.indexOf(video);
                }
            }
        }
        return -1;
    }

    /* JADX INFO: renamed from: V, reason: from getter */
    public final androidx.lifecycle.MutableLiveData getPlayVideoError() {
        return this.playVideoError;
    }

    /* JADX INFO: renamed from: W, reason: from getter */
    public final androidx.lifecycle.MutableLiveData getPlayer() {
        return this.player;
    }

    /* JADX INFO: renamed from: X, reason: from getter */
    public final androidx.lifecycle.MutableLiveData getVideoMuteListener() {
        return this.videoMuteListener;
    }

    /* JADX INFO: renamed from: Y, reason: from getter */
    public final androidx.lifecycle.MutableLiveData getWidthPlayerNormal() {
        return this.widthPlayerNormal;
    }

    /* JADX INFO: renamed from: Z, reason: from getter */
    public final androidx.lifecycle.MutableLiveData getIsChangeModePlayer() {
        return this.isChangeModePlayer;
    }

    /* JADX INFO: renamed from: a0, reason: from getter */
    public final androidx.lifecycle.MutableLiveData getIsPlaying() {
        return this.isPlaying;
    }

    public final void b0() {
        androidx.media3.exoplayer.ExoPlayer exoPlayer = (androidx.media3.exoplayer.ExoPlayer) this.player.f();
        if (exoPlayer != null) {
            exoPlayer.pause();
        }
    }

    public final void d0() {
        this.exitFullScreen.n(java.lang.Boolean.TRUE);
    }

    public final void e0(boolean isPlayWhenReady) {
        this.isPlayWhenReady = isPlayWhenReady;
    }

    public final void f0(androidx.media3.ui.PlayerView newPlayerView) {
        androidx.media3.exoplayer.ExoPlayer exoPlayer = (androidx.media3.exoplayer.ExoPlayer) this.player.f();
        if (exoPlayer != null) {
            androidx.media3.ui.PlayerView.U(exoPlayer, this.currentPlayerView, newPlayerView);
            this.currentPlayerView = newPlayerView;
        }
    }

    public final void g0(java.util.ArrayList lstVideo, boolean isAdd) {
        com.vinfast.companion.core.utils.video.VideoViewModel videoViewModel;
        androidx.media3.exoplayer.ExoPlayer exoPlayer;
        kotlin.jvm.internal.Intrinsics.l(lstVideo, "lstVideo");
        this.listVideo.q(lstVideo);
        com.vinfast.companion.core.utils.video.model.Video video = (com.vinfast.companion.core.utils.video.model.Video) this.currentVideoPlaying.f();
        boolean zA = true;
        if (video == null) {
            androidx.media3.exoplayer.ExoPlayer exoPlayer2 = (androidx.media3.exoplayer.ExoPlayer) this.player.f();
            if (exoPlayer2 != null) {
                videoViewModel = this;
                P(videoViewModel, 0, exoPlayer2, 0, 4, null);
            }
            if (zA || (exoPlayer = (androidx.media3.exoplayer.ExoPlayer) videoViewModel.player.f()) == null) {
            }
            java.util.ArrayList arrayList = new java.util.ArrayList(kotlin.collections.CollectionsKt.z(lstVideo, 10));
            java.util.Iterator it = lstVideo.iterator();
            while (it.hasNext()) {
                com.vinfast.companion.core.utils.video.model.Video video2 = (com.vinfast.companion.core.utils.video.model.Video) it.next();
                arrayList.add(new androidx.media3.common.MediaItem.Builder().k(video2.getUrl()).i(video2).a());
            }
            if (isAdd) {
                exoPlayer.z0(arrayList);
                return;
            }
            exoPlayer.R();
            exoPlayer.z0(arrayList);
            videoViewModel.indexOfVideoPlaying = 0;
            exoPlayer.l0(0, 0L);
            videoViewModel.currentVideoPlaying.n(lstVideo.get(videoViewModel.indexOfVideoPlaying));
            exoPlayer.prepare();
            exoPlayer.Y(videoViewModel.isPlayWhenReady);
            return;
        }
        zA = true ^ com.vinfast.companion.core.utils.video.model.Video.INSTANCE.a(lstVideo, video);
        videoViewModel = this;
        if (zA) {
        }
    }

    public final void i0(int width) {
        this.widthPlayerNormal.n(java.lang.Integer.valueOf(width));
    }
}
