package com.live.mylivewallpaper.activity;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.live.mylivewallpaper.R;
import com.live.mylivewallpaper.adapter.VpAdapter;
import com.live.mylivewallpaper.base.BaseActivity;
import com.live.mylivewallpaper.databinding.ActivityMainBinding;
import com.live.mylivewallpaper.databinding.ItemTabBinding;
import com.live.mylivewallpaper.fragment.LikeFragment;
import com.live.mylivewallpaper.fragment.MainFragment;
import com.live.mylivewallpaper.topon.AdManager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity<ActivityMainBinding> {


    @Override
    protected ActivityMainBinding getViewBinding() {
        return ActivityMainBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void onCreateInit() {
        AdManager.loadAllAd();
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(MainFragment.newInstance(0));
        fragmentList.add(MainFragment.newInstance(3));
        fragmentList.add(MainFragment.newInstance(2));
        fragmentList.add(LikeFragment.newInstance());

        VpAdapter adapter = new VpAdapter(this, fragmentList);
        vb.vp.setAdapter(adapter);
        new TabLayoutMediator(vb.tab, vb.vp, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                ItemTabBinding inflate = ItemTabBinding.inflate(getLayoutInflater());
                tab.setCustomView(inflate.getRoot());
                switch (position) {
                    case 0:
                        inflate.tabTitle.setText(ContextCompat.getString(MainActivity.this, R.string.tab_title_1));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.tab_trending));
                        break;
                    case 1:
                        inflate.tabTitle.setText(ContextCompat.getString(MainActivity.this, R.string.tab_title_2));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.tab_explore));
                        break;
                    case 2:
                        inflate.tabTitle.setText(ContextCompat.getString(MainActivity.this, R.string.tab_title_3));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.tab_shift));
                        break;
                    case 3:
                        inflate.tabTitle.setText(ContextCompat.getString(MainActivity.this, R.string.tab_title_4));
                        inflate.tabIm.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.tab_like));
                        break;
                }
            }
        }).attach();
    }

    @Override
    protected void onInitClick() {

    }

    @Override
    public boolean isFullScreen() {
        return true;
    }

    @Override
    public boolean statusBarLight() {
        return true;
    }

    @Override
    public void onClick(View v) {

    }
}