ChannelsRow.java revision 816a4be1a0f34f6a48877c8afd3dbbca19eac435
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.tv.menu; 18 19import android.content.Context; 20 21import com.android.tv.R; 22import com.android.tv.common.TvCommonConstants; 23import com.android.tv.recommendation.RecentChannelEvaluator; 24import com.android.tv.recommendation.Recommender; 25 26public class ChannelsRow extends ItemListRow { 27 public static final String ID = ChannelsRow.class.getName(); 28 29 private static final int MIN_COUNT_FOR_RECENT_CHANNELS = 5; 30 private static final int MAX_COUNT_FOR_RECENT_CHANNELS = 10; 31 32 private Recommender mTvRecommendation; 33 private ChannelsRowAdapter mChannelsAdapter; 34 private ChannelsPosterPrefetcher mChannelsPosterPrefetcher; 35 36 public ChannelsRow(Context context) { 37 super(context, 38 TvCommonConstants.IS_MNC_OR_HIGHER 39 ? R.string.menu_title_channels : R.string.menu_title_channels_legacy, 40 R.dimen.card_layout_height, 41 null); 42 mTvRecommendation = new Recommender(getContext(), new Recommender.Listener() { 43 @Override 44 public void onRecommenderReady() { 45 mChannelsAdapter.update(); 46 mChannelsPosterPrefetcher.prefetch(); 47 } 48 49 @Override 50 public void onRecommendationChanged() { 51 mChannelsAdapter.update(); 52 mChannelsPosterPrefetcher.prefetch(); 53 } 54 }, true); 55 mTvRecommendation.registerEvaluator(new RecentChannelEvaluator()); 56 mChannelsAdapter = new ChannelsRowAdapter(context, mTvRecommendation, 57 MIN_COUNT_FOR_RECENT_CHANNELS, MAX_COUNT_FOR_RECENT_CHANNELS); 58 setAdapter(mChannelsAdapter); 59 mChannelsPosterPrefetcher = new ChannelsPosterPrefetcher(context, 60 getMainActivity().getProgramDataManager(), mChannelsAdapter); 61 } 62 63 @Override 64 public void release() { 65 super.release(); 66 mTvRecommendation.release(); 67 mTvRecommendation = null; 68 } 69 70 /** 71 * Handle the update event of the recent channel. 72 */ 73 public void onRecentChannelUpdated() { 74 mChannelsPosterPrefetcher.prefetch(); 75 } 76 77 @Override 78 public String getId() { 79 return ID; 80 } 81} 82