コード例 #1
0
  @Override
  protected void initViewsAndEvents() {
    swipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.app_theme_color));
    swipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            goodPage = 1;
            firstGetData = true;
            getSelfGoods();
          }
        });

    listView.setOnLoadMoreListener(
        new LoadMoreListView.OnLoadMoreListener() {
          @Override
          public void onLoadMore() {
            goodPage++;
            getSelfGoods();
          }
        });

    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {}
        });
  }
コード例 #2
0
  // 获取自己的商品列表
  private void getSelfGoods() {
    if (firstGetData) {
      toggleShowLoading(true, null);
    }

    if (!NetUtils.isNetworkConnected(mContext)) {
      showNetWorkError();
      if (firstGetData) {
        toggleNetworkError(true, getGoodsClickListener);
      }
      listView.setLoading(false);
      swipeRefreshLayout.setRefreshing(false);
      return;
    }

    ApiManager.getService(mContext)
        .getSelfGoods(
            goodPage,
            is_active,
            null,
            new Callback<GetSelfGoodsRes>() {
              @Override
              public void success(GetSelfGoodsRes getSelfGoodsRes, Response response) {
                if (getSelfGoodsRes != null) {
                  listView.setLoading(false);
                  swipeRefreshLayout.setRefreshing(false);

                  if (goodPage == 1 && getSelfGoodsRes.getGoods().size() == 0) {
                    toggleShowEmpty(true, getString(R.string.no_good), null);
                    return;
                  }

                  if (goodPage != 1 && getSelfGoodsRes.getGoods().size() == 0) {
                    showToast(getString(R.string.no_more));
                    return;
                  }

                  if (is_active == 1) {
                    if (firstGetData) {
                      onSaleListAdapter =
                          new OnSaleListAdapter(
                              mContext,
                              getSelfGoodsRes.getGoods(),
                              OnSaleListAdapter.ViewHolder.class);
                      listView.setAdapter(onSaleListAdapter);
                      onSaleListAdapter.setOnGoodPullOffClickListener(
                          new OnSaleListAdapter.OnGoodPullOffClickListener() {
                            @Override
                            public void onPullOffClick(String good_id, int position) {
                              initProgressDialog();
                              progressDialog.setContent(mContext.getString(R.string.in_pull_off));
                              progressDialog.show();
                              updateGoodInfo(good_id, 0);
                            }
                          });

                      onSaleListAdapter.setOnGoodEditClickListener(
                          new OnSaleListAdapter.OnGoodEditClickListener() {
                            @Override
                            public void onEditClick(String good_id) {
                              Bundle bundle = new Bundle();
                              bundle.putInt(EditGoodInfoAct.IN_WAY, EditGoodInfoAct.IN_FROM_EDIT);
                              bundle.putString(EditGoodInfoAct.GOOD_ID, good_id);
                              readyGo(EditGoodInfoAct.class, bundle);
                            }
                          });
                      toggleRestore();
                      firstGetData = false;
                    } else {
                      onSaleListAdapter.addEntities(getSelfGoodsRes.getGoods());
                      onSaleListAdapter.notifyDataSetChanged();
                    }
                  } else {
                    if (firstGetData) {
                      pullOffListAdapter =
                          new PullOffListAdapter(
                              mContext,
                              getSelfGoodsRes.getGoods(),
                              PullOffListAdapter.ViewHolder.class);
                      listView.setAdapter(pullOffListAdapter);
                      pullOffListAdapter.setOnGoodEditClickListener(
                          new PullOffListAdapter.OnGoodEditClickListener() {
                            @Override
                            public void onEditClick(String good_id) {
                              Bundle bundle = new Bundle();
                              bundle.putInt(EditGoodInfoAct.IN_WAY, EditGoodInfoAct.IN_FROM_EDIT);
                              bundle.putString(EditGoodInfoAct.GOOD_ID, good_id);
                              readyGo(EditGoodInfoAct.class, bundle);
                            }
                          });

                      pullOffListAdapter.setOnGoodSaleClickListener(
                          new PullOffListAdapter.OnGoodSaleClickListener() {
                            @Override
                            public void onSaleClick(String good_id, int position) {
                              initProgressDialog();
                              progressDialog.setContent(mContext.getString(R.string.in_pull_off));
                              progressDialog.show();
                              updateGoodInfo(good_id, 1);
                            }
                          });
                      toggleRestore();
                      firstGetData = false;
                    } else {
                      pullOffListAdapter.addEntities(getSelfGoodsRes.getGoods());
                      pullOffListAdapter.notifyDataSetChanged();
                    }
                  }
                }
              }

              @Override
              public void failure(RetrofitError error) {
                if (goodPage == 1) {
                  toggleShowEmpty(true, null, getGoodsClickListener);
                } else {
                  showInnerError(error);
                }
                listView.setLoading(false);
                swipeRefreshLayout.setRefreshing(false);
              }
            });
  }