Пример #1
0
 /** 检查用户登录状态以便于刷新 */
 private void checkLogin() {
   if (modelFirst == null && DB.getInstance(getActivity()).getUserModel() != null) {
     modelFirst = DB.getInstance(getActivity()).getUserModel();
     organization_login_layout.setVisibility(View.GONE);
     refreshOrganization();
   } else if (modelFirst != null && DB.getInstance(getActivity()).getUserModel() == null) {
     modelFirst = null;
     organization_login_layout.setVisibility(View.VISIBLE);
     allOrganizationInfo.clear();
     adapter.notifyDataSetChanged();
   } else if (modelFirst != null && DB.getInstance(getActivity()).getUserModel() != null) {
     if (modelFirst.getUser_id() != DB.getInstance(getActivity()).getUserModel().getUser_id()) {
       modelFirst = DB.getInstance(getActivity()).getUserModel();
       refreshOrganization();
     }
   }
 }
Пример #2
0
  /** 加载校友组织列表 */
  private void loadOrganizationData() {
    isLoading = true;
    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    UserModel model = DB.getInstance(getActivity()).getUserModel();
    if (model == null) {
      organization_list.onRefreshComplete();
      isLoading = false;
      return;
    }
    Security se = new Security();
    String serToken =
        se.getToken(
            "" + (ParamsManager.extratime + System.currentTimeMillis()),
            "get",
            model.getToken(),
            getActivity());
    Header[] headers = {
      new BasicHeader("Authorization", AuthorizationConfig.TOKENPRE + model.getToken()),
      new BasicHeader("Validation", serToken)
    };
    client.get(
        getActivity(),
        ParamsManager.HttpUrl + "StudentsContacts/contactsapi/aluassociation/get",
        headers,
        params,
        new AsyncHttpResponseHandler() {

          @Override
          public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            // TODO Auto-generated method stub
            if (getActivity() != null && getActivity().isFinishing()) {
              return;
            }
            System.out.println(new String(arg2));
            allOrganizationInfo.clear();
            allOrganizationInfo.addAll(
                JsonParse.getAllOrganizationModel(new String(arg2), queryType));
            adapter.notifyDataSetChanged();
            organization_list_no.setVisibility(View.GONE);
          }

          @Override
          public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            // TODO Auto-generated method stub
            if (getActivity() != null && getActivity().isFinishing()) {
              return;
            }
            organization_list_no.setVisibility(View.VISIBLE);
            if (arg0 == 401) {
              JsonParse.showMessage(getActivity(), new String(arg2));
            } else {
              CommonUtils.showCustomToast(
                  getActivity(), getResources().getString(R.string.network_error), false);
            }
          }

          @Override
          public void onFinish() {
            // TODO Auto-generated method stub
            super.onFinish();
            organization_list.onRefreshComplete();
            isLoading = false;
          }
        });
  }
Пример #3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    if (view == null) {
      modelFirst = DB.getInstance(getActivity()).getUserModel();
      allOrganizationInfo = new ArrayList<Object>();

      view =
          LayoutInflater.from(getActivity())
              .inflate(R.layout.fragment_organization, container, false);

      nav_title = (TextView) view.findViewById(R.id.nav_title);
      nav_title.setText("校友组织");
      nav_left_item = (ImageView) view.findViewById(R.id.nav_left_item);
      nav_left_item.setVisibility(View.VISIBLE);
      nav_left_item.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              getActivity().finish();
            }
          });
      nav_right_item = (ImageView) view.findViewById(R.id.nav_right_item);
      nav_right_item.setVisibility(View.VISIBLE);
      nav_right_item.setImageResource(R.drawable.ic_organization_add);
      nav_right_item.setOnClickListener(
          new ImageView.OnClickListener() {

            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              UserModel model = DB.getInstance(getActivity()).getUserModel();
              if (model == null) {
                Intent intent = new Intent(getActivity(), LoginActivity.class);
                startActivity(intent);
              } else {
                //						if(pop!=null&&pop.isShowing()) {
                //							pop.dismiss();
                //						}
                //						else {
                //							showAddOrganizationLayout();
                //						}

                String[] strArray = null;
                if (queryType.equals("all")) {
                  String[] temp = {"添加班级录", "添加校友会"};
                  strArray = temp;
                } else if (queryType.equals("myclass")) {
                  String[] temp = {"添加班级录"};
                  strArray = temp;
                } else if (queryType.equals("myalumni")) {
                  String[] temp = {"添加校友会"};
                  strArray = temp;
                }
                CommonUtils.showCustomAlertDialog(
                    getActivity(),
                    strArray,
                    null,
                    new OnDialogItemClickListener() {

                      @Override
                      public void click(int pos) {
                        // TODO Auto-generated method stub
                        if (queryType.equals("all")) {
                          if (pos == 0) {
                            Intent intent = new Intent(getActivity(), SearchClassActivity.class);
                            getParentFragment()
                                .startActivityForResult(intent, ParamsManager.ORGANIZATION_REFRESH);
                          } else if (pos == 1) {
                            Intent intent = new Intent(getActivity(), SearchAlumniActivity.class);
                            startActivity(intent);
                          }
                        } else if (queryType.equals("myclass")) {
                          Intent intent = new Intent(getActivity(), SearchClassActivity.class);
                          startActivityForResult(intent, ParamsManager.ORGANIZATION_REFRESH);
                        } else if (queryType.equals("myalumni")) {
                          Intent intent = new Intent(getActivity(), SearchAlumniActivity.class);
                          startActivity(intent);
                        }
                      }
                    });
              }
            }
          });

      organization_list = (PullToRefreshListView) view.findViewById(R.id.organization_list);
      actualbeginListView = organization_list.getRefreshableView();
      adapter =
          new OrganizationAdapter(getActivity(), allOrganizationInfo, OrganizationFragment.this);
      actualbeginListView.setAdapter(adapter);
      actualbeginListView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
              // TODO Auto-generated method stub

            }
          });
      organization_list.setOnRefreshListener(
          new OnRefreshListener<ListView>() {

            @Override
            public void onRefresh(PullToRefreshBase<ListView> refreshView) {
              // TODO Auto-generated method stub
              // Update the LastUpdatedLabel
              // 此处有bug,在切换页面时候造成底部subview隐藏小时,故在此不显示
              refreshView.getLoadingLayoutProxy().setLastUpdatedLabel("");
              // Do work to refresh the list here.
              if (!isLoading) {
                loadOrganizationData();
              }
            }
          });

      organization_login = (TextView) view.findViewById(R.id.organization_login);
      organization_login.setOnClickListener(
          new TextView.OnClickListener() {

            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              Intent intent = new Intent(getActivity(), LoginActivity.class);
              startActivity(intent);
            }
          });
      organization_login_layout =
          (RelativeLayout) view.findViewById(R.id.organization_login_layout);
      UserModel model = DB.getInstance(getActivity()).getUserModel();
      if (model == null) {
        organization_login_layout.setVisibility(View.VISIBLE);
      } else {
        organization_login_layout.setVisibility(View.GONE);
        new Handler()
            .postDelayed(
                new Runnable() {

                  @Override
                  public void run() {
                    // TODO Auto-generated method stub
                    refreshOrganization();
                  }
                },
                300);
      }
      organization_list_no = (TextView) view.findViewById(R.id.organization_list_no);
    }
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
      parent.removeView(view);
    }
    return view;
  }