androidx.loader.content.CursorLoader Java Examples

The following examples show how to use androidx.loader.content.CursorLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RNSharePathUtil.java    From react-native-share with MIT License 6 votes vote down vote up
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    final String column = MediaStore.MediaColumns.DATA;
    final String[] projection = { column };

    try {
        CursorLoader loader = new CursorLoader(context, uri, projection, selection, selectionArgs, null);
        cursor = loader.loadInBackground();
        if (cursor != null && cursor.moveToFirst()) {
            final int index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(index);
        }
    } finally {
        if (cursor != null) cursor.close();
    }
    return null;
}
 
Example #2
Source File: TVShowProgressFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Uri uri;

    int hostId = HostManager.getInstance(getActivity()).getHostInfo().getId();
    switch (id) {
        case LOADER_NEXT_EPISODES:
            // Load seasons
            uri = MediaContract.Episodes.buildTVShowEpisodesListUri(hostId, itemId, NEXT_EPISODES_COUNT);
            String selection = MediaContract.EpisodesColumns.PLAYCOUNT + "=0";
            return new CursorLoader(getActivity(), uri,
                                    NextEpisodesListQuery.PROJECTION, selection, null, NextEpisodesListQuery.SORT);
        case LOADER_SEASONS:
            // Load seasons
            uri = MediaContract.Seasons.buildTVShowSeasonsListUri(hostId, itemId);
            return new CursorLoader(getActivity(), uri,
                                    SeasonsListQuery.PROJECTION, null, null, SeasonsListQuery.SORT);
        default:
            return null;
    }
}
 
Example #3
Source File: ContactsLoaderCallback.java    From tindroid with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // If this is the loader for finding contacts in the Contacts Provider
    if (id == mID) {
        mSearchTerm = args != null ? args.getString(ARG_SEARCH_TERM) : null;

        String[] selectionArgs = null;
        String selection = ContactsQuery.SELECTION;
        if (mSearchTerm != null) {
            selection = ContactsQuery.SELECTION + ContactsQuery.SELECTION_FILTER;
            selectionArgs = new String[]{mSearchTerm + "%"};
        }

        return new CursorLoader(mContext,
                ContactsQuery.CONTENT_URI,
                ContactsQuery.PROJECTION,
                selection,
                selectionArgs,
                ContactsQuery.SORT_ORDER);
    }

    throw new IllegalArgumentException("Unknown loader ID "+id);
}
 
Example #4
Source File: BlankFragment.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Loader onCreateLoader(int id, @Nullable Bundle args) {
    Uri baseUri;
    if (mCurFilter != null) {
        baseUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI,
                Uri.encode(mCurFilter));
    } else {
        baseUri = ContactsContract.Contacts.CONTENT_URI;
    }

    // Now create and return a CursorLoader that will take care of
    // creating a Cursor for the data being displayed.
    String select = "((" + ContactsContract.Contacts.DISPLAY_NAME + " NOTNULL) AND ("
            + ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1) AND ("
            + ContactsContract.Contacts.DISPLAY_NAME + " != '' ))";
    return new CursorLoader(getActivity(), baseUri,
            CONTACTS_SUMMARY_PROJECTION, select, null,
            ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
}
 
Example #5
Source File: CastFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    int hostId = HostManager.getInstance(getActivity()).getHostInfo().getId();

    Uri uri;
    int itemId = getArguments().getInt(BUNDLE_ITEMID);

    if (id == TYPE.MOVIE.ordinal()) {
        uri = MediaContract.MovieCast.buildMovieCastListUri(hostId, itemId);
        return new CursorLoader(getActivity(), uri,
                                MovieCastListQuery.PROJECTION, null, null, MovieCastListQuery.SORT);
    } else {
        uri = MediaContract.TVShowCast.buildTVShowCastListUri(hostId, itemId);
        return new CursorLoader(getActivity(), uri,
                                TVShowCastListQuery.PROJECTION, null, null, TVShowCastListQuery.SORT);
    }
}
 
