package xn.hxp.ui.main;

import android.content.Intent;
import android.content.IntentFilter;
import android.view.View;

import androidx.viewbinding.ViewBinding;

import com.blankj.utilcode.util.ActivityUtils;

import xn.hxp.base.BaseActivity;
import xn.hxp.databinding.ActivityMainBinding;
import xn.hxp.databinding.IncludeMainLBinding;
import xn.hxp.databinding.IncludeMainRBinding;
import xn.hxp.receiver.MinuteTickReceiver;
import xn.hxp.ui.start.SettingActivity;

public class MainActivity extends BaseActivity {

    private ActivityMainBinding binding;
    private MainActivityLHelper mainActivityLHelper;
    private MainActivityRHelper mainActivityRHelper;
    private MainActivityTitleHelper mainActivityTitleHelper;

    private MinuteTickReceiver minuteTickReceiver;

    @Override
    protected ViewBinding setViewBinding() {
        return binding = ActivityMainBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void onInit() {
        mainActivityLHelper = new MainActivityLHelper(this, binding.includeL);
        mainActivityRHelper = new MainActivityRHelper(this, binding.includeR);
        mainActivityTitleHelper = new MainActivityTitleHelper(this, binding.includeTitle);

        // 进入配置页面
        binding.includeTitle.titlePic.setOnLongClickListener(v -> {
            ActivityUtils.startActivity(SettingActivity.class);
            return true;
        });

        // 注册分钟广播
        IntentFilter filter = new IntentFilter(Intent.ACTION_TIME_TICK);
        minuteTickReceiver = new MinuteTickReceiver();
        registerReceiver(minuteTickReceiver, filter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 解绑分钟广播
        if (minuteTickReceiver != null) {
            unregisterReceiver(minuteTickReceiver);
        }
    }

    @Override
    protected void cdFinish() {

    }

    @Override
    protected void cdTime(int cd) {

    }
}