Skip to content

Commit 42ceb5c

Browse files
author
aaron
committed
修复添加任务后数量没有刷新的 bug
1 parent 146f8c8 commit 42ceb5c

File tree

8 files changed

+239
-31
lines changed

8 files changed

+239
-31
lines changed

app/src/main/java/net/coding/program/project/ProjectFragment.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ public void onRefresh() {
133133
getNetwork(host, host);
134134
}
135135

136-
@Override
137-
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
138-
if (type != Type.Main && type != Type.Create) {
139-
inflater.inflate(R.menu.menu_project_pick_search, menu);
140-
}
141-
142-
super.onCreateOptionsMenu(menu, inflater);
143-
}
136+
// @Override
137+
// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
138+
// if (type != Type.Main && type != Type.Create) {
139+
// inflater.inflate(R.menu.menu_project_pick_search, menu);
140+
// }
141+
//
142+
// super.onCreateOptionsMenu(menu, inflater);
143+
// }
144144

145145
void action_filter() {
146146
if (pageIndex != program_title.length) {

app/src/main/java/net/coding/program/project/detail/ProjectTaskFragment.java

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import net.coding.program.common.ListModify;
2222
import net.coding.program.common.PinyinComparator;
2323
import net.coding.program.common.event.EventRefreshTask;
24+
import net.coding.program.common.event.EventRequestTaskCount;
25+
import net.coding.program.common.event.EventUpdateTaskCount;
2426
import net.coding.program.common.model.AccountInfo;
2527
import net.coding.program.common.model.ProjectObject;
2628
import net.coding.program.common.model.ProjectTaskCountModel;
@@ -43,6 +45,8 @@
4345
import org.androidannotations.annotations.OptionsMenu;
4446
import org.androidannotations.annotations.ViewById;
4547
import org.greenrobot.eventbus.EventBus;
48+
import org.greenrobot.eventbus.Subscribe;
49+
import org.greenrobot.eventbus.ThreadMode;
4650
import org.json.JSONArray;
4751
import org.json.JSONException;
4852
import org.json.JSONObject;
@@ -56,6 +60,12 @@ public class ProjectTaskFragment extends TaskFilterFragment {
5660

5761
final String HOST_MEMBERS = Global.HOST_API + "/project/%d/members?pageSize=1000";
5862

63+
private static final String TAG_PROJECT_TASK_COUNT = "TAG_PROJECT_TASK_COUNT";
64+
private static final String TAG_ALL_COUNT = "TAG_ALL_COUNT";
65+
private static final String TAG_WATCH_COUNT = "TAG_WATCH_COUNT";
66+
private static final String TAG_SOME_COUNT = "TAG_SOME_COUNT";
67+
private static final String TAG_SOME_LABEL = "TAG_SOME_LABEL";
68+
5969
@FragmentArg
6070
ProjectObject mProjectObject;
6171

@@ -112,6 +122,7 @@ protected void initFilterViews() {
112122
if (toolBarTitle != null) {
113123
toolBarTitle.setOnClickListener(v -> {
114124
meActionFilter();
125+
loadDataCount();
115126
});
116127
toolBarTitle.setBackgroundResource(0);
117128
Drawable drawable = getResources().getDrawable(R.drawable.arrow_drop_down_green);
@@ -121,7 +132,6 @@ protected void initFilterViews() {
121132
toolBarTitle.setText("全部任务");
122133
}
123134

124-
125135
loadData(0);
126136
}
127137

@@ -151,6 +161,31 @@ private void loadData(int index) {
151161
}
152162
}
153163

164+
@Subscribe(threadMode = ThreadMode.MAIN)
165+
public void onEventRequestTaskCount(EventRequestTaskCount event) {
166+
if (getActivity() == null) return;
167+
168+
loadDataCount();
169+
}
170+
171+
private void loadDataCount() {
172+
mTaskProjectCountModel = new TaskProjectCountModel();
173+
int index = pager.getCurrentItem();
174+
if (index == 0) {
175+
//全部成员
176+
//「全部任务」数量 - 进行中,已完成的 「我创建的」数量 = create
177+
getNetwork(String.format(urlProjectTaskCount, mProjectObject.getId()), TAG_PROJECT_TASK_COUNT);
178+
getNetwork(String.format(urlALL_Count, mProjectObject.getId()), TAG_ALL_COUNT);
179+
getNetwork(String.format(urlALL_WATCH_Count, mProjectObject.getId(), account.id), TAG_WATCH_COUNT);
180+
181+
} else {
182+
Member members = mMembersAll.get(index);
183+
184+
//某个成员
185+
getNetwork(String.format(urlSome_Count, mProjectObject.getId(), members.user_id), TAG_SOME_COUNT);
186+
}
187+
}
188+
154189
private void loadAllLabels() {
155190
// int cur = tabs.getCurrentPosition();
156191
int cur = pager.getCurrentItem();
@@ -296,11 +331,64 @@ public void parseJson(int code, JSONObject respanse, String tag, int pos, Object
296331
} else {
297332
showErrorMsg(code, respanse);
298333
}
334+
} else if (tag.equals(TAG_PROJECT_TASK_COUNT)) {
335+
if (code == 0) {
336+
TaskProjectCountModel projectTaskCountModel = JSONUtils.getData(respanse.getString("data"), TaskProjectCountModel.class);
337+
mTaskProjectCountModel.creatorDone = projectTaskCountModel.creatorDone;
338+
mTaskProjectCountModel.creatorProcessing = projectTaskCountModel.creatorProcessing;
339+
mTaskProjectCountModel.watcherDone = projectTaskCountModel.watcherDone;
340+
mTaskProjectCountModel.watcherProcessing = projectTaskCountModel.watcherProcessing;
341+
} else {
342+
showErrorMsg(code, respanse);
343+
}
344+
} else if (tag.equals(TAG_ALL_COUNT)) {
345+
if (code == 0) {
346+
ProjectTaskCountModel projectTaskCountModel = JSONUtils.getData(respanse.getString("data"), ProjectTaskCountModel.class);
347+
mTaskProjectCountModel.owner = projectTaskCountModel.done + projectTaskCountModel.processing;
348+
mTaskProjectCountModel.ownerDone = projectTaskCountModel.done;
349+
mTaskProjectCountModel.ownerProcessing = projectTaskCountModel.processing;
350+
mTaskProjectCountModel.creator = projectTaskCountModel.create;
351+
postEventUpdateCount();
352+
} else {
353+
showErrorMsg(code, respanse);
354+
}
355+
} else if (tag.equals(TAG_WATCH_COUNT)) {
356+
if (code == 0) {
357+
mTaskProjectCountModel.watcher = JSONUtils.getJSONLong("totalRow", respanse.getString("data"));
358+
postEventUpdateCount();
359+
} else {
360+
showErrorMsg(code, respanse);
361+
}
362+
} else if (tag.equals(TAG_SOME_COUNT)) {
363+
if (code == 0) {
364+
ProjectTaskUserCountModel item = JSONUtils.getData(respanse.getString("data"), ProjectTaskUserCountModel.class);
365+
366+
mTaskProjectCountModel.owner = item.memberDone + item.memberProcessing;
367+
mTaskProjectCountModel.ownerDone = item.memberDone;
368+
mTaskProjectCountModel.ownerProcessing = item.memberProcessing;
369+
370+
mTaskProjectCountModel.creatorDone = item.creatorDone;
371+
mTaskProjectCountModel.creator = item.creatorDone + item.creatorProcessing;
372+
mTaskProjectCountModel.creatorProcessing = item.creatorProcessing;
373+
374+
mTaskProjectCountModel.watcher = item.watcherDone + item.watcherProcessing;
375+
mTaskProjectCountModel.watcherDone = item.watcherDone;
376+
mTaskProjectCountModel.watcherProcessing = item.watcherProcessing;
377+
378+
postEventUpdateCount();
379+
} else {
380+
showErrorMsg(code, respanse);
381+
}
299382
}
383+
300384
//设置DrawerLayout的数据
301385
setDrawerData();
302386
}
303387

388+
private void postEventUpdateCount() {
389+
EventBus.getDefault().post(new EventUpdateTaskCount());
390+
}
391+
304392
@OnActivityResult(ListModify.RESULT_EDIT_LIST)
305393
void onResultEditList(int resultCode, Intent data) {
306394
if (resultCode == Activity.RESULT_OK) {

app/src/main/java/net/coding/program/project/detail/TaskFilterFragment.java

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
import net.coding.program.common.FilterListener;
1212
import net.coding.program.common.Global;
1313
import net.coding.program.common.event.EventFilterDetail;
14+
import net.coding.program.common.event.EventUpdateTaskCount;
1415
import net.coding.program.common.model.FilterModel;
1516
import net.coding.program.common.model.TaskLabelModel;
1617
import net.coding.program.common.model.TaskProjectCountModel;
1718
import net.coding.program.common.network.LoadingFragment;
1819

1920
import org.greenrobot.eventbus.EventBus;
21+
import org.greenrobot.eventbus.Subscribe;
22+
import org.greenrobot.eventbus.ThreadMode;
2023

2124
import java.util.ArrayList;
2225
import java.util.List;
@@ -87,7 +90,8 @@ private void iniTaskStatusLayout() {
8790
if (getActivity() == null) return;
8891

8992
View viewById = getActivity().findViewById(R.id.ll_task_filter);
90-
viewById.setVisibility(viewById.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
93+
boolean needHide = viewById.getVisibility() == View.VISIBLE;
94+
viewById.setVisibility(needHide ? View.GONE : View.VISIBLE);
9195
}
9296

9397
private void iniTaskStatus() {
@@ -100,14 +104,6 @@ private void iniTaskStatus() {
100104
"我关注的",
101105
"我创建的"
102106
};
103-
//
104-
// if (mTaskCountModel != null) {
105-
// filterTxtCount = new String[]{
106-
// String.format(" (%s)", mTaskCountModel.processing + mTaskCountModel.done),
107-
// String.format(" (%s)", mTaskCountModel.watchAll),
108-
// String.format(" (%s)", mTaskCountModel.create)
109-
// };
110-
// }
111107

112108
if (mTaskProjectCountModel != null) {
113109
filterTxtCount = new String[]{
@@ -210,6 +206,41 @@ public void onRefresh() {
210206

211207
}
212208

209+
@Subscribe(threadMode = ThreadMode.MAIN)
210+
public void onEventUpdateCount(EventUpdateTaskCount event) {
211+
if (getActivity() == null) return;
212+
213+
int[] filterItem = {R.id.tv_status1, R.id.tv_status2, R.id.tv_status3};
214+
String[] filterTxtCount = new String[0];
215+
String[] filterTxt = new String[]{
216+
isProjectInner() ? "全部任务" : "我的任务",
217+
"我关注的",
218+
"我创建的"
219+
};
220+
221+
if (mTaskProjectCountModel != null) {
222+
filterTxtCount = new String[]{
223+
String.format(" (%s)", mTaskProjectCountModel.owner),
224+
String.format(" (%s)", mTaskProjectCountModel.watcher),
225+
String.format(" (%s)", mTaskProjectCountModel.creator)
226+
};
227+
}
228+
229+
for (int i = 0; i < filterItem.length; i++) {
230+
TextView status = getActivity().findViewById(filterItem[i]);
231+
if (filterTxtCount.length == 3) {
232+
status.setText(filterTxt[i] + filterTxtCount[i]);
233+
} else {
234+
status.setText(filterTxt[i]);
235+
}
236+
}
237+
}
238+
239+
@Override
240+
protected boolean useEventBus() {
241+
return true;
242+
}
243+
213244
protected boolean isProjectInner() {
214245
return false;
215246
}

0 commit comments

Comments
 (0)