|
|
@@ -47,205 +47,213 @@ import java.util.List;
|
|
|
*/
|
|
|
|
|
|
public class ActivityFragment extends EasyFragment implements View.OnClickListener {
|
|
|
- private HttpClient httpClient = new HttpClient.Builder(Constants.charitBaseUrl()).isDebug(true).build();
|
|
|
- private PullToRefreshListView refreshListView;
|
|
|
- private BaseActivity baseActivity;
|
|
|
- private TextView statusTv;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onAttach(Context context) {
|
|
|
- super.onAttach(context);
|
|
|
- if (context instanceof BaseActivity) {
|
|
|
- baseActivity = (BaseActivity) context;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected int inflateLayoutId() {
|
|
|
- return R.layout.fragment_charitable_list;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreateView(Bundle savedInstanceState, boolean createView) {
|
|
|
- if (createView) {
|
|
|
- setHasOptionsMenu(true);
|
|
|
- initView();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
- inflater.inflate(R.menu.search, menu);
|
|
|
- super.onCreateOptionsMenu(menu, inflater);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
- if (item.getItemId() == R.id.search) {
|
|
|
- startActivity(new Intent(ct, CharitSearchActivity.class).
|
|
|
- putExtra("type", 2)
|
|
|
- .putExtra("title", "活动搜索"));
|
|
|
- }
|
|
|
- return super.onOptionsItemSelected(item);
|
|
|
- }
|
|
|
-
|
|
|
- private void initView() {
|
|
|
- refreshListView = (PullToRefreshListView) findViewById(R.id.refreshListView);
|
|
|
- refreshListView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
|
|
|
- refreshListView.getRefreshableView().addHeaderView(getHandlerView());
|
|
|
- refreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
- @Override
|
|
|
- public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
- if (mAdapter != null && ListUtils.getSize(mAdapter.getModels()) > i) {
|
|
|
- CharitActModel model = mAdapter.getModels().get(i);
|
|
|
- IntentUtils.linkCommonWeb(ct, Constants.BASE_CHARIT_ACTIVITY_URL + "?pro_id=" + model.getId(), model.getName());
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- setAdapter(null);
|
|
|
- initData();
|
|
|
- }
|
|
|
-
|
|
|
- public View getHandlerView() {
|
|
|
- View handlerView = LayoutInflater.from(ct).inflate(R.layout.handler_charit_activity, null);
|
|
|
- statusTv = (TextView) handlerView.findViewById(R.id.statusTv);
|
|
|
- handlerView.findViewById(R.id.searchIv).setOnClickListener(this);
|
|
|
- statusTv.setOnClickListener(this);
|
|
|
- return handlerView;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void initData() {
|
|
|
- loadData("", "全部");
|
|
|
- }
|
|
|
-
|
|
|
- private void loadData(String keyWork, final String status) {
|
|
|
- if (!NetUtils.isNetWorkConnected(ct)) {
|
|
|
- ToastUtil.showToast(ct, R.string.networks_out);
|
|
|
- return;
|
|
|
- }
|
|
|
- baseActivity.progressDialog.show();
|
|
|
- httpClient.Api().send(new HttpClient.Builder()
|
|
|
- .url("activities")
|
|
|
- .add("keyWork", keyWork)
|
|
|
- .add("status", status)
|
|
|
- .method(Method.GET)
|
|
|
- .build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
- @Override
|
|
|
- public void onResponse(Object o) {
|
|
|
- try {
|
|
|
- if (o != null) {
|
|
|
- handlerData(o.toString(), status);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- if (e != null) {
|
|
|
- LogUtil.i("e=" + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- baseActivity.progressDialog.dismiss();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }));
|
|
|
- }
|
|
|
-
|
|
|
- private ActivityAdapter mAdapter;
|
|
|
- private List<CharitActModel> allModels;
|
|
|
-
|
|
|
- private void handlerData(String message, String status) throws Exception {
|
|
|
- LogUtil.i("handlerData");
|
|
|
- if (JSONUtil.validateJSONObject(message)) {
|
|
|
- JSONObject object = JSON.parseObject(message);
|
|
|
- JSONArray array = JSONUtil.getJSONArray(object, "activityList");
|
|
|
- allModels = JSON.parseArray(array.toString(), CharitActModel.class);
|
|
|
- setAdapter(status, allModels);
|
|
|
- } else {
|
|
|
- setAdapter(null);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void setAdapter(String status, List<CharitActModel> models) {
|
|
|
+ private HttpClient httpClient = new HttpClient.Builder(Constants.charitBaseUrl()).isDebug(true).build();
|
|
|
+ private PullToRefreshListView refreshListView;
|
|
|
+ private BaseActivity baseActivity;
|
|
|
+ private TextView statusTv;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAttach(Context context) {
|
|
|
+ super.onAttach(context);
|
|
|
+ if (context instanceof BaseActivity) {
|
|
|
+ baseActivity = (BaseActivity) context;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int inflateLayoutId() {
|
|
|
+ return R.layout.fragment_charitable_list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreateView(Bundle savedInstanceState, boolean createView) {
|
|
|
+ if (createView) {
|
|
|
+ setHasOptionsMenu(true);
|
|
|
+ initView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
+ inflater.inflate(R.menu.search, menu);
|
|
|
+ super.onCreateOptionsMenu(menu, inflater);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+ if (item.getItemId() == R.id.search) {
|
|
|
+ startActivity(new Intent(ct, CharitSearchActivity.class).
|
|
|
+ putExtra("type", 2)
|
|
|
+ .putExtra("title", "活动搜索"));
|
|
|
+ }
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initView() {
|
|
|
+ refreshListView = (PullToRefreshListView) findViewById(R.id.refreshListView);
|
|
|
+ refreshListView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
|
|
|
+ refreshListView.getRefreshableView().addHeaderView(getHandlerView());
|
|
|
+ refreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
+ try {
|
|
|
+ toDetail((int) l);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ setAdapter(null);
|
|
|
+ initData();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void toDetail(int position) throws Exception {
|
|
|
+ if (mAdapter != null && ListUtils.getSize(mAdapter.getModels()) > position) {
|
|
|
+ CharitActModel model = mAdapter.getModels().get(position);
|
|
|
+ IntentUtils.linkCommonWeb(ct, Constants.BASE_CHARIT_ACTIVITY_URL + "?pro_id=" + model.getId(), model.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public View getHandlerView() {
|
|
|
+ View handlerView = LayoutInflater.from(ct).inflate(R.layout.handler_charit_activity, null);
|
|
|
+ statusTv = (TextView) handlerView.findViewById(R.id.statusTv);
|
|
|
+ handlerView.findViewById(R.id.searchIv).setOnClickListener(this);
|
|
|
+ statusTv.setOnClickListener(this);
|
|
|
+ return handlerView;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void initData() {
|
|
|
+ loadData("", "全部");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadData(String keyWork, final String status) {
|
|
|
+ if (!NetUtils.isNetWorkConnected(ct)) {
|
|
|
+ ToastUtil.showToast(ct, R.string.networks_out);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ baseActivity.progressDialog.show();
|
|
|
+ httpClient.Api().send(new HttpClient.Builder()
|
|
|
+ .url("activities")
|
|
|
+ .add("keyWork", keyWork)
|
|
|
+ .add("status", status)
|
|
|
+ .method(Method.GET)
|
|
|
+ .build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object o) {
|
|
|
+ try {
|
|
|
+ if (o != null) {
|
|
|
+ handlerData(o.toString(), status);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (e != null) {
|
|
|
+ LogUtil.i("e=" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ baseActivity.progressDialog.dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ private ActivityAdapter mAdapter;
|
|
|
+ private List<CharitActModel> allModels;
|
|
|
+
|
|
|
+ private void handlerData(String message, String status) throws Exception {
|
|
|
+ LogUtil.i("handlerData");
|
|
|
+ if (JSONUtil.validateJSONObject(message)) {
|
|
|
+ JSONObject object = JSON.parseObject(message);
|
|
|
+ JSONArray array = JSONUtil.getJSONArray(object, "activityList");
|
|
|
+ allModels = JSON.parseArray(array.toString(), CharitActModel.class);
|
|
|
+ setAdapter(status, allModels);
|
|
|
+ } else {
|
|
|
+ setAdapter(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setAdapter(String status, List<CharitActModel> models) {
|
|
|
// String newtime = DateFormatUtil.long2Str("yyyy.MM.dd HH:mm");
|
|
|
- List<CharitActModel> showModels = new ArrayList<>();
|
|
|
- if (!"全部".equals(status)) {
|
|
|
- for (CharitActModel model : models) {
|
|
|
- if (status.equals(model.getStage())) {
|
|
|
- showModels.add(model);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- showModels = allModels;
|
|
|
- }
|
|
|
- setAdapter(showModels);
|
|
|
- }
|
|
|
-
|
|
|
- private void setAdapter(List<CharitActModel> models) {
|
|
|
- if (mAdapter == null) {
|
|
|
- mAdapter = new ActivityAdapter(ct, models);
|
|
|
- refreshListView.setAdapter(mAdapter);
|
|
|
- } else {
|
|
|
- mAdapter.setModels(models);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(View view) {
|
|
|
- int id = view.getId();
|
|
|
- if (id == R.id.searchIv) {
|
|
|
-
|
|
|
- } else if (id == R.id.statusTv) {
|
|
|
- showCommonWordsIV(statusTv);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void showCommonWordsIV(View view) {
|
|
|
- final PopupWindow window = new PopupWindow(ct);
|
|
|
- View windowView = LayoutInflater.from(ct).inflate(R.layout.item_list_pop, null);
|
|
|
- window.setContentView(windowView);
|
|
|
- ListView contentLV = (ListView) windowView.findViewById(R.id.contentLV);
|
|
|
- final String[] messages = {"全部", "进行中", "已结束"};
|
|
|
- contentLV.setAdapter(new PopListAdapter(ct, messages));
|
|
|
- window.setTouchable(true);
|
|
|
- window.setBackgroundDrawable(ct.getResources().getDrawable(R.drawable.pop_round_bg));
|
|
|
- window.getContentView().measure(0, 0);
|
|
|
- window.setHeight(DisplayUtil.dip2px(ct, 150));
|
|
|
- window.setWidth(DisplayUtil.dip2px(ct, 80));
|
|
|
+ List<CharitActModel> showModels = new ArrayList<>();
|
|
|
+ if (!"全部".equals(status)) {
|
|
|
+ for (CharitActModel model : models) {
|
|
|
+ if (status.equals(model.getStage())) {
|
|
|
+ showModels.add(model);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ showModels = allModels;
|
|
|
+ }
|
|
|
+ setAdapter(showModels);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setAdapter(List<CharitActModel> models) {
|
|
|
+ if (mAdapter == null) {
|
|
|
+ mAdapter = new ActivityAdapter(ct, models);
|
|
|
+ refreshListView.setAdapter(mAdapter);
|
|
|
+ } else {
|
|
|
+ mAdapter.setModels(models);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ int id = view.getId();
|
|
|
+ if (id == R.id.searchIv) {
|
|
|
+
|
|
|
+ } else if (id == R.id.statusTv) {
|
|
|
+ showCommonWordsIV(statusTv);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void showCommonWordsIV(View view) {
|
|
|
+ final PopupWindow window = new PopupWindow(ct);
|
|
|
+ View windowView = LayoutInflater.from(ct).inflate(R.layout.item_list_pop, null);
|
|
|
+ window.setContentView(windowView);
|
|
|
+ ListView contentLV = (ListView) windowView.findViewById(R.id.contentLV);
|
|
|
+ final String[] messages = {"全部", "进行中", "已结束"};
|
|
|
+ contentLV.setAdapter(new PopListAdapter(ct, messages));
|
|
|
+ window.setTouchable(true);
|
|
|
+ window.setBackgroundDrawable(ct.getResources().getDrawable(R.drawable.pop_round_bg));
|
|
|
+ window.getContentView().measure(0, 0);
|
|
|
+ window.setHeight(DisplayUtil.dip2px(ct, 150));
|
|
|
+ window.setWidth(DisplayUtil.dip2px(ct, 80));
|
|
|
// window.setAnimationStyle(R.style.MenuAnimationFade);
|
|
|
- window.setOutsideTouchable(false);
|
|
|
- window.setFocusable(true);
|
|
|
- //获取需要在其上方显示的控件的位置信息
|
|
|
- int[] location = new int[2];
|
|
|
- view.getLocationOnScreen(location);
|
|
|
- //在控件上方显示
|
|
|
- window.showAtLocation(view, Gravity.NO_GRAVITY, location[0], location[1] + view.getHeight());
|
|
|
- DisplayUtil.backgroundAlpha(ct, 0.6f);
|
|
|
- contentLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
- @Override
|
|
|
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
- String message = messages[position];
|
|
|
- window.dismiss();
|
|
|
- selectStatus(message);
|
|
|
- statusTv.setText(message);
|
|
|
- }
|
|
|
- });
|
|
|
- window.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
- @Override
|
|
|
- public void onDismiss() {
|
|
|
- DisplayUtil.backgroundAlpha(ct, 1f);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void selectStatus(String message) {
|
|
|
- if (message == null || message.length() <= 0) {
|
|
|
- ToastUtil.showToast(ct, "选择错误");
|
|
|
- } else if (ListUtils.isEmpty(allModels)) {
|
|
|
- loadData("", message);
|
|
|
- } else {
|
|
|
- setAdapter(message, allModels);
|
|
|
- }
|
|
|
- }
|
|
|
+ window.setOutsideTouchable(false);
|
|
|
+ window.setFocusable(true);
|
|
|
+ //获取需要在其上方显示的控件的位置信息
|
|
|
+ int[] location = new int[2];
|
|
|
+ view.getLocationOnScreen(location);
|
|
|
+ //在控件上方显示
|
|
|
+ window.showAtLocation(view, Gravity.NO_GRAVITY, location[0], location[1] + view.getHeight());
|
|
|
+ DisplayUtil.backgroundAlpha(ct, 0.6f);
|
|
|
+ contentLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ String message = messages[position];
|
|
|
+ window.dismiss();
|
|
|
+ selectStatus(message);
|
|
|
+ statusTv.setText(message);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ window.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ DisplayUtil.backgroundAlpha(ct, 1f);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void selectStatus(String message) {
|
|
|
+ if (message == null || message.length() <= 0) {
|
|
|
+ ToastUtil.showToast(ct, "选择错误");
|
|
|
+ } else if (ListUtils.isEmpty(allModels)) {
|
|
|
+ loadData("", message);
|
|
|
+ } else {
|
|
|
+ setAdapter(message, allModels);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|