SaleInstructionFragment.java
10.1 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package com.bigfish.salecenter.ui.fragment;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import com.badoo.mobile.util.WeakHandler;
import com.bigfish.salecenter.R;
import com.bigfish.salecenter.adapter.CommentAdapter;
import com.bigfish.salecenter.api.SaleService;
import com.bigfish.salecenter.databinding.FragmentSaleInstructionBinding;
import com.bigfish.salecenter.model.CommentBean;
import com.bigfish.salecenter.model.CommentPostData;
import com.bigfish.salecenter.model.ProductDetailBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dayu.base.api.Api;
import com.dayu.base.ui.fragment.BaseFragment;
import com.dayu.base.ui.presenter.SImplePresenter;
import com.dayu.event.UserInfo;
import com.dayu.utils.CommonUtils;
import com.dayu.utils.GlideImageLoader;
import com.dayu.utils.LogUtils;
import com.dayu.utils.ProgressUtil;
import com.dayu.utils.UserManager;
import com.dayu.widgets.KeyboardStateObserver;
import java.util.ArrayList;
import java.util.List;
/**
* Created by mReturn
* on 2020/2/13
**/
public class SaleInstructionFragment extends BaseFragment<SImplePresenter, FragmentSaleInstructionBinding> {
List<String> sceneList = new ArrayList<>();
List<String> pointList = new ArrayList<>();
ProductDetailBean mDetail;
private UserInfo userInfo;
private CommentBean selectedItem;
private int page = 1;
private int pageSize = 2000;
private CommentAdapter mCommentAdapter;
private List<CommentBean> commentList = new ArrayList<>();
private WeakHandler weakHandler = new WeakHandler();
public static SaleInstructionFragment newInstance(ProductDetailBean detail) {
Bundle args = new Bundle();
args.putSerializable("data", detail);
SaleInstructionFragment fragment = new SaleInstructionFragment();
fragment.setArguments(args);
return fragment;
}
@Override
public void setPresenter() {
}
@Override
public int getLayoutId() {
return R.layout.fragment_sale_instruction;
}
@Override
public void initView() {
userInfo = UserManager.getInstance().getUser();
GlideImageLoader.load(mActivity, mBind.ivAvatar, userInfo.getHeaderImg(), R.drawable.icon_user_default);
if (getArguments() != null) {
mDetail = (ProductDetailBean) getArguments().getSerializable("data");
}
initCommentAdapter();
if (mDetail != null) {
initDataView();
initCommentListener();
}
getCommentData();
}
//设置基本信息
private void initDataView() {
mBind.tvBonus.setText(CommonUtils.getMoneyStr(mActivity, mDetail.getSalesPrice()));
mBind.tvFace.setText(mDetail.getCustomerPortrait());
for (int i = 0; i < mDetail.getGoodsCategorys().size(); i++) {
sceneList.add(mDetail.getGoodsCategorys().get(i).getCategoryName());
}
fillPointList(mDetail.getSellingPoint1());
fillPointList(mDetail.getSellingPoint2());
fillPointList(mDetail.getSellingPoint3());
setSceneAdapter();
setPointAdapter();
}
//填充卖点数据
private void fillPointList(String pointStr){
if (!TextUtils.isEmpty(pointStr))
pointList.add(pointStr);
}
//适用场景
private void setSceneAdapter() {
BaseQuickAdapter<String, BaseViewHolder> sceneAdapter =
new BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_product_scene, sceneList) {
@Override
protected void convert(BaseViewHolder helper, String item) {
CheckBox cbScene = helper.getView(R.id.cb_scene);
cbScene.setText(item);
}
};
mBind.rvScene.setLayoutManager(new GridLayoutManager(mActivity, 3));
mBind.rvScene.setAdapter(sceneAdapter);
}
//主打卖点
private void setPointAdapter() {
BaseQuickAdapter<String, BaseViewHolder> pointdapter =
new BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_sale_point, pointList) {
@Override
protected void convert(BaseViewHolder helper, String item) {
helper.setText(R.id.tv_point_item, item);
}
};
mBind.rvSellPoint.setLayoutManager(new GridLayoutManager(mActivity, 3));
mBind.rvSellPoint.setAdapter(pointdapter);
}
private void initCommentAdapter() {
mCommentAdapter = new CommentAdapter(false);
mCommentAdapter.setViewType(R.layout.item_sale_comment);
mCommentAdapter.setData(commentList);
mBind.rvComponent.setLayoutManager(new LinearLayoutManager(mActivity));
mBind.rvComponent.setAdapter(mCommentAdapter);
mCommentAdapter.setLoadMore(true);
mBind.rvComponent.setNestedScrollingEnabled(false);
}
@SuppressLint("ClickableViewAccessibility")
private void initCommentListener() {
KeyboardStateObserver.getKeyboardStateObserver(mActivity).setKeyboardVisibilityListener(
new KeyboardStateObserver.OnKeyboardVisibilityListener() {
@Override
public void onKeyboardShow() {
mBind.btnComment.setVisibility(View.GONE);
}
@Override
public void onKeyboardHide() {
weakHandler.postDelayed(() -> {
mBind.btnComment.setVisibility(View.VISIBLE);
}, 100);
}
});
mBind.nsvOperate.setOnTouchListener((view, motionEvent) -> {
CommonUtils.hideSoftInput(mActivity, mBind.edtComment);
return false;
});
//发送
mBind.btnSend.setOnClickListener(v -> {
String content = mBind.edtComment.getText().toString();
if (TextUtils.isEmpty(content)) return;
ProgressUtil.startLoad(mActivity);
CommentPostData commentData = new CommentPostData();
commentData.targetId = mDetail.getId();
commentData.targetName = mDetail.getGoodsModel();
commentData.accountId = Integer.parseInt(userInfo.getAccountId());
commentData.accountName = userInfo.getAccountName();
commentData.messageAvatarUrl = userInfo.getHeaderImg();
commentData.content = content;
commentData.updated = userInfo.getAccountName();
if (selectedItem == null) {
commentData.messageType = 1;
} else {
commentData.messageType = 2;
commentData.beAccountId = selectedItem.getAccountId();
commentData.beName = selectedItem.getAccountName();
commentData.beMessageId = selectedItem.getId();
if (commentData.parentId > 0) {
commentData.parentId = selectedItem.getParentId();
} else {
commentData.parentId = selectedItem.getId();
}
}
Api.getService(SaleService.class).addComment(commentData).compose(Api.applySchedulers())
.subscribe(mPresenter.baseObserver(result -> {
if (result)
getCommentData();
}));
selectedItem = null;
mBind.edtComment.setText("");
CommonUtils.hideSoftInput(mActivity, mBind.edtComment);
});
mBind.btnComment.setOnClickListener(v -> {
selectedItem = null;
mBind.edtComment.setText("");
mBind.edtComment.requestFocus();
CommonUtils.ShowSoftInput(mActivity, mBind.edtComment);
});
mCommentAdapter.setOnItemClickListener((item, bind) -> {
selectedItem = item;
mBind.edtComment.setText("");
mBind.edtComment.requestFocus();
CommonUtils.ShowSoftInput(mActivity, mBind.edtComment);
});
}
private void getCommentData() {
showDialog();
Api.getService(SaleService.class).getComment(mDetail.getId(), 1, 4, 1, page, pageSize).compose(Api.applySchedulers())
.subscribe(mPresenter.baseObserver(data -> {
if (page == 1) {
commentList.clear();
}
// commentList = transData(data.getData());
commentList = data.getData();
mBind.tvComponent.setText("留言. " + commentList.size());
mCommentAdapter.setData(commentList);
}));
}
//转换评论数据
private List<CommentBean> transData(List<CommentBean> datas) {
List<CommentBean> tempList = new ArrayList<>();
for (int i = 0; i < datas.size(); i++) {
CommentBean cData = datas.get(i);
if (cData.getMessageType() == 1) {
if (!tempList.contains(cData))
tempList.add(cData);
} else {
int parentId = cData.getParentId();
for (int j = 0; j < datas.size(); j++) {
CommentBean cData2 = datas.get(j);
if (cData2.getId() == parentId) {
if (!tempList.contains(cData2)) {
tempList.add(cData2);
if (!tempList.contains(cData))
if (!tempList.contains(cData))
tempList.add(tempList.indexOf(cData2) + 1, cData);
} else if (!tempList.contains(cData)) {
tempList.add(tempList.indexOf(cData2) + 1, cData);
}
} else if (!tempList.contains(cData2)) {
tempList.add(cData2);
}
}
}
}
return tempList;
}
}