Search in sources :

Example 6 with DownloadMission

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);
}
Also used : RandomAccessFile(java.io.RandomAccessFile) DownloadMission(us.shandian.giga.get.DownloadMission) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 7 with 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));
    }
}
Also used : DownloadDataSource(us.shandian.giga.get.DownloadDataSource) DownloadManagerImpl(us.shandian.giga.get.DownloadManagerImpl) ArrayList(java.util.ArrayList) DownloadMission(us.shandian.giga.get.DownloadMission) Test(org.junit.Test)

Example 8 with DownloadMission

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();
}
Also used : DownloadMission(us.shandian.giga.get.DownloadMission) Test(org.junit.Test)

Example 9 with DownloadMission

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;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DownloadMission(us.shandian.giga.get.DownloadMission) Cursor(android.database.Cursor)

Example 10 with DownloadMission

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);
}
Also used : Utility(us.shandian.giga.util.Utility) DownloadMission(us.shandian.giga.get.DownloadMission) ProgressDrawable(us.shandian.giga.ui.common.ProgressDrawable)

Aggregations

DownloadMission (us.shandian.giga.get.DownloadMission)10 Test (org.junit.Test)5 File (java.io.File)3 RandomAccessFile (java.io.RandomAccessFile)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 PopupMenu (android.widget.PopupMenu)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 DownloadDataSource (us.shandian.giga.get.DownloadDataSource)1 DownloadManagerImpl (us.shandian.giga.get.DownloadManagerImpl)1 ProgressDrawable (us.shandian.giga.ui.common.ProgressDrawable)1 Utility (us.shandian.giga.util.Utility)1