use of us.shandian.giga.get.sqlite.SQLiteDownloadDataSource 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