Example #6
Source File: AlbumLoader.java    From Matisse with Apache License 2.0 6 votes vote down vote up
public static CursorLoader newInstance(Context context) {
    String selection;
    String[] selectionArgs;
    if (SelectionSpec.getInstance().onlyShowGif()) {
        selection = beforeAndroidTen()
                ? SELECTION_FOR_SINGLE_MEDIA_GIF_TYPE : SELECTION_FOR_SINGLE_MEDIA_GIF_TYPE_29;
        selectionArgs = getSelectionArgsForSingleMediaGifType(
                MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
    } else if (SelectionSpec.getInstance().onlyShowImages()) {
        selection = beforeAndroidTen()
                ? SELECTION_FOR_SINGLE_MEDIA_TYPE : SELECTION_FOR_SINGLE_MEDIA_TYPE_29;
        selectionArgs = getSelectionArgsForSingleMediaType(
                MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
    } else if (SelectionSpec.getInstance().onlyShowVideos()) {
        selection = beforeAndroidTen()
                ? SELECTION_FOR_SINGLE_MEDIA_TYPE : SELECTION_FOR_SINGLE_MEDIA_TYPE_29;
        selectionArgs = getSelectionArgsForSingleMediaType(
                MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO);
    } else {
        selection = beforeAndroidTen() ? SELECTION : SELECTION_29;
        selectionArgs = SELECTION_ARGS;
    }
    return new AlbumLoader(context, selection, selectionArgs);
}
 
Example #7
Source File: MediaSetsLoader.java    From YImagePicker with Apache License 2.0 6 votes vote down vote up
public static CursorLoader create(Context context, Set<MimeType> mimeTypeSet, boolean isLoadVideo, boolean isLoadImage) {
    int index = 0;
    String mimeSelection = "";
    ArrayList<String> arrayList = MimeType.getMimeTypeList(mimeTypeSet);
    String[] selectionArgs = new String[arrayList.size()];
    for (String mimeType : arrayList) {
        selectionArgs[index] = mimeType;
        mimeSelection = String.format("%s =? OR %s", MIME_TYPE, mimeSelection);
        index++;
    }

    if (mimeSelection.endsWith(" OR ")) {
        mimeSelection = mimeSelection.substring(0, mimeSelection.length() - 4);
    }
    String selection = "(" + MEDIA_TYPE + "=" + MEDIA_TYPE_VIDEO + " OR " + MEDIA_TYPE + "=" + MEDIA_TYPE_IMAGE + ")" +
            " AND " +
            SIZE + ">0" +
            " AND (" +
            mimeSelection + ")";
    return new MediaSetsLoader(context, selection, selectionArgs, isLoadVideo, isLoadImage);
}
 
Example #8
Source File: ChannelDatabaseService.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Loader<Cursor> getSearchCursorForGroupsLoader(final String searchString) {

        return new CursorLoader(context, null, null, null, null, MobiComDatabaseHelper.CHANNEL_DISPLAY_NAME + " asc") {
            @Override
            public Cursor loadInBackground() {

                SQLiteDatabase db = dbHelper.getReadableDatabase();
                Cursor cursor;

                StringBuffer stringBuffer = new StringBuffer();

                stringBuffer.append("SELECT ").append(" * ").
                        append(" FROM ").append(MobiComDatabaseHelper.CHANNEL).append(" where ").append(MobiComDatabaseHelper.TYPE).append(" NOT IN ('").append(Channel.GroupType.CONTACT_GROUP.getValue()).append("')");

                if (!TextUtils.isEmpty(searchString)) {
                    stringBuffer.append(" AND " + MobiComDatabaseHelper.CHANNEL_DISPLAY_NAME + " like '%" + searchString.replaceAll("'", "''") + "%'");
                }
                stringBuffer.append(" order by " + MobiComDatabaseHelper.CHANNEL_DISPLAY_NAME + " COLLATE NOCASE asc ");
                cursor = db.rawQuery(stringBuffer.toString(), null);

                return cursor;

            }
        };
    }
 
Example #9
Source File: LoaderCreator.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
public static CursorLoader create(Context context, int id, Bundle bundle) {
    LocalFileLoader loader = null;
    switch (id) {
        case ALL_BOOK_FILE:
            loader = new LocalFileLoader(context);
            break;
        default:
            loader = null;
            break;
    }
    if (loader != null) {
        return loader;
    }

    throw new IllegalArgumentException("The id of Loader is invalid!");
}
 
Example #10
Source File: MusicVideoListFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
@Override
protected CursorLoader createCursorLoader() {
    HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
    Uri uri = MediaContract.MusicVideos.buildMusicVideosListUri(hostInfo != null ? hostInfo.getId() : -1);

    String selection = null;
    String selectionArgs[] = null;
    String searchFilter = getSearchFilter();
    if (!TextUtils.isEmpty(searchFilter)) {
        selection = MediaContract.MusicVideosColumns.TITLE + " LIKE ?";
        selectionArgs = new String[] {"%" + searchFilter + "%"};
    }

    return new CursorLoader(getActivity(), uri,
            MusicVideosListQuery.PROJECTION, selection, selectionArgs, MusicVideosListQuery.SORT);
}
 
Example #11
Source File: ArtistInfoFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    Uri uri;
    switch (i) {
        case LOADER_ARTIST:
            uri = MediaContract.Artists.buildArtistUri(getHostInfo().getId(), getDataHolder().getId());
            return new CursorLoader(getActivity(), uri,
                                    DetailsQuery.PROJECTION, null, null, null);
        case LOADER_SONGS:
            uri = MediaContract.Songs.buildArtistSongsListUri(getHostInfo().getId(), getDataHolder().getId());
            return new CursorLoader(getActivity(), uri,
                                    SongsListQuery.PROJECTION, null, null, SongsListQuery.SORT);
        default:
            return null;
    }
}
 
Example #12
Source File: ArtistListFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
@Override
protected CursorLoader createCursorLoader() {
    HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
    Uri uri = MediaContract.Artists.buildArtistsListUri(hostInfo != null ? hostInfo.getId() : -1);

    String selection = null;
    String selectionArgs[] = null;
    String searchFilter = getSearchFilter();
    if (!TextUtils.isEmpty(searchFilter)) {
        selection = MediaContract.ArtistsColumns.ARTIST + " LIKE ?";
        selectionArgs = new String[] {"%" + searchFilter + "%"};
    }

    return new CursorLoader(getActivity(), uri,
            ArtistListQuery.PROJECTION, selection, selectionArgs, ArtistListQuery.SORT);
}
 
Example #13
Source File: AudioGenresListFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
@Override
protected CursorLoader createCursorLoader() {
    HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
    Uri uri = MediaContract.AudioGenres.buildAudioGenresListUri(hostInfo != null ? hostInfo.getId() : -1);

    String selection = null;
    String selectionArgs[] = null;
    String searchFilter = getSearchFilter();
    if (!TextUtils.isEmpty(searchFilter)) {
        selection = MediaContract.AudioGenres.TITLE + " LIKE ?";
        selectionArgs = new String[] {"%" + searchFilter + "%"};
    }

    return new CursorLoader(getActivity(), uri,
            AudioGenreListQuery.PROJECTION, selection, selectionArgs, AudioGenreListQuery.SORT);
}
 
Example #14
Source File: TVShowEpisodeListFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
@Override
protected CursorLoader createCursorLoader() {
    HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
    Uri uri = MediaContract.Episodes.buildTVShowSeasonEpisodesListUri(hostInfo.getId(), tvshowId, tvshowSeason);

    // Filters
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    StringBuilder selection = new StringBuilder();
    if (preferences.getBoolean(Settings.KEY_PREF_TVSHOW_EPISODES_FILTER_HIDE_WATCHED, Settings.DEFAULT_PREF_TVSHOW_EPISODES_FILTER_HIDE_WATCHED)) {
        selection.append(MediaContract.EpisodesColumns.PLAYCOUNT)
                 .append("=0");
    }

    return new CursorLoader(getActivity(), uri,
                            EpisodesListQuery.PROJECTION, selection.toString(), null, EpisodesListQuery.SORT);
}
 
Example #15
Source File: LoaderCreator.java    From a with GNU General Public License v3.0 6 votes vote down vote up
public static CursorLoader create(Context context, int id, Bundle bundle) {
    LocalFileLoader loader = null;
    switch (id) {
        case ALL_BOOK_FILE:
            loader = new LocalFileLoader(context);
            break;
        default:
            loader = null;
            break;
    }
    if (loader != null) {
        return loader;
    }

    throw new IllegalArgumentException("The id of Loader is invalid!");
}
 
Example #16
Source File: AlbumInfoFragment.java    From Kore with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    Uri uri;
    int albumId = getDataHolder().getId();
    int id = HostManager.getInstance(getActivity()).getHostInfo().getId();
    switch (i) {
        case LOADER_ALBUM:
            uri = MediaContract.Albums.buildAlbumUri(id, albumId);
            return new CursorLoader(getActivity(), uri,
                                    AlbumDetailsQuery.PROJECTION, null, null, null);
        default:
            return null;
    }
}
 
