package com.tofly.ghrq_route.common.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.widget.Toolbar;

import com.tofly.ghrq_route.R;
import com.tofly.ghrq_route.base.BaseApp;
import com.tofly.ghrq_route.base.ui.BaseUi;
import com.tofly.ghrq_route.common.ui.adapter.BigImageAdapter;
import com.tofly.ghrq_route.common.ui.view.BigImageViewPager;
import com.tofly.ghrq_route.common.ui.view.IconPageIndicator;
import com.tofly.ghrq_route.common.util.image.ImageUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zombiexq on 2016/6/29.
 */
public class UiBigImageList extends BaseUi {
    @BindView(R.id.view_pager)
    BigImageViewPager viewPager;
    @BindView(R.id.ipi_labels)
    IconPageIndicator ipiLabels;

    private List<String> pictures;
    private BigImageAdapter bigImageAdapter = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.ui_bigimage_list);
        ButterKnife.bind(this);

        initView();
        initData();
        initListener();
    }

    private void initView() {
        Toolbar toolbar = getToolbar();
        if (toolbar != null) {
            toolbar.setTitle("");
        }
    }

    private void initData() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        if (bundle != null){
            pictures = bundle.getStringArrayList(ImageUtil.PICS_PATH_KEY);
            if (pictures != null && pictures.size() > 0){
                bigImageAdapter = new BigImageAdapter(this, pictures, viewPager);
                viewPager.setAdapter(bigImageAdapter);
                if (pictures.size() > 1){
                    ipiLabels.setVisibility(View.VISIBLE);
                    ipiLabels.setViewPager(viewPager);
                    ipiLabels.setItemSpace(BaseApp.dip2px(15));

                    if (bundle.containsKey(ImageUtil.CURRENT_PATH_KEY)){
                        String current_path = bundle.getString(ImageUtil.CURRENT_PATH_KEY);
                        if (current_path != null && !current_path.isEmpty()){
                            int index = pictures.indexOf(current_path);
                            if (index != -1 && index < bigImageAdapter.getCount()){
                                ipiLabels.setCurrentItem(index);
                            }
                        }
                    }
                }
            }
        }
    }

    private void initListener() {

    }

    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        init();
    }

    private void init() {


    }
}
