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;
}
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();
}
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();
}
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);
}
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());
}
Aggregations