@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); prepareBackgroundManager(); mVideoCursorAdapter = new CursorObjectAdapter(new CardPresenter()); mVideoCursorAdapter.setMapper(mVideoCursorMapper); mSelectedVideo = (Video) getActivity().getIntent() .getParcelableExtra(VideoDetailsActivity.VIDEO); if (mSelectedVideo != null || !hasGlobalSearchIntent()) { removeNotification(getActivity().getIntent() .getIntExtra(VideoDetailsActivity.NOTIFICATION_ID, NO_NOTIFICATION)); setupAdapter(); setupDetailsOverviewRow(); setupMovieListRow(); updateBackground(mSelectedVideo.bgImageUrl); // When a Related Video item is clicked. setOnItemViewClickedListener(new ItemViewClickedListener()); } }
@Override public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor c) { // List of categories if (cursorLoader.getId() == -1) { // Empty view visibility mEmptyView.setVisibility(c.getCount() > 0 ? View.GONE : View.VISIBLE); if (mCurrentCategoriesCursor != null) { if (!isCategoriesListModified(mCurrentCategoriesCursor, c)) { // no actual modification, no need to rebuild all the rows mCurrentCategoriesCursor = c; // keep the reference to the new cursor because the old one won't be valid anymore return; } } mCurrentCategoriesCursor = c; loadCategoriesRows(c); } // One of the row else { CursorObjectAdapter adapter = mAdaptersMap.get(cursorLoader.getId()); if (adapter != null) { adapter.changeCursor(c); } } }
public void init() { mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); setAdapter(mRowsAdapter); setBrandColor(ContextCompat.getColor(getContext(), R.color.primary)); setBadgeDrawable(ContextCompat.getDrawable(getContext(), 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]); mRowsAdapter.add(new ListRow(headerItem, manager.getItemList())); } setOnItemViewClickedListener(getDefaultItemViewClickedListener()); setOnItemViewSelectedListener(getDefaultItemSelectedListener()); bgHelper = new BackgroundHelper(getActivity()); bgHelper.prepareBackgroundManager(); }
public void init() { mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); setAdapter(mRowsAdapter); setBrandColor(ContextCompat.getColor(getContext(), R.color.primary)); setBadgeDrawable(ContextCompat.getDrawable(getContext(), 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]); mRowsAdapter.add(new ListRow(headerItem, manager.getItemList())); } setOnItemViewClickedListener(getDefaultItemViewClickedListener()); }
public void init() { mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); setAdapter(mRowsAdapter); setBrandColor(ContextCompat.getColor(getContext(), R.color.primary)); setBadgeDrawable(ContextCompat.getDrawable(getContext(), 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]); mRowsAdapter.add(new ListRow(headerItem, manager.getItemList())); } }
/** * Creates a ListRow for related videos. */ private void addOtherRows() { mVideoCursorAdapter = new CursorObjectAdapter(new CardPresenter()); mVideoCursorAdapter.setMapper(new VideoCursorMapper()); Bundle args = new Bundle(); args.putString(VideoContract.VideoEntry.COLUMN_CATEGORY, mSelectedVideo.category); getLoaderManager().initLoader(RECOMMENDED_VIDEOS_LOADER, args, this); HeaderItem header = new HeaderItem(getString(R.string.related_movies)); mRowsAdapter.add(new ListRow(header, mVideoCursorAdapter)); }
@Override public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { if (cursorLoader.getId()==SEASONS_LOADER_ID) { //TODO: // CAUTION: we get an update here each time a single episode resume point is changed... // Basic solution: fill the season rows only the first time, i.e. guess it does not change over // time, which is true with the current feature set at least... cursor.moveToFirst(); final int seasonNumberColumn = cursor.getColumnIndex(VideoStore.Video.VideoColumns.SCRAPER_E_SEASON); mSeasonAdapters = new SparseArray<CursorObjectAdapter>(); // Build one row for each season while (!cursor.isAfterLast()) { int seasonNumber = cursor.getInt(seasonNumberColumn); CursorObjectAdapter seasonAdapter = new CursorObjectAdapter(new PosterImageCardPresenter(getActivity(), PosterImageCardPresenter.EpisodeDisplayMode.FOR_SEASON_LIST)); seasonAdapter.setMapper(new CompatibleCursorMapperConverter(new VideoCursorMapper())); mSeasonAdapters.put(seasonNumber, seasonAdapter); mRowsAdapter.add(new ListRow(seasonNumber, new HeaderItem(seasonNumber, "Season " + seasonNumber), seasonAdapter)); getLoaderManager().restartLoader(seasonNumber, null, this); cursor.moveToNext(); } cursor.close(); } else { // We got the list of episode for one season, load it mSeasonAdapters.get(cursorLoader.getId()).changeCursor(cursor); } }
private void loadRows() { mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); mSeasonsAdapter = new CursorObjectAdapter(new SeasonPresenter(getActivity())); mSeasonsAdapter.setMapper(new CompatibleCursorMapperConverter(new SeasonCursorMapper())); mSeasonsListRow = new ListRow( new HeaderItem(getString(R.string.how_to_mark_season_watched)), mSeasonsAdapter); mRowsAdapter.add(mSeasonsListRow); setAdapter(mRowsAdapter); }
public VideoDataManager(Context mContext, LoaderManager mLoaderManager, Uri mRowUri, ObjectAdapter rowContents) { this.mLoaderManager = mLoaderManager; this.mRowUri = mRowUri; this.mContext = mContext; mItemList = rowContents; LOADER_ID = Double.valueOf(Math.random() * Integer.MAX_VALUE).intValue(); mMapper = new VideoItemMapper(); ((CursorObjectAdapter) mItemList).setMapper(mMapper); }
private void addOtherRows() { ObjectAdapter rowContents = new CursorObjectAdapter((new SinglePresenterSelector(new CardPresenter()))); VideoDataManager manager = new VideoDataManager(getActivity(), getLoaderManager(), VideoItemContract.VideoItem.buildDirUri(), rowContents); manager.startDataLoading(); HeaderItem headerItem = new HeaderItem(0, "You may also like"); mRowsAdapter.add(new ListRow(headerItem, manager.getItemList())); }
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { int id = loader.getId(); ObjectAdapter adapter = getAdapter(); ListRow row = (ListRow) adapter.get(id); CursorObjectAdapter rowAdapter = (CursorObjectAdapter) row .getAdapter(); rowAdapter.swapCursor(cursor); }
@Override public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to // onLoadFinished() // above is about to be closed. We need to make sure we are no // longer using it. int id = loader.getId(); ObjectAdapter adapter = getAdapter(); ListRow row = (ListRow) adapter.get(id); CursorObjectAdapter rowAdapter = (CursorObjectAdapter) row .getAdapter(); rowAdapter.swapCursor(null); }
private CursorObjectAdapter setupRelatedVideosCursor() { CursorObjectAdapter videoCursorAdapter = new CursorObjectAdapter(new CardPresenter()); videoCursorAdapter.setMapper(new VideoCursorMapper()); Bundle args = new Bundle(); args.putString(VideoContract.VideoEntry.COLUMN_CATEGORY, mVideo.category); getLoaderManager().initLoader(RELATED_VIDEOS_LOADER, args, mVideoLoaderCallbacks); return videoCursorAdapter; }
private void loadRows() { Log.d(TAG,"loadRows()"); // Two different row presenters, one standard for regular cards, one special for the icon items ListRowPresenter listRowPresenter = new ListRowPresenter(); IconItemRowPresenter iconItemRowPresenter = new IconItemRowPresenter(); // Only way I found to use two different presenter is using a ClassPresenterSelector, hence i needed // to create a dummy IconListRow that does nothing more than a regular ListRow ClassPresenterSelector rowsPresenterSelector = new ClassPresenterSelector(); rowsPresenterSelector.addClassPresenter(ListRow.class, listRowPresenter); rowsPresenterSelector.addClassPresenter(IconListRow.class, iconItemRowPresenter); // Basic header presenter for both row presenters listRowPresenter.setHeaderPresenter(new RowHeaderPresenter()); iconItemRowPresenter.setHeaderPresenter(new RowHeaderPresenter()); mRowsAdapter = new ArrayObjectAdapter(rowsPresenterSelector); mLastAddedAdapter = new CursorObjectAdapter(new PosterImageCardPresenter(getActivity())); mLastAddedAdapter.setMapper(new CompatibleCursorMapperConverter(new VideoCursorMapper())); mLastAddedRow = new ListRow(ROW_ID_LAST_ADDED, new HeaderItem(getString(R.string.recently_added)), mLastAddedAdapter); mRowsAdapter.add(mLastAddedRow); mLastPlayedAdapter = new CursorObjectAdapter(new PosterImageCardPresenter(getActivity())); mLastPlayedAdapter.setMapper(new CompatibleCursorMapperConverter(new VideoCursorMapper())); mLastPlayedRow = new ListRow(ROW_ID_LAST_PLAYED, new HeaderItem(getString(R.string.recently_played)), mLastPlayedAdapter); mRowsAdapter.add(mLastPlayedRow); ArrayObjectAdapter movieRowAdapter = new ArrayObjectAdapter(new BoxItemPresenter()); movieRowAdapter.add(buildAllMoviesBox()); movieRowAdapter.add(new Box(Box.ID.MOVIES_BY_GENRE, getString(R.string.movies_by_genre), R.drawable.genres_banner)); movieRowAdapter.add(new Box(Box.ID.MOVIES_BY_YEAR, getString(R.string.movies_by_year), R.drawable.years_banner)); mRowsAdapter.add(new ListRow(ROW_ID_MOVIES, new HeaderItem(getString(R.string.movies)), movieRowAdapter)); mTvshowsAdapter = new CursorObjectAdapter(new PosterImageCardPresenter(getActivity())); mTvshowsAdapter.setMapper(new CompatibleCursorMapperConverter(new TvshowCursorMapper())); mTvshowsRow = new ListRow(ROW_ID_TVSHOWS, new HeaderItem(getString(R.string.all_tv_shows)), mTvshowsAdapter); mRowsAdapter.add(mTvshowsRow); mFileBrowsingRowAdapter = new ArrayObjectAdapter(new BoxItemPresenter()); mFileBrowsingRowAdapter.add(new Box(Box.ID.NETWORK, getString(R.string.network_storage), R.drawable.filetype_new_server)); mFileBrowsingRowAdapter.add(new Box(Box.ID.FOLDERS, getString(R.string.internal_storage), R.drawable.filetype_new_folder)); mFileBrowsingRowAdapter.add(new Box(Box.ID.VIDEOS_BY_LISTS, getString(R.string.video_lists), R.drawable.filetype_new_playlist)); mNonScrapedVideosItem = new Box(Box.ID.NON_SCRAPED_VIDEOS, getString(R.string.non_scraped_videos), R.drawable.filetype_new_unscraped_video); // Add USB and SDcard items at init ?depending of their availability updateUsbAndSdcardVisibility(); mRowsAdapter.add(new ListRow(ROW_ID_FILES, new HeaderItem(getString(R.string.leanback_browsing)), mFileBrowsingRowAdapter)); mPreferencesRowAdapter = new ArrayObjectAdapter(new IconItemPresenter()); mPreferencesRowAdapter.add(new Icon(Icon.ID.PREFERENCES, getString(R.string.preferences), R.drawable.lollipop_settings)); mPreferencesRowAdapter.add(new Icon(Icon.ID.PRIVATE_MODE, getString(R.string.private_mode_is_on), getString(R.string.private_mode_is_off), R.drawable.private_mode, R.drawable.private_mode_off, PrivateMode.isActive())); mPreferencesRowAdapter.add(new Icon(Icon.ID.LEGACY_UI, getString(R.string.leanback_legacy_ui), R.drawable.legacy_ui_icon)); mPreferencesRowAdapter.add(new Icon(Icon.ID.HELP_FAQ, getString(R.string.help_faq), R.drawable.lollipop_help)); // Must use an IconListRow to have the dedicated presenter used (see ClassPresenterSelector above) mRowsAdapter.add(new IconListRow(ROW_ID_PREFERENCES, new HeaderItem(getString(R.string.preferences)), mPreferencesRowAdapter)); setAdapter(mRowsAdapter); }
private void loadCategoriesRows(Cursor c) { int subsetIdColumn = c.getColumnIndex(MoviesByLoader.COLUMN_SUBSET_ID); int subsetNameColumn = c.getColumnIndex(MoviesByLoader.COLUMN_SUBSET_NAME); int listOfMovieIdsColumn = c.getColumnIndex(MoviesByLoader.COLUMN_LIST_OF_MOVIE_IDS); mRowsAdapter.clear(); mAdaptersMap.clear(); // NOTE: A first version was using a CursorObjectAdapter for the rows. // The problem was that when any DB update occurred (resume point...) I found no way // to not update all the rows. Hence the selection position on the current row was lost. // I tried to not update but the older cursor was closed by the LoaderManager (I think), leading to crashes. // Solution implemented here is to "convert" the cursor into an array. No performance issue since the // number of categories is always quite limited (~100 max) // Build the array of categories from the cursor ArrayList<ListRow> rows = new ArrayList<>(c.getCount()); c.moveToFirst(); while(!c.isAfterLast()) { int subsetId = (int) c.getLong(subsetIdColumn); String subsetName = c.getString(subsetNameColumn); String listOfMovieIds = c.getString(listOfMovieIdsColumn); // Build the row CursorObjectAdapter subsetAdapter = new CursorObjectAdapter(mVideoPresenter); subsetAdapter.setMapper(mVideoMapper); rows.add(new ListRow(new HeaderItem(subsetName), subsetAdapter)); mAdaptersMap.append(subsetId, subsetAdapter); // Start the loader manager for this row Bundle args = new Bundle(); args.putString("ids", listOfMovieIds); args.putString("sort", mSortOrder); getLoaderManager().restartLoader(subsetId, args, this); c.moveToNext(); } mRowsAdapter.addAll(0,rows); }
private void loadCategoriesRows(Cursor c) { int subsetIdColumn = c.getColumnIndex(MoviesByLoader.COLUMN_SUBSET_ID); int subsetNameColumn = c.getColumnIndex(MoviesByLoader.COLUMN_SUBSET_NAME); int listOfMovieIdsColumn = c.getColumnIndex(MoviesByLoader.COLUMN_LIST_OF_MOVIE_IDS); mRowsAdapter.clear(); mAdaptersMap.clear(); // NOTE: A first version was using a CursorObjectAdapter for the rows. // The problem was that when any DB update occurred (resume point...) I found no way // to not update all the rows. Hence the selection position on the current row was lost. // I tried to not update but the older cursor was closed by the LoaderManager (I think), leading to crashes. // Solution implemented here is to "convert" the cursor into an array. No performance issue since the // number of categories is always quite limited (~100 max) // Build the array of categories from the cursor ArrayList<ListRow> rows = new ArrayList<>(c.getCount()); c.moveToFirst(); while(!c.isAfterLast()) { int subsetId = (int) c.getLong(subsetIdColumn); String subsetName = c.getString(subsetNameColumn); String listOfMovieIds = c.getString(listOfMovieIdsColumn); // Build the row CursorObjectAdapter subsetAdapter = new CursorObjectAdapter(mVideoPresenter); subsetAdapter.setMapper(mVideoMapper); rows.add(new ListRow(subsetId, new HeaderItem(subsetName), subsetAdapter)); mAdaptersMap.append(subsetId, subsetAdapter); // Start the loader manager for this row Bundle args = new Bundle(); args.putString("ids", listOfMovieIds); args.putString("sort", mSortOrder); getLoaderManager().restartLoader(subsetId, args, this); c.moveToNext(); } mRowsAdapter.addAll(0,rows); }
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { if (mItemList instanceof CursorObjectAdapter) { ((CursorObjectAdapter) mItemList).swapCursor(cursor); } }
public void onLoaderReset(Loader<Cursor> cursorLoader) { if (mItemList instanceof CursorObjectAdapter) { ((CursorObjectAdapter) mItemList).swapCursor(null); } }
@Override protected void onPostExecute(DetailsOverviewRow detailRow) { ClassPresenterSelector ps = new ClassPresenterSelector(); FullWidthDetailsOverviewRowPresenter detailsPresenter = new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter(getContext())); detailsPresenter.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.primary)); detailsPresenter.setInitialState(FullWidthDetailsOverviewRowPresenter.STATE_FULL); detailsPresenter.setOnActionClickedListener(new OnActionClickedListener() { @Override public void onActionClicked(Action action) { if (action.getId() == ACTION_PLAY) { Intent intent = new Intent(getActivity(), PlayerActivity.class); intent.putExtra(Video.INTENT_EXTRA_VIDEO, selectedVideo); startActivity(intent); } else { Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show(); } } }); ps.addClassPresenter(DetailsOverviewRow.class, detailsPresenter); ps.addClassPresenter(ListRow.class, new ListRowPresenter()); /** bonus code for adding related items to details fragment **/ // <START> ArrayObjectAdapter adapter = new ArrayObjectAdapter(ps); adapter.add(detailRow); String subcategories[] = { "You may also like" }; CursorObjectAdapter rowAdapter = new CursorObjectAdapter(new SinglePresenterSelector(new CardPresenter())); VideoDataManager manager = new VideoDataManager(getActivity(), getLoaderManager(), VideoItemContract.VideoItem.buildDirUri(), rowAdapter); manager.startDataLoading(); HeaderItem header = new HeaderItem(0, subcategories[0]); adapter.add(new ListRow(header, rowAdapter)); setAdapter(adapter); // <END> }