Search in sources :

Example 1 with DownloadMission

use of us.shandian.giga.get.DownloadMission in project NewPipe by TeamNewPipe.

the class DownloadMissionSQLiteHelper method getMissionFromCursor.

public static DownloadMission getMissionFromCursor(Cursor cursor) {
    if (cursor == null)
        throw new NullPointerException("cursor is null");
    int pos;
    String name = cursor.getString(cursor.getColumnIndexOrThrow(KEY_NAME));
    String location = cursor.getString(cursor.getColumnIndexOrThrow(KEY_LOCATION));
    String url = cursor.getString(cursor.getColumnIndexOrThrow(KEY_URL));
    DownloadMission mission = new DownloadMission(name, url, location);
    mission.done = cursor.getLong(cursor.getColumnIndexOrThrow(KEY_DONE));
    mission.timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(KEY_TIMESTAMP));
    mission.finished = true;
    return mission;
}
Also used : DownloadMission(us.shandian.giga.get.DownloadMission)

Example 2 with DownloadMission

use of us.shandian.giga.get.DownloadMission in project NewPipe by TeamNewPipe.

the class MissionAdapter method buildPopup.

private void buildPopup(final ViewHolder h) {
    PopupMenu popup = new PopupMenu(mContext, h.menu);
    popup.inflate(R.menu.mission);
    Menu menu = popup.getMenu();
    MenuItem start = menu.findItem(R.id.start);
    MenuItem pause = menu.findItem(R.id.pause);
    MenuItem view = menu.findItem(R.id.view);
    MenuItem delete = menu.findItem(R.id.delete);
    MenuItem checksum = menu.findItem(R.id.checksum);
    // Set to false first
    start.setVisible(false);
    pause.setVisible(false);
    view.setVisible(false);
    delete.setVisible(false);
    checksum.setVisible(false);
    if (!h.mission.finished) {
        if (!h.mission.running) {
            if (h.mission.errCode == -1) {
                start.setVisible(true);
            }
            delete.setVisible(true);
        } else {
            pause.setVisible(true);
        }
    } else {
        view.setVisible(true);
        delete.setVisible(true);
        checksum.setVisible(true);
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            switch(id) {
                case R.id.start:
                    mManager.resumeMission(h.position);
                    mBinder.onMissionAdded(mManager.getMission(h.position));
                    return true;
                case R.id.pause:
                    mManager.pauseMission(h.position);
                    mBinder.onMissionRemoved(mManager.getMission(h.position));
                    h.lastTimeStamp = -1;
                    h.lastDone = -1;
                    return true;
                case R.id.view:
                    File f = new File(h.mission.location, h.mission.name);
                    String ext = Utility.getFileExt(h.mission.name);
                    Log.d(TAG, "Viewing file: " + f.getAbsolutePath() + " ext: " + ext);
                    if (ext == null) {
                        Log.w(TAG, "Can't view file because it has no extension: " + h.mission.name);
                        return false;
                    }
                    String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext.substring(1));
                    Log.v(TAG, "Mime: " + mime + " package: " + mContext.getApplicationContext().getPackageName() + ".provider");
                    if (f.exists()) {
                        viewFileWithFileProvider(f, mime);
                    } else {
                        Log.w(TAG, "File doesn't exist");
                    }
                    return true;
                case R.id.delete:
                    mManager.deleteMission(h.position);
                    notifyDataSetChanged();
                    return true;
                case R.id.md5:
                case R.id.sha1:
                    DownloadMission mission = mManager.getMission(h.position);
                    new ChecksumTask().execute(mission.location + "/" + mission.name, ALGORITHMS.get(id));
                    return true;
                default:
                    return false;
            }
        }
    });
    popup.show();
}
Also used : DownloadMission(us.shandian.giga.get.DownloadMission) MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu) Menu(android.view.Menu) File(java.io.File) PopupMenu(android.widget.PopupMenu)

Example 3 with DownloadMission

use of us.shandian.giga.get.DownloadMission in project NewPipe by TeamNewPipe.

the class DownloadManagerImplTest method resumeMission.

@Test
public void resumeMission() throws Exception {
    DownloadMission mission = missions.get(0);
    mission.running = true;
    verify(mission, never()).start();
    downloadManager.resumeMission(0);
    verify(mission, never()).start();
    mission.running = false;
    downloadManager.resumeMission(0);
    verify(mission, times(1)).start();
}
Also used : DownloadMission(us.shandian.giga.get.DownloadMission) Test(org.junit.Test)

Example 4 with DownloadMission

use of us.shandian.giga.get.DownloadMission in project NewPipe by TeamNewPipe.

the class DownloadManagerImplTest method startMission.

@Ignore
@Test
public void startMission() throws Exception {
    DownloadMission mission = missions.get(0);
    mission = spy(mission);
    missions.set(0, mission);
    String url = "https://github.com/favicon.ico";
    // create a temp file and delete it so we have a temp directory
    File tempFile = File.createTempFile("favicon", ".ico");
    String name = tempFile.getName();
    String location = tempFile.getParent();
    assertTrue(tempFile.delete());
    int id = downloadManager.startMission(url, location, name, true, 10);
}
Also used : DownloadMission(us.shandian.giga.get.DownloadMission) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with DownloadMission

use of us.shandian.giga.get.DownloadMission in project NewPipe by TeamNewPipe.

the class DownloadManagerImplTest method deleteMission.

@Test
public void deleteMission() throws Exception {
    DownloadMission mission = missions.get(0);
    assertEquals(mission, downloadManager.getMission(0));
    downloadManager.deleteMission(0);
    verify(mission, times(1)).delete();
    assertNotEquals(mission, downloadManager.getMission(0));
    assertEquals(49, downloadManager.getCount());
}
Also used : DownloadMission(us.shandian.giga.get.DownloadMission) Test(org.junit.Test)

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