Skip to content

Commit ff79556

Browse files
committed
修改新建任务选择 project list 的界面
1 parent fba8c1f commit ff79556

6 files changed

Lines changed: 252 additions & 89 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package net.coding.program.project;
2+
3+
import android.os.Bundle;
4+
import android.support.v4.app.Fragment;
5+
import android.support.v4.app.FragmentManager;
6+
import android.support.v4.view.PagerAdapter;
7+
import android.util.Log;
8+
import android.view.ViewGroup;
9+
10+
import net.coding.program.common.SaveFragmentPagerAdapter;
11+
import net.coding.program.model.ProjectObject;
12+
13+
import java.util.ArrayList;
14+
15+
/**
16+
* Created by chenchao on 15/8/1.
17+
*/
18+
class MyProjectPagerAdapter extends SaveFragmentPagerAdapter {
19+
20+
private ProjectFragment projectFragment;
21+
22+
public MyProjectPagerAdapter(ProjectFragment projectFragment, FragmentManager fm) {
23+
super(fm);
24+
this.projectFragment = projectFragment;
25+
}
26+
27+
@Override
28+
public CharSequence getPageTitle(int position) {
29+
return projectFragment.program_title[position];
30+
}
31+
32+
@Override
33+
public int getCount() {
34+
return projectFragment.program_title.length;
35+
}
36+
37+
@Override
38+
public int getItemPosition(Object object) {
39+
return PagerAdapter.POSITION_NONE;
40+
}
41+
42+
@Override
43+
public Object instantiateItem(ViewGroup container, int position) {
44+
ProjectListFragment fragment = (ProjectListFragment) super.instantiateItem(container, position);
45+
fragment.setData(getChildData(position), projectFragment.requestOk);
46+
47+
return fragment;
48+
}
49+
50+
@Override
51+
public Fragment getItem(int position) {
52+
Log.d("", "all p " + position);
53+
ProjectListFragment fragment = new ProjectListFragment_();
54+
Bundle bundle = new Bundle();
55+
56+
bundle.putSerializable("mData", getChildData(position));
57+
bundle.putSerializable("type", projectFragment.type);
58+
fragment.setArguments(bundle);
59+
60+
saveFragment(fragment);
61+
62+
return fragment;
63+
}
64+
65+
private ArrayList<ProjectObject> getChildData(int position) {
66+
ArrayList<ProjectObject> childData = new ArrayList<>();
67+
68+
switch (position) {
69+
case 1:
70+
stuffChildData(childData, "member");
71+
break;
72+
case 2:
73+
stuffChildData(childData, "owner");
74+
break;
75+
default:
76+
if (projectFragment.type == ProjectFragment.Type.Pick) {
77+
stuffPrivateProjectChildData(childData);
78+
} else {
79+
childData.addAll(projectFragment.mData);
80+
}
81+
break;
82+
}
83+
84+
return childData;
85+
}
86+
87+
void stuffChildData(ArrayList<ProjectObject> child, String type) {
88+
for (int i = 0; i < projectFragment.mData.size(); ++i) {
89+
ProjectObject item = projectFragment.mData.get(i);
90+
if (item.current_user_role.equals(type)) {
91+
child.add(item);
92+
}
93+
}
94+
}
95+
96+
void stuffPrivateProjectChildData(ArrayList<ProjectObject> child) {
97+
for (int i = 0; i < projectFragment.mData.size(); ++i) {
98+
ProjectObject item = projectFragment.mData.get(i);
99+
if (!item.isPublic()) {
100+
child.add(item);
101+
}
102+
}
103+
}
104+
}

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

Lines changed: 32 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@
66
import android.content.IntentFilter;
77
import android.os.Bundle;
88
import android.support.v4.app.Fragment;
9-
import android.support.v4.app.FragmentManager;
10-
import android.support.v4.view.PagerAdapter;
119
import android.support.v4.view.ViewPager;
1210
import android.support.v4.widget.SwipeRefreshLayout;
13-
import android.util.Log;
1411
import android.util.TypedValue;
15-
import android.view.ViewGroup;
12+
import android.view.Menu;
13+
import android.view.MenuInflater;
14+
import android.view.View;
1615

1716
import net.coding.program.MyApp;
1817
import net.coding.program.R;
1918
import net.coding.program.common.Global;
20-
import net.coding.program.common.SaveFragmentPagerAdapter;
2119
import net.coding.program.common.network.BaseFragment;
2220
import net.coding.program.maopao.MaopaoAddActivity_;
2321
import net.coding.program.model.AccountInfo;
@@ -28,10 +26,9 @@
2826

2927
import org.androidannotations.annotations.AfterViews;
3028
import org.androidannotations.annotations.EFragment;
29+
import org.androidannotations.annotations.FragmentArg;
3130
import org.androidannotations.annotations.OptionsItem;
32-
import org.androidannotations.annotations.OptionsMenu;
3331
import org.androidannotations.annotations.ViewById;
34-
import org.androidannotations.annotations.res.StringArrayRes;
3532
import org.json.JSONArray;
3633
import org.json.JSONException;
3734
import org.json.JSONObject;
@@ -41,21 +38,23 @@
4138
import java.util.List;
4239