Example #17
Source File: TVShowEpisodeInfoFragment.java    From Kore with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    Uri uri;
    switch (i) {
        case LOADER_EPISODE:
            uri = MediaContract.Episodes.buildTVShowEpisodeUri(getHostInfo().getId(), tvshowId,
                                                               getDataHolder().getId());
            return new CursorLoader(getActivity(), uri,
                                    EpisodeDetailsQuery.PROJECTION, null, null, null);
        default:
            return null;
    }
}
 
Example #18
Source File: MainFragment.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (id == CATEGORY_LOADER) {
        return new CursorLoader(
                getContext(),
                VideoContract.VideoEntry.CONTENT_URI, // Table to query
                new String[]{"DISTINCT " + VideoContract.VideoEntry.COLUMN_CATEGORY},
                // Only categories
                null, // No selection clause
                null, // No selection arguments
                null  // Default sort order
        );
    } else {
        // Assume it is for a video.
        String category = args.getString(VideoContract.VideoEntry.COLUMN_CATEGORY);

        // This just creates a CursorLoader that gets all videos.
        return new CursorLoader(
                getContext(),
                VideoContract.VideoEntry.CONTENT_URI, // Table to query
                null, // Projection to return - null means return all fields
                VideoContract.VideoEntry.COLUMN_CATEGORY + " = ?", // Selection clause
                new String[]{category},  // Select based on the category id.
                null // Default sort order
        );
    }
}
 
