in LeanbackShowcase/app/src/main/java/androidx/leanback/leanbackshowcase/app/rows/ChannelContents.java [236:303]
private Long addChannel(Context context, ChannelContents channelContents) {
// This ID is associated with current context
String channelInputId = createInputId(context);
Channel channel = new Channel.Builder()
.setDisplayName(channelContents.getName())
.setDescription(channelContents.getDescription())
.setType(TvContractCompat.Channels.TYPE_PREVIEW)
.setInputId(channelInputId)
.setAppLinkIntentUri(Uri.parse(SCHEME + "://" + PACKAGE_NAME
+ "/" + MAIN_ACTIVITY))
.setInternalProviderId(channelContents.getChannelContentsId())
.build();
/**
* The interaction between current app and launcher interface is through ContentProvider
* All the published data should be inserted into content provider
*/
Uri channelUri = context.getContentResolver().insert(TvContractCompat.Channels.CONTENT_URI,
channel.toContentValues());
if (channelUri == null || channelUri.equals(Uri.EMPTY)) {
Log.e(TAG, "Insert channel failed");
/**
* If the task is failed return null as a signal for error handling
*/
return null;
}
long channelId = ContentUris.parseId(channelUri);
sLookupTable.put(channelId, channelContents);
channelContents.setChannelPublishedId(channelId);
createChannelLogo(context, channelId, R.drawable.row_app_icon);
List<VideoContent> videos = channelContents.getVideos();
int weight = videos.size();
for (int i = 0; i < videos.size(); ++i, --weight) {
VideoContent clip = videos.get(i);
final String clipId = clip.getVideoId();
/**
* Enable preview feature for the video added to the home screen
*/
PreviewProgram program = new PreviewProgram.Builder()
.setChannelId(channelId)
.setTitle(clip.getTitle())
.setDescription(clip.getDescription())
.setPosterArtUri(Uri.parse(clip.getCardImageUrl()))
.setIntentUri(Uri.parse(SCHEME + "://" + PACKAGE_NAME
+ "/" + VIDEO_PLAY_ACTIVITY + "/" + clipId))
.setPreviewVideoUri(Uri.parse(clip.getPreviewVideoUrl()))
.setInternalProviderId(clipId)
.setWeight(weight)
.setPosterArtAspectRatio(clip.getAspectRatio())
.setType(TvContractCompat.PreviewPrograms.TYPE_MOVIE)
.build();
Uri preview_uri =
Uri.parse(CONTENT_ANDROID_MEDIA_TV_PREVIEW_PROGRAM);
Uri programUri = context.getContentResolver().insert(preview_uri,
program.toContentValues());
if (programUri == null || programUri.equals(Uri.EMPTY)) {
Log.e(TAG, "Insert program failed");
} else {
clip.setProgramId(ContentUris.parseId(programUri));
}
}
return channelId;
}