4340
@EFragment(R.layout.fragment_project)
44-
@OptionsMenu(R.menu.menu_fragment_project)
4541
public class ProjectFragment extends BaseFragment implements ProjectListFragment.UpdateData, SwipeRefreshLayout.OnRefreshListener {
4642

4743
public static final String RECEIVER_INTENT_REFRESH_PROJECT = "net.coding.program.project.receiver.refresh";
4844
final String host = Global.HOST_API + "/projects?pageSize=100&type=all&sort=hot";
49-
@StringArrayRes
45+
5046
String[] program_title;
5147
@ViewById
5248
net.coding.program.third.WechatTab tabs;
5349
@ViewById(R.id.pagerFragmentProgram)
5450
ViewPager pager;
51+
52+
@FragmentArg
53+
Type type = Type.Main;
5554
boolean requestOk = true;
5655
boolean needRefresh = true;
57-
private ArrayList<ProjectObject> mData = new ArrayList<>();
58-
private MyPagerAdapter adapter;
56+
ArrayList<ProjectObject> mData = new ArrayList<>();
57+
private MyProjectPagerAdapter adapter;
5958
private BroadcastReceiver refreshReceiver = new BroadcastReceiver() {
6059
@Override
6160
public void onReceive(Context context, Intent intent) {
@@ -69,7 +68,16 @@ public void onReceive(Context context, Intent intent) {
6968
protected void init() {
7069
hideProgressDialog();
7170
mData = AccountInfo.loadProjects(getActivity());
72-
adapter = new MyPagerAdapter(getChildFragmentManager());
71+
72+
if (type == Type.Main) {
73+
setHasOptionsMenu(true);
74+
program_title = getResources().getStringArray(R.array.program_title);
75+
} else {
76+
setHasOptionsMenu(false);
77+
program_title = getResources().getStringArray(R.array.program_title_pick);
78+
}
79+
80+
adapter = new MyProjectPagerAdapter(this, getChildFragmentManager());
7381

7482
pager.setAdapter(adapter);
7583

@@ -78,13 +86,23 @@ protected void init() {
7886
pager.setPageMargin(pageMargin);
7987

8088
tabs.setViewPager(pager);
89+
90+
if (type == Type.Pick) {
91+
tabs.setVisibility(View.GONE);
92+
}
8193
}
8294

8395
@Override
8496
public void onRefresh() {
8597
getNetwork(host, host);
8698
}
8799

100+
@Override
101+
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
102+
inflater.inflate(net.coding.program.R.menu.menu_fragment_project, menu);
103+
super.onCreateOptionsMenu(menu, inflater);
104+
}
105+
88106
@Override
89107
public void updateRead(int id) {
90108
List<WeakReference<Fragment>> fragmentList = adapter.getFragments();
@@ -216,74 +234,7 @@ public void onDestroy() {
216234
super.onDestroy();
217235
}
218236

219-
private class MyPagerAdapter extends SaveFragmentPagerAdapter {
220-
221-
public MyPagerAdapter(FragmentManager fm) {
222-
super(fm);
223-
}
224-
225-
@Override
226-
public CharSequence getPageTitle(int position) {
227-
return program_title[position];
228-
}
229-
230-
@Override
231-
public int getCount() {
232-
return program_title.length;
233-
}
234-
235-
@Override
236-
public int getItemPosition(Object object) {
237-
return PagerAdapter.POSITION_NONE;
238-
}
239-
240-
@Override
241-
public Object instantiateItem(ViewGroup container, int position) {
242-
ProjectListFragment fragment = (ProjectListFragment) super.instantiateItem(container, position);
243-
fragment.setData(getChildData(position), requestOk);
244-
245-
return fragment;
246-
}
247-
248-
@Override
249-
public Fragment getItem(int position) {
250-
Log.d("", "all p " + position);
251-
ProjectListFragment fragment = new ProjectListFragment_();
252-
Bundle bundle = new Bundle();
253-
254-
bundle.putSerializable("mData", getChildData(position));
255-
fragment.setArguments(bundle);
256-
257-
saveFragment(fragment);
258-
259-
return fragment;
260-
}
261-
262-
private ArrayList<ProjectObject> getChildData(int position) {
263-
ArrayList<ProjectObject> childData = new ArrayList<>();
264-
265-
switch (position) {
266-
case 1:
267-
stuffChildData(childData, "member");
268-
break;
269-
case 2:
270-
stuffChildData(childData, "owner");
271-
break;
272-
default:
273-
childData.addAll(mData);
274-
break;
275-
}
276-
277-
return childData;
278-
}
279-
280-
void stuffChildData(ArrayList<ProjectObject> child, String type) {
281-
for (int i = 0; i < mData.size(); ++i) {
282-
ProjectObject item = mData.get(i);
283-
if (item.current_user_role.equals(type)) {
284-
child.add(item);
285-
}
286-
}
287-
}
237+
public enum Type {
238+
Main, Pick
288239
}
289240
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class ProjectListFragment extends RefreshBaseFragment {
4848
private static final String URL_PIN_SET = Global.HOST_API + "/user/projects/pin";
4949
@FragmentArg
5050
ArrayList<ProjectObject> mData = new ArrayList<>();
51+
@FragmentArg
52+
ProjectFragment.Type type = ProjectFragment.Type.Main;
53+
5154
boolean mRequestOk;
5255
@ViewById
5356
ExpandableStickyListHeadersListView listView;
@@ -203,7 +206,14 @@ public void listView(ProjectObject item) {
203206
fragment = this;
204207
}
205208

206-
ProjectHomeActivity_.intent(fragment).mProjectObject(item).startForResult(InitProUtils.REQUEST_PRO_UPDATE);
209+
if (type == ProjectFragment.Type.Main) {
210+
ProjectHomeActivity_.intent(fragment).mProjectObject(item).startForResult(InitProUtils.REQUEST_PRO_UPDATE);
211+
} else {
212+
Intent intent = new Intent();
213+
intent.putExtra("data", item);
214+
getActivity().setResult(Activity.RESULT_OK, intent);
215+
getActivity().finish();
216+
}
207217
}
208218

209219
@Override

0 commit comments

Comments
 (0)