use of us.shandian.giga.get.DownloadManagerImpl in project NewPipe by TeamNewPipe.
the class DownloadManagerImplTest method setUp.
@org.junit.Before
public void setUp() throws Exception {
dowloadDataSource = mock(DownloadDataSource.class);
missions = new ArrayList<>();
for (int i = 0; i < 50; ++i) {
missions.add(generateFinishedDownloadMission());
}
when(dowloadDataSource.loadMissions()).thenReturn(new ArrayList<>(missions));
downloadManager = new DownloadManagerImpl(new ArrayList<String>(), dowloadDataSource);
}
use of us.shandian.giga.get.DownloadManagerImpl 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.DownloadManagerImpl in project NewPipe by TeamNewPipe.
the class DownloadManagerService method onCreate.
@Override
public void onCreate() {
super.onCreate();
if (DEBUG) {
Log.d(TAG, "onCreate");
}
mBinder = new DMBinder();
if (mDataSource == null) {
mDataSource = new SQLiteDownloadDataSource(this);
}
if (mManager == null) {
ArrayList<String> paths = new ArrayList<>(2);
paths.add(NewPipeSettings.getVideoDownloadPath(this));
paths.add(NewPipeSettings.getAudioDownloadPath(this));
mManager = new DownloadManagerImpl(paths, mDataSource);
if (DEBUG) {
Log.d(TAG, "mManager == null");
Log.d(TAG, "Download directory: " + paths);
}
}
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.setClass(this, DownloadActivity.class);
Drawable icon = this.getResources().getDrawable(R.mipmap.ic_launcher);
Builder builder = new Builder(this).setContentIntent(PendingIntent.getActivity(this, 0, i, 0)).setSmallIcon(android.R.drawable.stat_sys_download).setLargeIcon(((BitmapDrawable) icon).getBitmap()).setContentTitle(getString(R.string.msg_running)).setContentText(getString(R.string.msg_running_detail));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, DownloadActivity.class).setAction(DownloadActivity.INTENT_LIST), PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
mNotification = builder.build();
HandlerThread thread = new HandlerThread("ServiceMessenger");
thread.start();
mHandler = new Handler(thread.getLooper()) {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
case UPDATE_MESSAGE:
{
int runningCount = 0;
for (int i = 0; i < mManager.getCount(); i++) {
if (mManager.getMission(i).running) {
runningCount++;
}
}
updateState(runningCount);
break;
}
}
}
};
}
Aggregations