MainActivity.java 3.46 KB
package com.lijinji.call;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.amitshekhar.utils.DatabaseHelper;
import com.lijinji.call.adapter.MenuBean;
import com.lijinji.call.adapter.RecyclerViewAdapter;
import com.lijinji.call.bean.LineBean;
import com.lijinji.call.product.ProductManagerActivity;
import com.lijinji.call.product.ProductTaskActivity;
import com.lijinji.call.util.CommonActivity;
import com.lijinji.call.util.Constant;
import com.lijinji.call.util.DataBaseHelpter;
import com.lijinji.call.util.MenuConstant;
import com.lijinji.call.util.WMSLog;
import com.lijinji.call.util.WMSUtils;

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

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends CommonActivity {


    @BindView(com.lijinji.call.R.id.recycleView)
    RecyclerView recycleView;
    private Context mContext;
    private RecyclerViewAdapter adapter;
    private ArrayList<MenuBean> menuBeans;
    private GridLayoutManager layoutManager;

    @Override
    protected void initActivityOnCreate(Bundle savedInstanceState) {
        super.initActivityOnCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        mContext = this;
        setTitle(this.getString(R.string.please_select_line));
        setBackImageVisible(View.GONE);
        initView();
    }

    private void initView() {
        adapter = new RecyclerViewAdapter(mContext);
        layoutManager = new GridLayoutManager(mContext, 3);
        recycleView.setLayoutManager(layoutManager);
        recycleView.setAdapter(adapter);
        menuBeans = buildMenuBeans();
        if(menuBeans != null) {
            adapter.setList(menuBeans);
        }
        adapter.setOnItemClickListener(listener);
    }

    private ArrayList<MenuBean> buildMenuBeans() {
        ArrayList<MenuBean> sortmenuBeans = new ArrayList<>();
        ArrayList<String> menuList = getLines();
        ArrayList<Drawable> drawableList = MenuConstant.getMenuDrawable(mContext);
        MenuBean menuBean;
        for (int k = 0; k < menuList.size(); k++) {
            menuBean = new MenuBean(drawableList.get(0), menuList.get(k));
            sortmenuBeans.add(menuBean);
        }
        return sortmenuBeans;
    }

    private ArrayList<String> getLines() {
       List<LineBean> lineBeans = DataBaseHelpter.queryAllLine();
       ArrayList<String> lines = new ArrayList<>();
       for(LineBean lineBean : lineBeans) {
           String name = lineBean.getName();
           int type = lineBean.getType();
           if(type == 0) {
               lines.add(name);
           }
       }
       return lines;
    }

    private RecyclerViewAdapter.OnRecyclerViewItemClickListener listener = new RecyclerViewAdapter.OnRecyclerViewItemClickListener() {
        @Override
        public void onItemClick(int position) {
            chooseItemListener(position);
        }
    };

    private void chooseItemListener(int positino) {
        List<LineBean> lineBeans = DataBaseHelpter.queryAllLine();
        WMSUtils.saveData(Constant.CURREN_LINE_NUMBER, String.valueOf(lineBeans.get(positino).getId()));
        WMSUtils.startActivity(mContext, ProductManagerActivity.class);
    }


}