Example #19
Source File: TVShowInfoFragment.java    From Kore with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    Uri uri = MediaContract.TVShows.buildTVShowUri(getHostInfo().getId(), getDataHolder().getId());
    return new CursorLoader(getActivity(), uri,
                            TVShowDetailsQuery.PROJECTION, null, null, null);

}
 
Example #20
Source File: MovieInfoFragment.java    From Kore with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    Uri uri;
    switch (i) {
        case LOADER_MOVIE:
            uri = MediaContract.Movies.buildMovieUri(getHostInfo().getId(), getDataHolder().getId());
            return new CursorLoader(getActivity(), uri,
                                    MovieDetailsQuery.PROJECTION, null, null, null);
        default:
            return null;
    }
}
 
Example #21
Source File: UARTLogFragment.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NonNull
@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
	switch (id) {
		case LOG_REQUEST_ID: {
			return new CursorLoader(requireContext(), logSession.getSessionEntriesUri(), LOG_PROJECTION, null, null, LogContract.Log.TIME);
		}
	}
	throw new UnsupportedOperationException("Could not create loader with ID " + id);
}
 
Example #22
Source File: MainFragment.java    From androidtv-Leanback with Apache License 2.0 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (id == CATEGORY_LOADER) {
        return new CursorLoader(
                getContext(),
                VideoContract.VideoEntry.CONTENT_URI, // Table to query
                new String[]{"DISTINCT " + VideoContract.VideoEntry.COLUMN_CATEGORY},
                // Only categories
                null, // No selection clause
                null, // No selection arguments
                null  // Default sort order
        );
    } else {
        // Assume it is for a video.
        String category = args.getString(VideoContract.VideoEntry.COLUMN_CATEGORY);

        // This just creates a CursorLoader that gets all videos.
        return new CursorLoader(
                getContext(),
                VideoContract.VideoEntry.CONTENT_URI, // Table to query
                null, // Projection to return - null means return all fields
                VideoContract.VideoEntry.COLUMN_CATEGORY + " = ?", // Selection clause
                new String[]{category},  // Select based on the category id.
                null // Default sort order
        );
    }
}
 
Example #23
Source File: PlaybackFragment.java    From androidtv-Leanback with Apache License 2.0 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // When loading related videos or videos for the playlist, query by category.
    String category = args.getString(VideoContract.VideoEntry.COLUMN_CATEGORY);
    return new CursorLoader(
            getActivity(),
            VideoContract.VideoEntry.CONTENT_URI,
            null,
            VideoContract.VideoEntry.COLUMN_CATEGORY + " = ?",
            new String[] {category},
            null);
}
 
Example #24
Source File: VideoDetailsFragment.java    From androidtv-Leanback with Apache License 2.0 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {
        case RELATED_VIDEO_LOADER: {
            String category = args.getString(VideoContract.VideoEntry.COLUMN_CATEGORY);
            return new CursorLoader(
                    getActivity(),
                    VideoContract.VideoEntry.CONTENT_URI,
                    null,
                    VideoContract.VideoEntry.COLUMN_CATEGORY + " = ?",
                    new String[]{category},
                    null
            );
        }
        default: {
            // Loading video from global search.
            String videoId = args.getString(VideoContract.VideoEntry._ID);
            return new CursorLoader(
                    getActivity(),
                    VideoContract.VideoEntry.CONTENT_URI,
                    null,
                    VideoContract.VideoEntry._ID + " = ?",
                    new String[]{videoId},
                    null
            );
        }
    }

}
 
