多任务下载框架Demo的运用

下载任务和任务调度部分代码之前已经发过了,这里只发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:
    
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值