MainActivity.java
3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.lijinji.scan;
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.scan.adapter.MenuBean;
import com.lijinji.scan.adapter.RecyclerViewAdapter;
import com.lijinji.scan.bean.LineBean;
import com.lijinji.scan.product.ProductManagerActivity;
import com.lijinji.scan.product.ProductTaskActivity;
import com.lijinji.scan.util.CommonActivity;
import com.lijinji.scan.util.Constant;
import com.lijinji.scan.util.DataBaseHelpter;
import com.lijinji.scan.util.MenuConstant;
import com.lijinji.scan.util.WMSLog;
import com.lijinji.scan.util.WMSUtils;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends CommonActivity {
@BindView(com.lijinji.scan.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);
}
}