package com.ifpdos.videopresenter.e;

import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.util.Log;
import android.view.TextureView;
import b.b.a.c;
import b.b.a.f.f;
import com.ifpdos.videopresenter.b.l;
import com.ifpdos.videopresenter.b.m;
import com.ifpdos.videopresenter.view.gestureview.a;
import java.io.IOException;
import org.greenrobot.eventbus.ThreadMode;
import org.greenrobot.eventbus.j;

/* JADX INFO: compiled from: PresenterTextureModel.java */
/* JADX INFO: loaded from: classes.dex */
public class b implements TextureView.SurfaceTextureListener {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private com.ifpdos.videopresenter.view.gestureview.a f2384a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private b.b.a.c f2385b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private Camera f2386c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private boolean f2387d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private SurfaceTexture f2388e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private Runnable f2389f = new a();

    /* JADX INFO: compiled from: PresenterTextureModel.java */
    class a implements Runnable {
        a() {
        }

        @Override // java.lang.Runnable
        public void run() {
            if (b.this.f2387d) {
                return;
            }
            b.this.f2387d = true;
            b.this.f2384a.setAlpha(1.0f);
        }
    }

    /* JADX INFO: renamed from: com.ifpdos.videopresenter.e.b$b, reason: collision with other inner class name */
    /* JADX INFO: compiled from: PresenterTextureModel.java */
    static /* synthetic */ class C0081b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        static final /* synthetic */ int[] f2391a;

        static {
            int[] iArr = new int[f.EnumC0033f.values().length];
            f2391a = iArr;
            try {
                iArr[f.EnumC0033f.OPENED.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f2391a[f.EnumC0033f.PREVIEWING.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f2391a[f.EnumC0033f.CLOSED.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                f2391a[f.EnumC0033f.DISMOUNTED.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                f2391a[f.EnumC0033f.MOUNTED.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
        }
    }

    private void e() {
        g();
        if (f(this.f2388e)) {
            b.b.a.c.g().f().w();
        }
    }

    private boolean f(SurfaceTexture surfaceTexture) {
        b.b.a.c cVar = this.f2385b;
        if (cVar == null || surfaceTexture == null) {
            return false;
        }
        Camera cameraA = cVar.a();
        this.f2386c = cameraA;
        if (cameraA != null) {
            try {
                cameraA.setPreviewTexture(surfaceTexture);
                return true;
            } catch (IOException e2) {
                b.c.c.l.b.b("PresenterTextureModel", e2);
            }
        }
        return false;
    }

    private void g() {
        this.f2384a.setAlpha(0.0f);
        this.f2387d = false;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: h, reason: merged with bridge method [inline-methods] */
    public /* synthetic */ void i() {
        this.f2384a.setVisibility(0);
    }

    private void j() {
        if (this.f2386c != null) {
            this.f2385b.l();
            this.f2386c = null;
        }
    }

    public void d(com.ifpdos.videopresenter.view.gestureview.a aVar) {
        if (!org.greenrobot.eventbus.c.c().h(this)) {
            org.greenrobot.eventbus.c.c().o(this);
        }
        this.f2385b = b.b.a.c.g();
        this.f2384a = aVar;
        aVar.setSurfaceTextureListener(this);
    }

    public void k() {
        if (org.greenrobot.eventbus.c.c().h(this)) {
            org.greenrobot.eventbus.c.c().q(this);
        }
        j();
        this.f2385b = null;
    }

    @j(threadMode = ThreadMode.MAIN)
    public void onCameraStatusChanged(m mVar) {
        int i = C0081b.f2391a[mVar.f2372a.ordinal()];
        if (i == 1) {
            this.f2384a.c(a.b.CENTER_INSIDE);
            return;
        }
        if (i == 2) {
            this.f2384a.postDelayed(this.f2389f, 500L);
            return;
        }
        if (i == 3) {
            g();
            return;
        }
        if (i == 4) {
            g();
            this.f2386c = null;
        } else {
            if (i != 5) {
                return;
            }
            e();
        }
    }

    @j(threadMode = ThreadMode.MAIN)
    public void onModelEvent(com.ifpdos.videopresenter.b.j jVar) {
        if (jVar.f2370a == c.a.NO_CAMERA) {
            g();
        }
    }

    @j(threadMode = ThreadMode.MAIN)
    public void onSlotEvnet(l lVar) {
        if (lVar.f2371a == f.b.PARAMS_CHANGED) {
            g();
            if (f(this.f2388e)) {
                b.b.a.c.g().f().w();
            }
        }
    }

    @Override // android.view.TextureView.SurfaceTextureListener
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
        b.b.a.c cVar;
        this.f2384a.d(i, i2);
        Log.d("PresenterTextureModel", "onSurfaceTextureAvailable");
        this.f2388e = surfaceTexture;
        if (!f(surfaceTexture) || (cVar = this.f2385b) == null || cVar.f() == null) {
            return;
        }
        this.f2385b.f().w();
    }

    @Override // android.view.TextureView.SurfaceTextureListener
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        Log.d("PresenterTextureModel", "onSurfaceTextureDestroyed");
        j();
        this.f2388e = null;
        return false;
    }

    @Override // android.view.TextureView.SurfaceTextureListener
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
        this.f2384a.setVisibility(4);
        this.f2384a.d(i, i2);
        this.f2384a.c(a.b.CENTER_INSIDE);
        this.f2384a.postDelayed(new Runnable() { // from class: com.ifpdos.videopresenter.e.a
            @Override // java.lang.Runnable
            public final void run() {
                this.f2383c.i();
            }
        }, 500L);
    }

    @Override // android.view.TextureView.SurfaceTextureListener
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
    }
}
