SettingFragment.java
5.32 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package com.huaheng.wms.fragment;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.huaheng.wms.LoginActivity;
import com.huaheng.wms.MainActivity;
import com.huaheng.wms.R;
import com.huaheng.wms.download.DownloadUtils;
import com.huaheng.wms.https.HttpInterface;
import com.huaheng.wms.util.Constant;
import com.huaheng.wms.util.MenuLayout;
import com.huaheng.wms.util.WMSUtils;
import com.huaheng.wms.work.login.CompanyInfo;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import rx.Subscriber;
public class SettingFragment extends BaseFragment {
@BindView(R.id.exitLayout)
MenuLayout exitLayout;
@BindView(R.id.upgradeLayout)
MenuLayout upgradeLayout;
@BindView(R.id.versionLayout)
MenuLayout versionLayout;
Unbinder unbinder;
@BindView(R.id.warehouseLayout)
MenuLayout warehouseLayout;
@BindView(R.id.companyLayout)
MenuLayout companyLayout;
private String[] companyCodes;
private int[] companyIds;
private boolean isDownloading = false;
@Override
public View layout(LayoutInflater inflater) {
View view = inflater.inflate(R.layout.fragment_settings, null);
return view;
}
@Override
public void releaseMemory() {
}
@Override
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
isDownloading = false;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO: inflate a fragment view
View rootView = super.onCreateView(inflater, container, savedInstanceState);
unbinder = ButterKnife.bind(this, rootView);
upgradeLayout.setMenuTitle(getString(R.string.upgrade));
upgradeLayout.setIconVisible(View.VISIBLE);
versionLayout.setMenuTitle(getString(R.string.version));
versionLayout.setMenuContent(WMSUtils.getVersionName());
exitLayout.setMenuTitle(getString(R.string.exit));
exitLayout.setIconVisible(View.VISIBLE);
warehouseLayout.setMenuTitle(getString(R.string.current_warehouse));
warehouseLayout.setMenuContent(WMSUtils.getData(Constant.CURREN_WAREHOUSE));
companyLayout.setMenuTitle(getString(R.string.current_company));
companyLayout.setMenuContent(WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE));
getCompanyInfo();
return rootView;
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
@OnClick({R.id.exitLayout, R.id.upgradeLayout, R.id.versionLayout, R.id.companyLayout})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.exitLayout:
getActivity().finish();
WMSUtils.startActivity(getContext(), LoginActivity.class);
break;
case R.id.companyLayout:
showListDialog();
break;
case R.id.upgradeLayout:
if(!isDownloading) {
DownloadUtils.as(getContext()).startDownload();
isDownloading = true;
}
break;
case R.id.versionLayout:
break;
}
}
private void showListDialog() {
if(companyCodes == null) {
WMSUtils.showShort(getContext().getString(R.string.choose_current_company_error));
}
AlertDialog.Builder listDialog =
new AlertDialog.Builder(getContext());
listDialog.setTitle(getContext().getString(R.string.enter_current_company));
listDialog.setItems(companyCodes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String currentCompany = companyCodes[which];
int currentId = companyIds[which];
WMSUtils.saveData(Constant.CURREN_COMPANY_CODE, currentCompany);
WMSUtils.saveData(Constant.CURREN_COMPANY_ID, String.valueOf(currentId));
companyLayout.setMenuContent(WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE));
}
});
listDialog.show();
}
private void getCompanyInfo() {
// HttpInterface.getInsstance().getCompanyInfo(new ProgressSubscriber<List<CompanyInfo>>(getContext(), getCompanyInfoListener));
HttpInterface.getInsstance().getCompanyInfo(new Subscriber<List<CompanyInfo>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(List<CompanyInfo> companyInfos) {
companyCodes = new String[companyInfos.size()];
companyIds = new int[companyInfos.size()];
for(int i=0; i < companyInfos.size(); i++) {
companyCodes[i] = companyInfos.get(i).getCompanyCode();
companyIds[i] = companyInfos.get(i).getCompanyId();
}
}
});
}
}