public class MainActivity extends AppCompatActivity implements Contract.Iview {
private Presenter presenter;
private RecyclerView recycler_frist;
private SouView sou_view;
private ImageView image_list;
private RecyclerView recycler_second;
private LayoutInflater view;
private RecyclerView recycler_view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sou_view = findViewById(R.id.sou_view);
image_list = sou_view.findViewById(R.id.image_list);
presenter = new Presenter();
presenter.attch(this);
image_list.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
presenter.show(Api_URL.SHOW_URL);
}
});
recycler_view = findViewById(R.id.recycler_view);
}
@Override
public void getRequest(String data) {
view = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View inflate = view.inflate(R.layout.pop_first,null);
recycler_frist = inflate.findViewById(R.id.recycler_frist);
Gson gson = new Gson();
ShowBean showBean = gson.fromJson(data, ShowBean.class);
final List<ShowBean.ResultBean> result = showBean.getResult();
ShowAdapter showAdapter = new ShowAdapter(result, this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recycler_frist.setLayoutManager(linearLayoutManager);
recycler_frist.setAdapter(showAdapter);
showAdapter.setOnclik(new ShowAdapter.OnClick() {
@Override
public void onClick(int i) {
String id = result.get(i).getId();
presenter.showTow(Api_URL.SHOW2_URL+"?firstCategoryId="+id);
}
});
PopupWindow popupWindow = new PopupWindow(inflate, ActionBar.LayoutParams.FILL_PARENT,
ActionBar.LayoutParams.WRAP_CONTENT);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
//设置颜色
ColorDrawable colorDrawable = new ColorDrawable((Color.GRAY));
popupWindow.setBackgroundDrawable(colorDrawable);
popupWindow.showAsDropDown(image_list);
}
@Override
public void getTowRequest(String data) {
View inflate1 = view.inflate(R.layout.pop_second,null);
recycler_second = inflate1.findViewById(R.id.recycler_second);
Gson gson = new Gson();
ShowBean showBean = gson.fromJson(data, ShowBean.class);
final List<ShowBean.ResultBean> result = showBean.getResult();
ShowAdapter showAdapter = new ShowAdapter(result, this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recycler_second.setLayoutManager(linearLayoutManager);
recycler_second.setAdapter(showAdapter);
showAdapter.setOnclik(new ShowAdapter.OnClick() {
@Override
public void onClick(int i) {
String id = result.get(i).getId();
presenter.showThree(Api_URL.SHOW3_URL+"?categoryId="+id+"&page="+1+"&count="+5);
}
});
PopupWindow popupWindow = new PopupWindow(inflate1, ActionBar.LayoutParams.FILL_PARENT,
ActionBar.LayoutParams.WRAP_CONTENT);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
//设置颜色
ColorDrawable colorDrawable = new ColorDrawable((Color.GRAY));
popupWindow.setBackgroundDrawable(colorDrawable);
popupWindow.showAsDropDown(image_list,50,50);
}
@Override
public void getThreeRequest(String data) {
Gson gson = new Gson();
ListBean listBean = gson.fromJson(data, ListBean.class);
List<ListBean.ResultBean> result = listBean.getResult();
ListAdapter listAdapter = new ListAdapter(result, this);
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
recycler_view.setLayoutManager(gridLayoutManager);
recycler_view.setAdapter(listAdapter);
}
@Override
protected void onDestroy() {
super.onDestroy();
presenter.detch();
}
}