Search in sources :

Example 1 with DownloadManagerImpl

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

Example 2 with DownloadManagerImpl

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));
    }
}
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 3 with DownloadManagerImpl

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;
                    }
            }
        }
    };
}
Also used : DownloadManagerImpl(us.shandian.giga.get.DownloadManagerImpl) Message(android.os.Message) SQLiteDownloadDataSource(us.shandian.giga.get.sqlite.SQLiteDownloadDataSource) Builder(android.support.v4.app.NotificationCompat.Builder) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) HandlerThread(android.os.HandlerThread) PendingIntent(android.app.PendingIntent)

Aggregations

ArrayList (java.util.ArrayList)3 DownloadManagerImpl (us.shandian.giga.get.DownloadManagerImpl)3 DownloadDataSource (us.shandian.giga.get.DownloadDataSource)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Handler (android.os.Handler)1 HandlerThread (android.os.HandlerThread)1 Message (android.os.Message)1 Builder (android.support.v4.app.NotificationCompat.Builder)1 Test (org.junit.Test)1 DownloadMission (us.shandian.giga.get.DownloadMission)1 SQLiteDownloadDataSource (us.shandian.giga.get.sqlite.SQLiteDownloadDataSource)1