use of zlc.season.rxdownload2.entity.DownloadRecord in project RxDownload by ssseasonnn.
the class DownloadManagerActivity method loadData.
private void loadData() {
RxDownload.getInstance(this).getTotalDownloadRecords().map(new Function<List<DownloadRecord>, List<DownloadItem>>() {
@Override
public List<DownloadItem> apply(List<DownloadRecord> downloadRecords) throws Exception {
List<DownloadItem> result = new ArrayList<>();
for (DownloadRecord each : downloadRecords) {
DownloadItem bean = new DownloadItem();
bean.record = each;
result.add(bean);
}
return result;
}
}).subscribe(new Consumer<List<DownloadItem>>() {
@Override
public void accept(List<DownloadItem> downloadBeen) throws Exception {
mAdapter.addAll(downloadBeen);
}
});
}
use of zlc.season.rxdownload2.entity.DownloadRecord in project RxDownload by ssseasonnn.
the class DataBaseHelper method readMissionsRecord.
/**
* Read missionId all records.
*
* @param missionId missionId
* @return Records
*/
public List<DownloadRecord> readMissionsRecord(String missionId) {
Cursor cursor = null;
try {
cursor = getReadableDatabase().query(TABLE_NAME, new String[] { COLUMN_ID, COLUMN_URL, COLUMN_SAVE_NAME, COLUMN_SAVE_PATH, COLUMN_DOWNLOAD_SIZE, COLUMN_TOTAL_SIZE, COLUMN_IS_CHUNKED, COLUMN_EXTRA1, COLUMN_EXTRA2, COLUMN_EXTRA3, COLUMN_EXTRA4, COLUMN_EXTRA5, COLUMN_DOWNLOAD_FLAG, COLUMN_DATE, COLUMN_MISSION_ID }, COLUMN_MISSION_ID + "=?", new String[] { missionId }, null, null, null);
List<DownloadRecord> result = new ArrayList<>();
cursor.moveToFirst();
if (cursor.getCount() > 0) {
do {
result.add(read(cursor));
} while (cursor.moveToNext());
}
return result;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
use of zlc.season.rxdownload2.entity.DownloadRecord in project RxDownload by ssseasonnn.
the class DownloadService method deleteAll.
/**
* Delete all mission which associate with missionId.
*
* @param missionId missionId
* @param deleteFile deleteFile?
*/
public void deleteAll(String missionId, boolean deleteFile) {
DownloadMission mission = missionMap.get(missionId);
if (mission != null && mission instanceof MultiMission) {
mission.delete(dataBaseHelper, deleteFile);
missionMap.remove(missionId);
} else {
createProcessor(missionId, processorMap).onNext(normal(null));
if (deleteFile) {
List<DownloadRecord> list = dataBaseHelper.readMissionsRecord(missionId);
for (DownloadRecord each : list) {
deleteFiles(getFiles(each.getSaveName(), each.getSavePath()));
dataBaseHelper.deleteRecord(each.getUrl());
}
}
}
}
use of zlc.season.rxdownload2.entity.DownloadRecord in project RxDownload by ssseasonnn.
the class DownloadService method receiveDownloadEvent.
/**
* Receive the url download event.
* <p>
* Will receive the following event:
* {@link DownloadFlag#NORMAL}、{@link DownloadFlag#WAITING}、
* {@link DownloadFlag#STARTED}、{@link DownloadFlag#PAUSED}、
* {@link DownloadFlag#COMPLETED}、{@link DownloadFlag#FAILED};
* <p>
* Every event has {@link DownloadStatus}, you can get it and display it on the interface.
*
* @param url url
* @return DownloadEvent
*/
public FlowableProcessor<DownloadEvent> receiveDownloadEvent(String url) {
FlowableProcessor<DownloadEvent> processor = createProcessor(url, processorMap);
DownloadMission mission = missionMap.get(url);
if (mission == null) {
//Not yet add this url mission.
DownloadRecord record = dataBaseHelper.readSingleRecord(url);
if (record == null) {
processor.onNext(normal(null));
} else {
File file = getFiles(record.getSaveName(), record.getSavePath())[0];
if (file.exists()) {
processor.onNext(createEvent(record.getFlag(), record.getStatus()));
} else {
processor.onNext(normal(null));
}
}
}
return processor;
}
use of zlc.season.rxdownload2.entity.DownloadRecord in project RxDownload by ssseasonnn.
the class DownloadService method deleteDownload.
/**
* Delete download.
* <p>
* Delete a url or all tasks belonging to missionId.
*
* @param url url or missionId
* @param deleteFile whether delete file
*/
public void deleteDownload(String url, boolean deleteFile) {
DownloadMission mission = missionMap.get(url);
if (mission != null && mission instanceof SingleMission) {
mission.delete(dataBaseHelper, deleteFile);
missionMap.remove(url);
} else {
createProcessor(url, processorMap).onNext(normal(null));
if (deleteFile) {
DownloadRecord record = dataBaseHelper.readSingleRecord(url);
if (record != null) {
deleteFiles(getFiles(record.getSaveName(), record.getSavePath()));
}
}
dataBaseHelper.deleteRecord(url);
}
}
Aggregations