Example #25
Source File: SearchFragment.java    From androidtv-Leanback with Apache License 2.0 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String query = mQuery;
    return new CursorLoader(
            getActivity(),
            VideoContract.VideoEntry.CONTENT_URI,
            null, // Return all fields.
            VideoContract.VideoEntry.COLUMN_NAME + " LIKE ? OR " +
                    VideoContract.VideoEntry.COLUMN_DESC + " LIKE ?",
            new String[]{"%" + query + "%", "%" + query + "%"},
            null // Default sort order
    );
}
 
Example #26
Source File: VerticalGridFragment.java    From androidtv-Leanback with Apache License 2.0 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(
            getActivity(),
            VideoContract.VideoEntry.CONTENT_URI,
            null, // projection
            null, // selection
            null, // selection clause
            null  // sort order
    );
}
 
Example #27
Source File: SettingsListFragment.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1)
{
    return new CursorLoader(mContext, TaskContract.TaskLists.getContentUri(mAuthority), new String[] {
            TaskContract.TaskLists._ID,
            TaskContract.TaskLists.LIST_NAME, TaskContract.TaskLists.LIST_COLOR, TaskContract.TaskLists.SYNC_ENABLED, TaskContract.TaskLists.VISIBLE,
            TaskContract.TaskLists.ACCOUNT_NAME, TaskContract.TaskLists.ACCOUNT_TYPE }, mListSelectionArguments, mListSelectionParam,
            TaskContract.TaskLists.ACCOUNT_NAME + " COLLATE NOCASE ASC");
}
 
Example #28
Source File: SongsListFragment.java    From Kore with Apache License 2.0 5 votes vote down vote up
@Override
protected CursorLoader createCursorLoader() {
    Uri uri;
    HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
    int hostId = hostInfo != null ? hostInfo.getId() : -1;

    if (artistId != -1) { // get songs for artist
        uri = MediaContract.Songs.buildArtistSongsListUri(hostId, artistId);
    } else if (albumId != -1) {
        uri = MediaContract.Songs.buildAlbumSongsListUri(hostId, albumId);
    } else { // get all songs
        uri = MediaContract.Songs.buildSongsListUri(hostId);
    }

    String selection = null;
    String selectionArgs[] = null;
    String searchFilter = getSearchFilter();
    if (!TextUtils.isEmpty(searchFilter)) {
        selection = MediaDatabase.Tables.SONGS + "." + MediaContract.Songs.TITLE + " LIKE ?";
        selectionArgs = new String[] {"%" + searchFilter + "%"};
    }

    if (albumId != -1) {
        return new CursorLoader(getActivity(), uri,
                                AlbumSongsListQuery.PROJECTION, selection, selectionArgs, AlbumSongsListQuery.SORT);
    } else {
        return new CursorLoader(getActivity(), uri,
                                SongsListQuery.PROJECTION, selection, selectionArgs, SongsListQuery.SORT);
    }
}
 
Example #29
Source File: PlaybackFragment.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // When loading related videos or videos for the playlist, query by category.
    String category = args.getString(VideoContract.VideoEntry.COLUMN_CATEGORY);
    return new CursorLoader(
            getActivity(),
            VideoContract.VideoEntry.CONTENT_URI,
            null,
            VideoContract.VideoEntry.COLUMN_CATEGORY + " = ?",
            new String[] {category},
            null);
}
 
Example #30
Source File: VideoDetailsFragment.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {
        case RELATED_VIDEO_LOADER: {
            String category = args.getString(VideoContract.VideoEntry.COLUMN_CATEGORY);
            return new CursorLoader(
                    getActivity(),
                    VideoContract.VideoEntry.CONTENT_URI,
                    null,
                    VideoContract.VideoEntry.COLUMN_CATEGORY + " = ?",
                    new String[]{category},
                    null
            );
        }
        default: {
            // Loading video from global search.
            String videoId = args.getString(VideoContract.VideoEntry._ID);
            return new CursorLoader(
                    getActivity(),
                    VideoContract.VideoEntry.CONTENT_URI,
                    null,
                    VideoContract.VideoEntry._ID + " = ?",
                    new String[]{videoId},
                    null
            );
        }
    }

}