use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.
the class DownloadManager method startAllDownload.
void startAllDownload() {
boolean update = false;
// Start all STATE_NONE and STATE_FAILED item
LinkedList<DownloadInfo> allInfoList = mAllInfoList;
LinkedList<DownloadInfo> waitList = mWaitList;
for (DownloadInfo info : allInfoList) {
if (info.state == DownloadInfo.STATE_NONE || info.state == DownloadInfo.STATE_FAILED) {
update = true;
// Set state DownloadInfo.STATE_WAIT
info.state = DownloadInfo.STATE_WAIT;
// Add to wait list
waitList.add(info);
// Update in DB
EhDB.putDownloadInfo(info);
}
}
if (update) {
// Notify Listener
for (DownloadInfoListener l : mDownloadInfoListeners) {
l.onUpdateAll();
}
// Ensure download
ensureDownload();
}
}
use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.
the class DownloadsScene method onClickSecondaryFab.
@Override
public void onClickSecondaryFab(FabLayout view, FloatingActionButton fab, int position) {
Context context = getContext2();
Activity activity = getActivity2();
EasyRecyclerView recyclerView = mRecyclerView;
if (null == context || null == activity || null == recyclerView) {
return;
}
if (0 == position) {
recyclerView.checkAll();
} else {
List<DownloadInfo> list = mList;
if (list == null) {
return;
}
LongList gidList = null;
List<DownloadInfo> downloadInfoList = null;
// Start, Stop, Delete
boolean collectGid = position == 1 || position == 2 || position == 3;
// Delete or Move
boolean collectDownloadInfo = position == 3 || position == 4;
if (collectGid) {
gidList = new LongList();
}
if (collectDownloadInfo) {
downloadInfoList = new LinkedList<>();
}
SparseBooleanArray stateArray = recyclerView.getCheckedItemPositions();
for (int i = 0, n = stateArray.size(); i < n; i++) {
if (stateArray.valueAt(i)) {
DownloadInfo info = list.get(stateArray.keyAt(i));
if (collectDownloadInfo) {
downloadInfoList.add(info);
}
if (collectGid) {
gidList.add(info.gid);
}
}
}
switch(position) {
case 1:
{
// Start
Intent intent = new Intent(activity, DownloadService.class);
intent.setAction(DownloadService.ACTION_START_RANGE);
intent.putExtra(DownloadService.KEY_GID_LIST, gidList);
activity.startService(intent);
// Cancel check mode
recyclerView.outOfCustomChoiceMode();
break;
}
case 2:
{
// Stop
if (null != mDownloadManager) {
mDownloadManager.stopRangeDownload(gidList);
}
// Cancel check mode
recyclerView.outOfCustomChoiceMode();
break;
}
case 3:
{
// Delete
CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(context, getString(R.string.download_remove_dialog_message_2, gidList.size()), getString(R.string.download_remove_dialog_check_text), Settings.getRemoveImageFiles());
DeleteRangeDialogHelper helper = new DeleteRangeDialogHelper(downloadInfoList, gidList, builder);
builder.setTitle(R.string.download_remove_dialog_title).setPositiveButton(android.R.string.ok, helper).show();
break;
}
case 4:
{
// Move
List<DownloadLabel> labelRawList = EhApplication.getDownloadManager(context).getLabelList();
List<String> labelList = new ArrayList<>(labelRawList.size() + 1);
labelList.add(getString(R.string.default_download_label_name));
for (int i = 0, n = labelRawList.size(); i < n; i++) {
labelList.add(labelRawList.get(i).getLabel());
}
String[] labels = labelList.toArray(new String[labelList.size()]);
MoveDialogHelper helper = new MoveDialogHelper(labels, downloadInfoList);
new AlertDialog.Builder(context).setTitle(R.string.download_move_dialog_title).setItems(labels, helper).show();
break;
}
}
}
}
use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.
the class DownloadsScene method handleArguments.
private boolean handleArguments(Bundle args) {
if (null == args) {
return false;
}
if (ACTION_CLEAR_DOWNLOAD_SERVICE.equals(args.getString(KEY_ACTION))) {
DownloadService.clear();
}
long gid;
if (null != mDownloadManager && -1L != (gid = args.getLong(KEY_GID, -1L))) {
DownloadInfo info = mDownloadManager.getDownloadInfo(gid);
if (null != info) {
mLabel = info.getLabel();
updateForLabel();
updateView();
// Get position
if (null != mList) {
int position = mList.indexOf(info);
if (position >= 0 && null != mRecyclerView) {
mRecyclerView.scrollToPosition(position);
} else {
mInitPosition = position;
}
}
return true;
}
}
return false;
}
use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.
the class DownloadsScene method onItemClick.
@Override
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
Activity activity = getActivity2();
EasyRecyclerView recyclerView = mRecyclerView;
if (null == activity || null == recyclerView) {
return false;
}
if (recyclerView.isInCustomChoice()) {
recyclerView.toggleItemChecked(position);
return true;
} else {
List<DownloadInfo> list = mList;
if (list == null) {
return false;
}
if (position < 0 && position >= list.size()) {
return false;
}
Intent intent = new Intent(activity, GalleryActivity.class);
intent.setAction(GalleryActivity.ACTION_EH);
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, list.get(position));
startActivity(intent);
return true;
}
}
use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.
the class EhDB method getAllDownloadInfo.
public static synchronized List<DownloadInfo> getAllDownloadInfo() {
DownloadsDao dao = sDaoSession.getDownloadsDao();
List<DownloadInfo> list = dao.queryBuilder().orderDesc(DownloadsDao.Properties.Time).list();
// Fix state
for (DownloadInfo info : list) {
if (info.state == DownloadInfo.STATE_WAIT || info.state == DownloadInfo.STATE_DOWNLOAD) {
info.state = DownloadInfo.STATE_NONE;
}
}
return list;
}
Aggregations