package xyz.stream.view;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Window;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.m3;
import androidx.lifecycle.s0;
import androidx.lifecycle.x0;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Locale;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import v3.a;
import xyz.stream.view.autosize.AutoSize;

/* JADX INFO: loaded from: classes3.dex */
public abstract class BaseActivity<BVM extends s0, VB extends v3.a> extends AppCompatActivity {
    public VB binding;
    public BVM viewModel;

    public static boolean isTranslucentOrFloating(Activity activity) {
        Exception e10;
        boolean zBooleanValue;
        Method method;
        try {
            TypedArray typedArrayObtainStyledAttributes = activity.obtainStyledAttributes((int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null));
            method = ActivityInfo.class.getMethod("isTranslucentOrFloating", TypedArray.class);
            method.setAccessible(true);
            zBooleanValue = ((Boolean) method.invoke(null, typedArrayObtainStyledAttributes)).booleanValue();
        } catch (Exception e11) {
            e10 = e11;
            zBooleanValue = false;
        }
        try {
            method.setAccessible(false);
        } catch (Exception e12) {
            e10 = e12;
            ViewLog.e(e10.getMessage());
        }
        return zBooleanValue;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013 A[Catch: Exception -> 0x001d, TryCatch #0 {Exception -> 0x001d, blocks: (B:4:0x0006, B:6:0x000d, B:8:0x0017, B:7:0x0013), top: B:18:0x0006 }] */
    @Override // androidx.appcompat.app.AppCompatActivity, android.app.Activity, android.view.ContextThemeWrapper, android.content.ContextWrapper
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void attachBaseContext(Context context) {
        Locale locale;
        String language = ViewRuntime.getLanguage();
        if (language != null) {
            try {
                String strSubstring = language.length() >= 2 ? language.substring(0, 2) : ViewRuntime.getDefaultLanguage();
                locale = new Locale(strSubstring);
            } catch (Exception unused) {
                locale = Locale.getDefault();
            }
        }
        try {
            Configuration configuration = new Configuration(context.getResources().getConfiguration());
            configuration.setLocale(locale);
            try {
                super.attachBaseContext(context.createConfigurationContext(configuration));
            } catch (Throwable unused2) {
                super.attachBaseContext(context);
            }
        } catch (Throwable unused3) {
            super.attachBaseContext(context);
        }
    }

    @Override // androidx.appcompat.app.AppCompatActivity, androidx.core.app.ComponentActivity, android.app.Activity, android.view.Window.Callback
    public boolean dispatchKeyEvent(KeyEvent keyEvent) {
        if (keyEvent.getAction() == 0) {
            ViewRuntime.onUserAction();
        }
        return super.dispatchKeyEvent(keyEvent);
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public boolean dispatchTouchEvent(MotionEvent motionEvent) {
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 0 || actionMasked == 1 || actionMasked == 2) {
            ViewRuntime.onUserAction();
        }
        return super.dispatchTouchEvent(motionEvent);
    }

    @Override // androidx.appcompat.app.AppCompatActivity, android.view.ContextThemeWrapper, android.content.ContextWrapper, android.content.Context
    public Resources getResources() {
        if (AutoSize.checkInit()) {
            runOnUiThread(new p000if.e(this, 19));
        }
        return super.getResources();
    }

    public abstract VB getViewBinding();

    public Class<BVM> getViewModelClass() {
        Class<BVM> cls;
        for (Class<?> superclass = getClass(); superclass != null && superclass != Object.class; superclass = superclass.getSuperclass()) {
            Type genericSuperclass = superclass.getGenericSuperclass();
            if (genericSuperclass instanceof ParameterizedType) {
                Type[] actualTypeArguments = ((ParameterizedType) genericSuperclass).getActualTypeArguments();
                if (actualTypeArguments.length > 0) {
                    Type type = actualTypeArguments[0];
                    if (type instanceof Class) {
                        cls = (Class) type;
                        break;
                    }
                    if (type instanceof ParameterizedType) {
                        Type rawType = ((ParameterizedType) type).getRawType();
                        if (rawType instanceof Class) {
                            cls = (Class) rawType;
                            break;
                        }
                    } else {
                        continue;
                    }
                } else {
                    continue;
                }
            }
        }
        cls = null;
        return (cls == null || !s0.class.isAssignableFrom(cls)) ? BaseViewModel.class : cls;
    }

    public void initData() {
    }

    public void initListener() {
    }

    public abstract void initView();

    @Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
    public void onCreate(@Nullable Bundle bundle) {
        if (ViewRuntime.restartIfNeeded(this)) {
            return;
        }
        ViewRuntime.restoreContentDesignSize(this);
        ViewRuntime.setCurrentContentActivity(this);
        onInit();
        Window window = getWindow();
        if (window != null) {
            o6.b.B(window, false);
            eb.e eVar = new m3(window, window.getDecorView()).f1786a;
            eVar.k(false);
            eVar.j(false);
        }
        super.onCreate(bundle);
        ViewRuntime.setCurrentContentActivity(this);
        if (!ViewRuntime.isPhone()) {
            UiUtils.setUpActivity(this, null);
        }
        this.viewModel = (BVM) new x0(this).a(getViewModelClass());
        VB vb2 = (VB) getViewBinding();
        this.binding = vb2;
        setContentView(vb2.getRoot());
        initView();
        initData();
        initListener();
    }

    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        super.onDestroy();
    }

    public void onInit() {
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(Object obj) {
        Class cls = ViewRuntime.f36442h;
        if (ViewRuntime.f36443i != null) {
            if (cls == null || cls.isInstance(obj)) {
                ViewRuntime.f36443i.handle(this, obj);
            }
        }
    }

    @Override // androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onResume() {
        super.onResume();
        UiUtils.adaptActivityDensity(this);
    }

    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onStart() {
        super.onStart();
        fe.d.b().j(this);
    }

    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onStop() {
        super.onStop();
        fe.d.b().m(this);
    }

    public void playReminderLive(Object obj) {
    }

    @Override // android.app.Activity
    public void setRequestedOrientation(int i10) {
        int i11 = Build.VERSION.SDK_INT;
        if (i11 < 36 || ViewRuntime.isPhone()) {
            if (i11 == 26 && isTranslucentOrFloating(this)) {
                return;
            }
            super.setRequestedOrientation(i10);
        }
    }
}
