|
|
|
@ -3,29 +3,29 @@ package com.android.activity.fragment;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
import androidx.viewpager2.widget.ViewPager2;
|
|
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
|
|
|
|
|
import com.android.R;
|
|
|
|
|
import com.android.activity.adapter.GoodsTypeAdapter;
|
|
|
|
|
import com.android.activity.adapter.GoodsTypeFSAdapter;
|
|
|
|
|
import com.android.bean.Good;
|
|
|
|
|
import com.android.bean.GoodRecords;
|
|
|
|
|
import com.android.bean.GoodsType;
|
|
|
|
|
import com.android.bean.ResponseData;
|
|
|
|
|
import com.android.model.goods.GoodsListener;
|
|
|
|
|
import com.android.model.goods.GoodsModelimpl;
|
|
|
|
|
import com.android.utils.eventBus.EventMsg;
|
|
|
|
|
import com.google.android.material.tabs.TabLayout;
|
|
|
|
|
import com.google.android.material.tabs.TabLayoutMediator;
|
|
|
|
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@ -39,8 +39,8 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
|
|
|
|
|
private Button button;
|
|
|
|
|
private GoodsModelimpl goodsModelimpl;
|
|
|
|
|
private List<GoodsType> goodsTypeList;
|
|
|
|
|
// private GoodsTypeAdapter goodsTypeAdapter = null;
|
|
|
|
|
// private RecyclerView recyclerView;
|
|
|
|
|
private List<Good> goodList;
|
|
|
|
|
private List<Good> typeGoodList;
|
|
|
|
|
private View rootView;
|
|
|
|
|
private GoodsTypeFSAdapter goodsTypeFSAdapter;
|
|
|
|
|
|
|
|
|
@ -59,11 +59,7 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initGoodsTypeData() {
|
|
|
|
|
goodsModelimpl = new GoodsModelimpl();
|
|
|
|
|
goodsModelimpl.getAllGoodsType(this);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
|
@ -74,15 +70,20 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
|
|
|
|
|
container, false);
|
|
|
|
|
Log.e("1","onCreateView");
|
|
|
|
|
initGoodsTypeData();
|
|
|
|
|
return rootView;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void initGoodsTypeData() {
|
|
|
|
|
goodsModelimpl = new GoodsModelimpl();
|
|
|
|
|
goodsModelimpl.getAllGoodsType(this);
|
|
|
|
|
goodsModelimpl.getAllGood(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rootView;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取商品类型成功回调
|
|
|
|
|
@Override
|
|
|
|
|
public void onGetAllGoodsType(ResponseData<List<GoodsType>> responseData) {
|
|
|
|
|
this.goodsTypeList = responseData.getData();
|
|
|
|
@ -93,23 +94,34 @@ public class HomePageFragment extends Fragment implements View.OnClickListener,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取商品成功回调
|
|
|
|
|
@Override
|
|
|
|
|
public void onGetAllGoodSuccess(ResponseData<GoodRecords> responseData) {
|
|
|
|
|
this.goodList = responseData.getData().getRecords();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initRecyclerview() {
|
|
|
|
|
viewPager = rootView.findViewById(R.id.view_pager);
|
|
|
|
|
|
|
|
|
|
// goodsTypeAdapter = new GoodsTypeAdapter(goodsTypeList,context,R.layout.list_good_stype_item);
|
|
|
|
|
// viewPager.setAdapter(goodsTypeAdapter);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<Fragment> fragments = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < goodsTypeList.size(); i++) {
|
|
|
|
|
fragments.add(GoodsTypeFragment.newInstance(goodsTypeList.get(i).getType()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// for (int j = 0; j < goodList.size(); j++) {
|
|
|
|
|
// if(goodList.get(i).getTypeId() == goodsTypeList.get(i).getId()){
|
|
|
|
|
// typeGoodList.add(goodList.get(i));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
fragments.add(GoodsTypeFragment.newInstance(goodsTypeList.get(i).getType(), goodList));
|
|
|
|
|
|
|
|
|
|
//EventBus发布消息
|
|
|
|
|
// EventBus.getDefault().postSticky(new EventMsg<>(goodsTypeList.get(i).getType(),200,goodList));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goodsTypeFSAdapter = new GoodsTypeFSAdapter(getActivity().getSupportFragmentManager(), getLifecycle(),fragments);
|
|
|
|
|
viewPager.setAdapter(goodsTypeFSAdapter);
|
|
|
|
|
//把TabLayout(选项卡布局)和ViewPager2绑定在一起。特别说明一下,下面这行代码是官方给的,特别好使。
|
|
|
|
|
//把TabLayout(选项卡布局)和ViewPager2绑定在一起。特别说明一下,下面这行代码是官方给的,特别好使。
|
|
|
|
|
TabLayout tablayout = rootView.findViewById(R.id.tabLayout);
|
|
|
|
|
new TabLayoutMediator(tablayout, viewPager,
|
|
|
|
|
(tab, position) -> tab.setText(goodsTypeList.get(position).getType())).attach();
|
|
|
|
|