public class MainActivity extends AppCompatActivity implements MainView {
private RecyclerView left;
private RecyclerView right;
private MainPersenterlml mainPersenterlml;
private List<LeftBean.ResultBean> list;
private LeftBean leftbean;
private LeftAdapter adapter;
private GridLayoutManager gridLayoutManager;
private RightBean rightBean;
private RightAdapter rightadapter;
private List<RightBean.ResultBean> rightlist;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
left = findViewById(R.id.recycle_left);
right = findViewById(R.id.recycle_right);
// 左侧适配器
adapter = new LeftAdapter(this);
left.setAdapter(adapter);
// 左侧布局管理器
LinearLayoutManager manager = new LinearLayoutManager(this);
manager.setOrientation(LinearLayoutManager.VERTICAL);
left.setLayoutManager(manager);
// 调用P层
mainPersenterlml = new MainPersenterlml(new MainModellml(), this);
// 右侧适配器
rightadapter = new RightAdapter(this);
// 右侧布局管理器
gridLayoutManager = new GridLayoutManager(this, 3);
right.setLayoutManager(gridLayoutManager);
right.setAdapter(rightadapter);
mainPersenterlml.doleft(0);
adapter.OnClickLisener(new LeftAdapter.OnClickListener() {
@Override
public void onItemClick(int position) {
String id = list.get(position).getId();
mainPersenterlml.doright(1,id);
adapter.notifyDataSetChanged();
}
});
}
@Override
public void success(int type, String data) {
if (type==0){
leftbean = new Gson().fromJson(data, LeftBean.class);
list = leftbean.getResult();
adapter.setList(list);
}else {
rightBean = new Gson().fromJson(data, RightBean.class);
rightlist = rightBean.getResult();
rightadapter.setList(rightlist);
}
}
@Override
public void fail(String error) {
}
}