package com.offline.music.player.ui.activity;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.viewbinding.ViewBinding;

import com.offline.music.player.databinding.ActivityBaseBinding;

public abstract class BaseActivity<T extends ViewBinding> extends AppCompatActivity implements View.OnClickListener {

//    private final ViewModelScope mViewModelScope = new ViewModelScope();

    protected T vb;

    private Window window;
    private View decorView;
    protected View mView;
    private ActivityBaseBinding rootVb;

//    protected VMApplication vmApplication;
//    protected MyMediaControllerManager mediaControllerManager;

    private Handler mHandler;
    private Runnable mRunnable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = getViewBinding();
        View root = vb.getRoot();
        rootVb = ActivityBaseBinding.inflate(getLayoutInflater(), null, false);
        rootVb.frameLayout.addView(root);
        setContentView(rootVb.getRoot());
        window = getWindow();
        decorView = window.getDecorView();
        mView = decorView.getRootView();
//        vmApplication = getApplicationScopeViewModel(VMApplication.class);
//        mediaControllerManager = MyMediaControllerManager.getInstance();


        setStatusBar();
        if (isFullScreen()) {
//            ImmersionBar.with(this).init();//设置沉浸式效果
//            ImmersionBar.setStatusBarView(this,0);
            initFullScreen();
        }
        onCreateInit();
        onInitClick();
    }

    protected abstract T getViewBinding();


    protected abstract void onCreateInit();

    protected abstract void onInitClick();

    public abstract boolean isFullScreen();

    public abstract boolean statusBarLight();

    public abstract boolean showPanel();








    private void setStatusBar() {
        //深色模式
        WindowInsetsControllerCompat insetsController = WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
        insetsController.setAppearanceLightStatusBars(statusBarLight());
    }

    private void initFullScreen() {
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//        mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
        mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }

//    protected <K extends ViewModel> K getActivityScopeViewModel(@NonNull Class<K> modelClass) {
//        return mViewModelScope.getActivityScopeViewModel(this, modelClass);
//    }
//
//    protected <K extends ViewModel> K getApplicationScopeViewModel(@NonNull Class<K> modelClass) {
//        return mViewModelScope.getApplicationScopeViewModel(modelClass);
//    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mHandler != null && mRunnable != null)
            mHandler.removeCallbacks(mRunnable);
    }
}