use of us.shandian.giga.get.DownloadMission in project NewPipe by TeamNewPipe.
the class DownloadManagerImplTest method generateFinishedDownloadMission.
private static DownloadMission generateFinishedDownloadMission() throws IOException {
File file = File.createTempFile("newpipetest", ".mp4");
file.deleteOnExit();
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
randomAccessFile.setLength(1000);
randomAccessFile.close();
DownloadMission downloadMission = new DownloadMission(file.getName(), "http://google.com/?q=how+to+google", file.getParent());
downloadMission.blocks = 1000;
downloadMission.done = 1000;
downloadMission.finished = true;
return spy(downloadMission);
}
use of us.shandian.giga.get.DownloadMission in project NewPipe by TeamNewPipe.
the class DownloadManagerImplTest method testThatMissionsAreLoaded.
@Test
public void testThatMissionsAreLoaded() throws IOException {
ArrayList<DownloadMission> missions = new ArrayList<>();
long millis = System.currentTimeMillis();
for (int i = 0; i < 50; ++i) {
DownloadMission mission = generateFinishedDownloadMission();
// reverse order by timestamp
mission.timestamp = millis - i;
missions.add(mission);
}
dowloadDataSource = mock(DownloadDataSource.class);
when(dowloadDataSource.loadMissions()).thenReturn(new ArrayList<>(missions));
downloadManager = new DownloadManagerImpl(new ArrayList<String>(), dowloadDataSource);
verify(dowloadDataSource, times(1)).loadMissions();
assertEquals(50, downloadManager.getCount());
for (int i = 0; i < 50; ++i) {
assertMissionEquals("mission " + i, missions.get(50 - 1 - i), downloadManager.getMission(i));
}
}
use of us.shandian.giga.get.DownloadMission in project NewPipe by TeamNewPipe.
the class DownloadManagerImplTest method pauseMission.
@Test
public void pauseMission() throws Exception {
DownloadMission mission = missions.get(0);
mission.running = false;
downloadManager.pauseMission(0);
verify(mission, never()).pause();
mission.running = true;
downloadManager.pauseMission(0);
verify(mission, times(1)).pause();
}
use of us.shandian.giga.get.DownloadMission in project NewPipe by TeamNewPipe.
the class SQLiteDownloadDataSource method loadMissions.
@Override
public List<DownloadMission> loadMissions() {
ArrayList<DownloadMission> result;
SQLiteDatabase database = downloadMissionSQLiteHelper.getReadableDatabase();
Cursor cursor = database.query(MISSIONS_TABLE_NAME, null, null, null, null, null, DownloadMissionSQLiteHelper.KEY_TIMESTAMP);
int count = cursor.getCount();
if (count == 0)
return new ArrayList<>();
result = new ArrayList<>(count);
while (cursor.moveToNext()) {
result.add(DownloadMissionSQLiteHelper.getMissionFromCursor(cursor));
}
return result;
}
use of us.shandian.giga.get.DownloadMission in project NewPipe by TeamNewPipe.
the class MissionAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(MissionAdapter.ViewHolder h, int pos) {
DownloadMission ms = mManager.getMission(pos);
h.mission = ms;
h.position = pos;
Utility.FileType type = Utility.getFileType(ms.name);
h.icon.setImageResource(Utility.getIconForFileType(type));
h.name.setText(ms.name);
h.size.setText(Utility.formatBytes(ms.length));
h.progress = new ProgressDrawable(mContext, Utility.getBackgroundForFileType(type), Utility.getForegroundForFileType(type));
h.bkg.setBackgroundDrawable(h.progress);
h.observer = new MissionObserver(this, h);
ms.addListener(h.observer);
updateProgress(h);
}
Aggregations