package com.ygtx.emcs.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.ygtx.emcs.activity.adapter.FunctionMenuAdapter;
import com.ygtx.emcs.activity.model.MainModel;
import com.ygtx.emcs.comm.BaseActivity;
import com.ygtx.emcs.databinding.YgtxFunctionActivyBinding;
import com.ygtx.emcs.util.DataUtil;
import com.ygtx.emcs.util.ToastUtils;

import java.util.ArrayList;


public class FunctionActivity extends BaseActivity {
    private Context context;
    private String title = "";
    private YgtxFunctionActivyBinding binding;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = YgtxFunctionActivyBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        context = this;
        String key = this.getParamString("key");
        title = this.getParamString("title");
        context = this;
        initInfoList(key);
        this.initCommonTop2();
    }

    public void initInfoList(String key){
        ArrayList<MainModel> list = new ArrayList<MainModel>();
        list = DataUtil.getMenus(null);

        final ArrayList<MainModel> ds = list;
        FunctionMenuAdapter mainViewAdapter = new FunctionMenuAdapter(list, this);
        binding.gridView.setAdapter(mainViewAdapter);
        binding.gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                MainModel shop = ds.get(arg2);
                Class actionClass = shop.getActionClass();
                if (actionClass==null){
                    ToastUtils.showToast(context,"正在开发");
                }else{
                    Intent intent = new Intent(context, actionClass);
                    startActivity(intent);
                }
            }
        });
        mainViewAdapter.notifyDataSetChanged();
    }

    public void receiverTask(String barcode){

    }

    @Override
    protected String getCommonTopTitle() {
        return title;
    }

    @Override
    protected int getCommonTopICO() {
        return 0;
    }
}
