Skip to content

Commit 9555da6

Browse files
committed
项目内筛选
1 parent fdc597c commit 9555da6

File tree

9 files changed

+213
-23
lines changed

9 files changed

+213
-23
lines changed

app/src/main/java/net/coding/program/common/DrawerLayoutHelper.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class DrawerLayoutHelper {
3434
private FilterModel mFilterModel;
3535
private int font2;
3636
private int green;
37+
private boolean showLabelCount;
3738

3839
public DrawerLayoutHelper() {
3940

@@ -43,9 +44,17 @@ public static DrawerLayoutHelper getInstance() {
4344
return new DrawerLayoutHelper();
4445
}
4546

46-
public void initData(Context context, DrawerLayout drawerLayout, FilterModel filterModel, FilterListener filterListener) {
47+
/**
48+
* @param context
49+
* @param projectInner 是不是显示标签数量
50+
* @param drawerLayout
51+
* @param filterModel
52+
* @param filterListener
53+
*/
54+
public void initData(Context context, boolean projectInner, DrawerLayout drawerLayout, FilterModel filterModel, FilterListener filterListener) {
4755
this.mContext = context;
4856
this.mFilterModel = filterModel;
57+
this.showLabelCount = !projectInner;
4958
font2 = mContext.getResources().getColor(R.color.font_2);
5059
green = mContext.getResources().getColor(R.color.green);
5160

@@ -119,7 +128,7 @@ private void iniLabels(FilterListener filterListener, EditText etSearch) {
119128
}
120129

121130
TextView labelItem = (TextView) layoutInflater.inflate(R.layout.dialog_task_filter_label_item, null);
122-
String str = String.format("%s (%d/%d)", item.name, item.processing, item.all);
131+
String str = showLabelCount ? String.format("%s (%d/%d)", item.name, item.processing, item.all) : item.name;
123132
labelItem.setText(str);
124133
setLeftDrawable(labelItem, item.color, item.name.equals(mFilterModel.label));
125134
labelItem.setOnClickListener(v -> {

app/src/main/java/net/coding/program/message/JSONUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ public static <T> List<T> getList(String key, String jsonString, Class<T> cls) {
3030
public static String getJSONString(String key, String jsonStringString) {
3131
return JSONObject.parseObject(jsonStringString).getString(key);
3232
}
33+
public static long getJSONLong(String key, String jsonStringString) {
34+
return JSONObject.parseObject(jsonStringString).getLong(key);
35+
}
3336
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package net.coding.program.model;
2+
3+
/**
4+
* Created by anfs on 22/12/2016.
5+
*/
6+
public class ProjectTaskCountModel {
7+
public long watch;
8+
public long processing;
9+
public long create;
10+
public long done;
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package net.coding.program.model;
2+
3+
/**
4+
* Created by anfs on 22/12/2016.
5+
*/
6+
public class ProjectTaskUserCountModel {
7+
public long memberDone;
8+
public long memberProcessing;
9+
10+
public long creatorDone;
11+
public long creatorProcessing;
12+
13+
public long watcherDone;
14+
public long watcherProcessing;
15+
}

app/src/main/java/net/coding/program/model/TaskLabelModel.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
*/
77
public class TaskLabelModel {
88
public String color;
9-
public String project_id;
9+
public long project_id;
1010
public String name;
1111
public int all;
1212
public int count;
1313
public int processing;
14+
15+
public int owner_id;
16+
public int task_count;
17+
public int merge_request_count;
1418
}

app/src/main/java/net/coding/program/model/TaskProjectCountModel.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
* 项目内 「我的任务、我关注的、我创建的」中「进行中的、已完成的」的数量
66
*/
77
public class TaskProjectCountModel {
8-
public int ownerDone;
9-
public int ownerProcessing;
10-
public int creatorDone;
11-
public int creatorProcessing;
12-
public int watcherDone;
13-
public int watcherProcessing;
8+
9+
public long owner;
10+
public long ownerDone;
11+
public long ownerProcessing;
12+
13+
public long creator;
14+
public long creatorDone;
15+
public long creatorProcessing;
16+
17+
public long watcher;
18+
public long watcherDone;
19+
public long watcherProcessing;
1420
}

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

Lines changed: 133 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
import net.coding.program.message.JSONUtils;
2525
import net.coding.program.model.AccountInfo;
2626
import net.coding.program.model.ProjectObject;
27+
import net.coding.program.model.ProjectTaskCountModel;
28+
import net.coding.program.model.ProjectTaskUserCountModel;
2729
import net.coding.program.model.TaskLabelModel;
2830
import net.coding.program.model.TaskObject;
2931
import net.coding.program.model.TaskProjectCountModel;
32+
import net.coding.program.model.UserObject;
3033
import net.coding.program.task.TaskListParentUpdate;
3134
import net.coding.program.task.TaskListUpdate;
3235
import net.coding.program.task.add.TaskAddActivity;
@@ -77,6 +80,7 @@ public class ProjectTaskFragment extends TaskFilterFragment implements TaskListP
7780
MemberTaskCount mMemberTask = new MemberTaskCount();
7881
private MyPagerAdapter adapter;
7982
private DrawerLayout drawer;
83+
private UserObject account;
8084

8185
@AfterViews
8286
protected final void initProjectTaskFragment() {
@@ -87,11 +91,29 @@ protected final void initProjectTaskFragment() {
8791
tabs.setLayoutInflater(mInflater);
8892
tabs.setVisibility(View.INVISIBLE);
8993

94+
account = AccountInfo.loadAccount(getActivity());
95+
9096
HOST_TASK_MEMBER = String.format(HOST_TASK_MEMBER, mProjectObject.getId());
9197
refresh();
9298

9399
adapter = new MyPagerAdapter(getChildFragmentManager());
94100
pager.setAdapter(adapter);
101+
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
102+
@Override
103+
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
104+
105+
}
106+
107+
@Override
108+
public void onPageSelected(int position) {
109+
loadData(position);
110+
}
111+
112+
@Override
113+
public void onPageScrollStateChanged(int state) {
114+
115+
}
116+
});
95117

96118
// 必须添加,否则回收恢复的时候,TaskListFragment 的 actionmenu 会显示几个出来
97119
setHasOptionsMenu(true);
@@ -106,10 +128,54 @@ protected void initFilterViews() {
106128
toolBarTitle.setOnClickListener(v -> {
107129
meActionFilter();
108130
});
109-
toolBarTitle.setText("我的任务");
131+
toolBarTitle.setText("全部任务");
132+
}
133+
134+
135+
loadData(0);
136+
}
137+
138+
@Override
139+
protected boolean isProjectInner() {
140+
return true;
141+
}
142+
143+
private void loadData(int index) {
144+
145+
mTaskProjectCountModel = new TaskProjectCountModel();
146+
147+
if (index == 0) {
148+
//全部成员
149+
//「全部任务」数量 - 进行中,已完成的 「我创建的」数量 = create
150+
getNetwork(String.format(urlProjectTaskCount, mProjectObject.getId()), urlProjectTaskCount);
151+
getNetwork(String.format(urlALL_Count, mProjectObject.getId()), urlALL_Count);
152+
getNetwork(String.format(urlALL_WATCH_Count, mProjectObject.getId(), account.id), urlALL_WATCH_Count);
153+
154+
loadAllLabels();
155+
} else {
156+
if (mMembersAll.size() <= index) {
157+
return;
158+
}
159+
TaskObject.Members members = mMembersAll.get(index);
160+
161+
//某个成员
162+
getNetwork(String.format(urlSome_Count, mProjectObject.getId(), members.user_id), urlSome_Count);
163+
getNetwork(String.format(urlSome_Label, mProjectObject.getId(), members.user_id), urlSome_Label);
164+
}
165+
}
166+
167+
private void loadAllLabels() {
168+
int cur = tabs.getCurrentPosition();
169+
if (cur != 0) {
170+
TaskObject.Members members = mMembersAll.get(cur + 1);
171+
getNetwork(String.format(urlSome_Label, mProjectObject.getId(), members.user_id), urlSome_Label);
172+
} else {
173+
if (statusIndex == 0) {
174+
getNetwork(String.format(urlALL_Label, mProjectObject.owner_user_name, mProjectObject.name), urlALL_Label);
175+
} else {
176+
getNetwork(String.format(urlProjectTaskLabels, mProjectObject.getId()) + getRole(), urlProjectTaskLabels);
177+
}
110178
}
111-
getNetwork(String.format(urlProjectTaskCount, mProjectObject.getId()), urlProjectTaskCount);
112-
getNetwork(String.format(urlProjectTaskLabels, mProjectObject.getId()) + getRole(), urlProjectTaskLabels);
113179
}
114180

115181
private void refresh() {
@@ -173,7 +239,29 @@ public void parseJson(int code, JSONObject respanse, String tag, int pos, Object
173239
} else if (tag.equals(urlProjectTaskCount)) {
174240
showLoading(false);
175241
if (code == 0) {
176-
mTaskProjectCountModel = JSONUtils.getData(respanse.getString("data"), TaskProjectCountModel.class);
242+
TaskProjectCountModel projectTaskCountModel = JSONUtils.getData(respanse.getString("data"), TaskProjectCountModel.class);
243+
mTaskProjectCountModel.creatorDone = projectTaskCountModel.creatorDone;
244+
mTaskProjectCountModel.creatorProcessing = projectTaskCountModel.creatorProcessing;
245+
mTaskProjectCountModel.watcherDone = projectTaskCountModel.watcherDone;
246+
mTaskProjectCountModel.watcherProcessing = projectTaskCountModel.watcherProcessing;
247+
} else {
248+
showErrorMsg(code, respanse);
249+
}
250+
} else if (tag.equals(urlALL_Count)) {
251+
showLoading(false);
252+
if (code == 0) {
253+
ProjectTaskCountModel projectTaskCountModel = JSONUtils.getData(respanse.getString("data"), ProjectTaskCountModel.class);
254+
mTaskProjectCountModel.owner = projectTaskCountModel.done + projectTaskCountModel.processing;
255+
mTaskProjectCountModel.ownerDone = projectTaskCountModel.done;
256+
mTaskProjectCountModel.ownerProcessing = projectTaskCountModel.processing;
257+
mTaskProjectCountModel.creator = projectTaskCountModel.create;
258+
} else {
259+
showErrorMsg(code, respanse);
260+
}
261+
} else if (tag.equals(urlALL_WATCH_Count)) {
262+
showLoading(false);
263+
if (code == 0) {
264+
mTaskProjectCountModel.watcher = JSONUtils.getJSONLong("totalRow", respanse.getString("data"));
177265
} else {
178266
showErrorMsg(code, respanse);
179267
}
@@ -185,6 +273,35 @@ public void parseJson(int code, JSONObject respanse, String tag, int pos, Object
185273
} else {
186274
showErrorMsg(code, respanse);
187275
}
276+
} else if (tag.equals(urlALL_Label)) {
277+
showLoading(false);
278+
if (code == 0) {
279+
taskLabelModels = JSONUtils.getList(respanse.getString("data"), TaskLabelModel.class);
280+
Collections.sort(taskLabelModels, new PinyinComparator());
281+
} else {
282+
showErrorMsg(code, respanse);
283+
}
284+
} else if (tag.equals(urlSome_Count)) {
285+
showLoading(false);
286+
if (code == 0) {
287+
ProjectTaskUserCountModel item = JSONUtils.getData(respanse.getString("data"), ProjectTaskUserCountModel.class);
288+
mTaskProjectCountModel.ownerDone = item.memberDone;
289+
mTaskProjectCountModel.ownerProcessing = item.memberProcessing;
290+
mTaskProjectCountModel.creatorDone = item.creatorDone;
291+
mTaskProjectCountModel.creatorProcessing = item.creatorProcessing;
292+
mTaskProjectCountModel.watcherDone = item.watcherDone;
293+
mTaskProjectCountModel.watcherProcessing = item.watcherProcessing;
294+
} else {
295+
showErrorMsg(code, respanse);
296+
}
297+
} else if (tag.equals(urlSome_Label)) {
298+
showLoading(false);
299+
if (code == 0) {
300+
taskLabelModels = JSONUtils.getList(respanse.getString("data"), TaskLabelModel.class);
301+
Collections.sort(taskLabelModels, new PinyinComparator());
302+
} else {
303+
showErrorMsg(code, respanse);
304+
}
188305
}
189306

190307
}
@@ -311,9 +428,17 @@ public Fragment getItem(int position) {
311428
bundle.putSerializable("mMembersArray", mUsersInfo);
312429
bundle.putSerializable("mMemberPos", position);
313430
bundle.putBoolean("mShowAdd", true);
314-
// bundle.putString("mMeAction", "");
315-
// bundle.putString("mStatus", "");
316-
// bundle.putString("mLabel", "");
431+
432+
bundle.putString("mMeAction", mMeActions[statusIndex]);
433+
if (mFilterModel != null) {
434+
bundle.putString("mStatus", mFilterModel.status + "");
435+
bundle.putString("mLabel", mFilterModel.label);
436+
bundle.putString("mKeyword", mFilterModel.keyword);
437+
} else {
438+
bundle.putString("mStatus", "");
439+
bundle.putString("mLabel", "");
440+
bundle.putString("mKeyword", "");
441+
}
317442
fragment.setParent(ProjectTaskFragment.this);
318443

319444
fragment.setArguments(bundle);
@@ -346,6 +471,6 @@ protected final void action_filter() {
346471
@Override
347472
protected void sureFilter() {
348473
super.sureFilter();
349-
getNetwork(String.format(urlProjectTaskLabels, mProjectObject.getId()) + getRole(), urlProjectTaskLabels);
474+
loadAllLabels();
350475
}
351476
}

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,20 @@ public class TaskFilterFragment extends LoadingFragment {
3939
protected final String urlProjectTaskLabels = Global.HOST_API + "/project/%s/tasks/labels?role=";
4040

4141
//项目内 全部成员
42-
protected final String urlALL_P_WatcherCount = Global.HOST_API + "project/{projectId}/task/count";
43-
protected final String urlALL_P_CreatorCount = Global.HOST_API + "/project/%s/task/count";
42+
//全部任务-标签-数量
43+
/**
44+
* 「全部任务」数量 = processing + done
45+
* 「我创建的」数量 = create
46+
* 进行中已完成的数量也有了
47+
*/
48+
protected final String urlALL_Count = Global.HOST_API + "/project/%s/task/count";
49+
protected final String urlALL_WATCH_Count = Global.HOST_API + "/tasks/search?project_id=%s&watcher=%s";
50+
//全部任务」的标签
51+
protected final String urlALL_Label = Global.HOST_API + "/user/%s/project/%s/task/label?withCount=true";
52+
53+
//某个成员的任务数量
54+
protected final String urlSome_Count = Global.HOST_API + "/project/%s/user/%s/tasks/counts";
55+
protected final String urlSome_Label = Global.HOST_API + "/project/%s/user/%s/tasks/labels";
4456

4557
//任务筛选
4658
protected TextView toolBarTitle;
@@ -52,6 +64,7 @@ public class TaskFilterFragment extends LoadingFragment {
5264
protected TaskCountModel mTaskCountModel;
5365
protected TaskProjectCountModel mTaskProjectCountModel;
5466

67+
5568
protected String getRole() {
5669
if (statusIndex >= mMeActions.length) {
5770
statusIndex = 0;
@@ -84,7 +97,7 @@ private void iniTaskStatus() {
8497
int[] filterItem = {R.id.tv_status1, R.id.tv_status2, R.id.tv_status3};
8598
String[] filterTxtCount = new String[0];
8699
String[] filterTxt = new String[]{
87-
"我的任务",
100+
isProjectInner() ? "全部任务" : "我的任务",
88101
"我关注的",
89102
"我创建的"
90103
};
@@ -175,7 +188,7 @@ protected final void actionFilter() {
175188
}
176189
}
177190

178-
DrawerLayoutHelper.getInstance().initData(getContext(), drawerLayout, mFilterModel, new FilterListener() {
191+
DrawerLayoutHelper.getInstance().initData(getContext(), isProjectInner(), drawerLayout, mFilterModel, new FilterListener() {
179192
@Override
180193
public void callback(FilterModel filterModel) {
181194
mFilterModel = filterModel;
@@ -207,4 +220,8 @@ public int getStatusIndex() {
207220
public void onRefresh() {
208221

209222
}
223+
224+
protected boolean isProjectInner() {
225+
return false;
226+
}
210227
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
180180
//检查是否有筛选条件
181181
String checkHostFilter() {
182182
String host = "";
183-
if (!TextUtils.isEmpty(mMeAction)) {
184-
int userId = AccountInfo.loadAccount(getActivity()).id;
183+
int userId = mMembers.user_id;
184+
if (!TextUtils.isEmpty(mMeAction) && userId != 0) {
185185
host += String.format("%s=%s&", mMeAction, userId);
186186
}
187187
if (!TextUtils.isEmpty(mStatus) && !mStatus.equals("0")) {

0 commit comments

Comments
 (0)