@Override public void onClick(View v) { if (v instanceof PrefixVideoChildItem) { PrefixVideoChildItem item = (PrefixVideoChildItem) v; if (item.data.state != PrefixVideo.STATE_COMPLETE) return; synchronized (adapter.dataSource) { PrefixVideo lastSelected = null; for (PrefixVideoGroup i : adapter.dataSource) { for (PrefixVideo j : i.items) { if (j.selected) { lastSelected = j; } } } if (lastSelected == item.data) { selected = null; item.data.selected = false; } else { if (lastSelected != null) { lastSelected.selected = false; } item.data.selected = true; selected = item.data; } adapter.notifyDataSetChanged(); } } else if (v.getId() == R.id.action_container) { PrefixVideo info = (PrefixVideo) v.getTag(); switch (info.state) { case PrefixVideo.STATE_DESCRIPTION: ELog.i("STATE_DOWNLOAD"); info.state = PrefixVideo.STATE_DOWNLOAD; break; case PrefixVideo.STATE_DOWNLOAD: case PrefixVideo.STATE_DOWNLOADING: ELog.i("STATE_DOWNLOADING"); info.state = PrefixVideo.STATE_DOWNLOADING; download(info); break; } adapter.notifyDataSetChanged(); } else if (v.getId() == R.id.progress) { PrefixVideo info = (PrefixVideo) v.getTag(); ELog.e("State:" + info.state); if (info.state == PrefixVideo.STATE_DOWNLOADING) { if (info.downloadTask.isDownloading()) { disconnect(info); } else { download(info); } } } }
@Override public boolean handleMessage(Message msg) { if (msg.what == HANDLER_UPDATE) { if (!adapter.isEmpty()) { host.progressContainer.setVisibility(View.GONE); } adapter.notifyDataSetChanged(); } return false; }
private void disconnect(PrefixVideo info) { info.downloadTask.disconnect(); adapter.notifyDataSetChanged(); }
private void download(PrefixVideo info) { info.state = PrefixVideo.STATE_DOWNLOADING; adapter.notifyDataSetChanged(); App.THREAD.execute(info.downloadTask); }