public void init() { mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); setAdapter(mRowsAdapter); setBrandColor(getResources().getColor(R.color.primary)); setBadgeDrawable(getResources().getDrawable(R.drawable.filmi)); for (int position = 0; position < HEADERS.length; position++) { ObjectAdapter rowContents = new CursorObjectAdapter((new SinglePresenterSelector(new CardPresenter()))); VideoDataManager manager = new VideoDataManager( getActivity(), getLoaderManager(), VideoItemContract.VideoItem.buildDirUri(), rowContents); manager.startDataLoading(); HeaderItem headerItem = new HeaderItem(position, HEADERS[position], null); mRowsAdapter.add(new ListRow(headerItem, manager.getItemList())); } setOnItemViewClickedListener(getDefaultItemViewClickedListener()); setOnItemViewSelectedListener(getDefaultItemSelectedListener()); bgHelper = new BackgroundHelper(getActivity()); bgHelper.prepareBackgroundManager(); }
@Override protected void onHandleIntent(Intent intent) { ContentProviderClient client = getContentResolver() .acquireContentProviderClient(VideoItemContract.VideoItem.buildDirUri()); try { Cursor cursor = client.query( VideoItemContract.VideoItem.buildDirUri(), VideoDataManager.PROJECTION, null, null, VideoItemContract.VideoItem.DEFAULT_SORT); VideoDataManager.VideoItemMapper mapper = new VideoDataManager.VideoItemMapper(); mapper.bindColumns(cursor); NotificationManager mNotificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); Log.d(TAG, mNotificationManager == null ? "It's null" : mNotificationManager.toString()); int count = 1; while (cursor.moveToNext() && count <= MAX_RECOMMENDATIONS) { Video video = mapper.bind(cursor); PendingIntent pendingIntent = buildPendingIntent(video); Bundle extras = new Bundle(); extras.putString(EXTRA_BACKGROUND_IMAGE_URL, video.getThumbUrl()); Bitmap image = Picasso.with(getApplicationContext()) .load(video.getThumbUrl()) .resize( VideoDetailsFragment.dpToPx(DETAIL_THUMB_WIDTH, getApplicationContext()), VideoDetailsFragment.dpToPx(DETAIL_THUMB_HEIGHT, getApplicationContext())) .get(); Notification notification = new NotificationCompat.BigPictureStyle( new NotificationCompat.Builder(getApplicationContext()) .setContentTitle(video.getTitle()) .setContentText(video.getDescription()) .setPriority(4) .setLocalOnly(true) .setOngoing(true) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary)) // .setCategory(Notification.CATEGORY_RECOMMENDATION) .setCategory("recommendation") .setLargeIcon(image) .setSmallIcon(R.drawable.ic_stat_f) .setContentIntent(pendingIntent) .setExtras(extras)) .build(); mNotificationManager.notify(count, notification); count++; } cursor.close(); } catch (RemoteException re) { Log.e(TAG, "Cannot query VideoItems", re); } catch (IOException re) { Log.e(TAG, "Cannot download thumbnail", re); } finally { client.release(); } }