Beispiel #1
0
  @Override
  protected void init() {
    baseActivity = (BaseActivity) getActivity();
    eGifts = new ArrayList<EGift>();
    loadingListener =
        new LoadingListener(
            baseActivity,
            srlLayout,
            rvList,
            new IMultiValueReturnHandle() {

              @Override
              public Object handle(Object... obj) {
                try {
                  Thread.sleep(1000);
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
                int page = ((Integer) obj[0]);
                String searchQuery = ((String) obj[1]);
                if (page == LoadingListener.INIT_PAGE) {
                  eGifts.clear();
                }
                int i = eGifts.size();
                int j = i + 10;
                for (; i < j; i++) {
                  eGifts.add(new EGift());
                }
                return eGifts.size() >= 50 ? true : false;
              }
            },
            new IMultiValueReturnHandle() {

              @Override
              public Object handle(Object... obj) {
                int page = (Integer) obj[0];
                if (page == LoadingListener.INIT_PAGE) {
                  rvList.post(
                      new Runnable() {
                        public void run() {
                          Utils.updRvListScroll(baseActivity, rvList, clLayout);
                        }
                      });
                }

                // boolean isAllLoadingComplete = (Boolean) obj[1];
                // if (isAllLoadingComplete && datas.size() == 0) {
                // ll404.setVisibility(View.VISIBLE);
                // }
                return null;
              }
            });
    Utils.initSrlLayout(
        baseActivity,
        srlLayout,
        new ISimpleHandle() {
          @Override
          public void handle() {
            loadingListener.setSearchQuery(null);
            loadingListener.loading(true, null);
          }
        });
    Utils.initRvList(
        baseActivity, rvList, new AdapterMyGift(baseActivity, eGifts, loadingListener));
  }
Beispiel #2
0
  @Override
  protected void init() {
    baseActivity = (BaseActivity) getActivity();
    eFleaMarkets = new ArrayList<EFleaMarket>();
    loadingListener =
        new LoadingListener(
            baseActivity,
            srlLayout,
            rvList,
            new IMultiValueReturnHandle() {

              @Override
              public Object handle(Object... obj) {
                try {
                  Thread.sleep(1000);
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
                int page = ((Integer) obj[0]);
                String searchQuery = ((String) obj[1]);
                if (page == LoadingListener.INIT_PAGE) {
                  eFleaMarkets.clear();
                }
                int i = eFleaMarkets.size();
                int j = i + 9;
                for (; i < j; i++) {
                  eFleaMarkets.add(new EFleaMarket());
                }
                return eFleaMarkets.size() >= 300 ? true : false;
              }
            },
            null);
    Utils.initSrlLayout(
        baseActivity,
        srlLayout,
        new ISimpleHandle() {
          @Override
          public void handle() {
            loadingListener.setSearchQuery(null);
            loadingListener.loading(true, null);
          }
        });
    List<EActivity> eActivities = new ArrayList<EActivity>();
    for (int i = 0; i < 3; i++) {
      EActivity eActivity = new EActivity();
      eActivity.Image =
          "http://img14.360buyimg.com/da/jfs/t2251/329/208071985/101581/32b7678d/55f7dae2N22ac3c64.jpg";
      eActivities.add(eActivity);
    }
    adapterFleaMarket =
        new AdapterFleaMarket(baseActivity, eFleaMarkets, eActivities, loadingListener, this);
    gridLayoutManager = new GridLayoutManager(baseActivity, 3);
    gridLayoutManager.setSpanSizeLookup(
        new GridLayoutManager.SpanSizeLookup() {
          @Override
          public int getSpanSize(int position) {
            switch (adapterFleaMarket.getItemViewType(position)) {
              case AdapterFleaMarket.TYPE_ACTIVITY:
              case AdapterFleaMarket.TYPE_ACTION:
              case AdapterFleaMarket.TYPE_FOOTER:
              case AdapterFleaMarket.TYPE_LINEAR:
                return 3;
              case AdapterFleaMarket.TYPE_ITEM:
                return 1;
            }
            return 1;
          }
        });
    int spacing = Utils.getDPValue(baseActivity, 8);
    rvList.addItemDecoration(
        new GridSpacingItemDecoration(
            new IMultiValueReturnHandle() {
              @Override
              public Object handle(Object... obj) {
                Rect outRect = (Rect) obj[0];
                int position = (int) obj[1];
                int spacing = (int) obj[2];
                switch (adapterFleaMarket.getItemViewType(position)) {
                  case AdapterFleaMarket.TYPE_ACTIVITY:
                  case AdapterFleaMarket.TYPE_ACTION:
                    return true;
                  case AdapterFleaMarket.TYPE_FOOTER:
                  case AdapterFleaMarket.TYPE_LINEAR:
                    outRect.left = spacing;
                    outRect.right = spacing;
                    outRect.bottom = spacing;
                    return true;
                  case AdapterFleaMarket.TYPE_ITEM:
                    return false;
                }
                return false;
              }
            },
            3,
            spacing,
            true));
    Utils.initRvList(baseActivity, rvList, gridLayoutManager, adapterFleaMarket);
  }