下载任务和任务调度部分代码之前已经发过了,这里只发UI相关部分代码:
/**
* <The trouble with the world is that the stupid are sure and the intelligent are full of doubt.>
* <p>
* HappyBaby
* <p>
* 作者:Jacky.Ao on 2018/2/26 15:23
* <p>
* 邮箱: jiazhi.ao@gmail.com
*/
public class ResourceFragment extends Fragment implements
ResourceListViewAdapter.OnDeleteClickListener, ResourceListViewAdapter.OnItemClickListener {
@Bind(R.id.download_tab)
Button downloadTab;
@Bind(R.id.downloading_tab)
Button downloadingTab;
@Bind(R.id.download_listview)
RecyclerView downloadListview;
private int hlIndex = 1;
private ResourceListViewAdapter resourceListViewAdapter;
private TaskDispatcher taskDispatcher;
public ResourceFragment() {
// Required empty public constructor
}
public static ResourceFragment newInstance() {
return new ResourceFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_resource, container, false);
ButterKnife.bind(this, view);
init();
return view;
}
private void init() {
taskDispatcher = TaskDispatcher.getInstance();
downloadListview.setLayoutManager(new WrapLinearLayoutManager(getActivity()));
downloadListview.setItemAnimator(new DefaultItemAnimator());
downloadListview.addItemDecoration(new RecycleViewDivider(getActivity(), LinearLayoutManager.VERTICAL));
resourceListViewAdapter = new ResourceListViewAdapter(getContext(),
hlIndex == 0 ? taskDispatcher.getDownloadedList() : taskDispatcher.getQueueTaskList(), this, this);
downloadListview.setAdapter(resourceListViewAdapter);
if (hlIndex == 0) {
downloadTab.setBackgroundResource(R.drawable.tab_radius_left);
downloadingTab.setBackgroundResource(android.R.color.transparent);
} else {
downloadingTab.setBackgroundResource(R.drawable.tab_radius_right);
downloadTab.setBackgroundResource(android.R.color.transparent);
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
ButterKnife.unbind(this);
}
@OnClick({R.id.download_tab, R.id.downloading_tab})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.download_tab:
updateTabUI(R.id.download_tab);
break;
case R.id.downloading_tab: