diff options
author | Nick Chalko <nchalko@google.com> | 2016-05-04 11:20:31 -0700 |
---|---|---|
committer | Nick Chalko <nchalko@google.com> | 2016-05-04 11:21:28 -0700 |
commit | 2e1279b8bbe0603fb4399b25b73121bed5953c46 (patch) | |
tree | 83d9dc7e66f196f2da6fb691d5bba5b2ee2b67b9 /src/com/android/tv/menu/ChannelsRowAdapter.java | |
parent | adcc7b8a20af38d03a47f8b7c4ab5eed256f085c (diff) | |
download | TV-2e1279b8bbe0603fb4399b25b73121bed5953c46.tar.gz |
Sync to joey ub-tv-dev at e7fbaa585b1eb7afec05f05032d2e8d99fb595d4
Change-Id: Ib2da547fc0b23c3b504e2fac9c635954fc03060f
Diffstat (limited to 'src/com/android/tv/menu/ChannelsRowAdapter.java')
-rw-r--r-- | src/com/android/tv/menu/ChannelsRowAdapter.java | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/src/com/android/tv/menu/ChannelsRowAdapter.java b/src/com/android/tv/menu/ChannelsRowAdapter.java index 51867d0b..200f4ac0 100644 --- a/src/com/android/tv/menu/ChannelsRowAdapter.java +++ b/src/com/android/tv/menu/ChannelsRowAdapter.java @@ -18,7 +18,9 @@ package com.android.tv.menu; import android.content.Context; import android.content.Intent; +import android.media.tv.TvInputInfo; import android.os.Build; +import android.support.v4.os.BuildCompat; import android.view.View; import com.android.tv.MainActivity; @@ -29,6 +31,8 @@ import com.android.tv.common.feature.CommonFeatures; import com.android.tv.data.Channel; import com.android.tv.recommendation.Recommender; import com.android.tv.util.SetupUtils; +import com.android.tv.util.TvInputManagerHelper; +import com.android.tv.util.Utils; import java.util.ArrayList; import java.util.List; @@ -37,16 +41,16 @@ import java.util.List; * An adapter of the Channels row. */ public class ChannelsRowAdapter extends ItemListRowView.ItemListAdapter<Channel> { - // There are four special cards: guide, setup, dvr, applink. - private static final int SIZE_OF_VIEW_TYPE = 4; + // There are four special cards: guide, setup, dvr, record, applink. + private static final int SIZE_OF_VIEW_TYPE = 5; private final Context mContext; private final Tracker mTracker; private final Recommender mRecommender; private final int mMaxCount; private final int mMinCount; - private boolean mShowDvrCard; - private int[] mViewType = new int[SIZE_OF_VIEW_TYPE]; + private final boolean mDvrFeatureEnabled; + private final int[] mViewType = new int[SIZE_OF_VIEW_TYPE]; private final View.OnClickListener mGuideOnClickListener = new View.OnClickListener() { @Override @@ -67,11 +71,28 @@ public class ChannelsRowAdapter extends ItemListRowView.ItemListAdapter<Channel> private final View.OnClickListener mDvrOnClickListener = new View.OnClickListener() { @Override public void onClick(View view) { + Utils.showToastMessageForDeveloperFeature(view.getContext()); mTracker.sendMenuClicked(R.string.channels_item_dvr); getMainActivity().getOverlayManager().showDvrManager(); } }; + private final View.OnClickListener mRecordOnClickListener = new View.OnClickListener() { + @Override + public void onClick(View view) { + Utils.showToastMessageForDeveloperFeature(view.getContext()); + RecordCardView v = ((RecordCardView) view); + boolean isRecording = v.isRecording(); + mTracker.sendMenuClicked(isRecording ? R.string.channels_item_record_start + : R.string.channels_item_record_stop); + if (!isRecording) { + v.startRecording(); + } else { + v.stopRecording(); + } + } + }; + private final View.OnClickListener mAppLinkOnClickListener = new View.OnClickListener() { @Override public void onClick(View view) { @@ -102,7 +123,7 @@ public class ChannelsRowAdapter extends ItemListRowView.ItemListAdapter<Channel> mRecommender = recommender; mMinCount = minCount; mMaxCount = maxCount; - mShowDvrCard = CommonFeatures.DVR.isEnabled(mContext); + mDvrFeatureEnabled = CommonFeatures.DVR.isEnabled(mContext) && BuildCompat.isAtLeastN(); } @Override @@ -131,6 +152,8 @@ public class ChannelsRowAdapter extends ItemListRowView.ItemListAdapter<Channel> viewHolder.itemView.setOnClickListener(mAppLinkOnClickListener); } else if (viewType == R.layout.menu_card_dvr) { viewHolder.itemView.setOnClickListener(mDvrOnClickListener); + } else if (viewType == R.layout.menu_card_record) { + viewHolder.itemView.setOnClickListener(mRecordOnClickListener); } else { viewHolder.itemView.setTag(getItemList().get(position)); viewHolder.itemView.setOnClickListener(mChannelOnClickListener); @@ -140,17 +163,33 @@ public class ChannelsRowAdapter extends ItemListRowView.ItemListAdapter<Channel> @Override public void update() { List<Channel> channelList = new ArrayList<>(); - Channel dummyChannel = new Channel.Builder() - .build(); + Channel dummyChannel = new Channel.Builder().build(); // For guide item channelList.add(dummyChannel); // For setup item - boolean showSetupCard = SetupUtils.getInstance(mContext) - .hasNewInput(((MainActivity) mContext).getTvInputManagerHelper()); + TvInputManagerHelper inputManager = TvApplication.getSingletons(mContext) + .getTvInputManagerHelper(); + boolean showSetupCard = SetupUtils.getInstance(mContext).hasNewInput(inputManager); Channel currentChannel = ((MainActivity) mContext).getCurrentChannel(); boolean showAppLinkCard = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && currentChannel != null && currentChannel.getAppLinkType(mContext) != Channel.APP_LINK_TYPE_NONE; + boolean showDvrCard = false; + boolean showRecordCard = false; + if (mDvrFeatureEnabled) { + for (TvInputInfo info : inputManager.getTvInputInfos(true, true)) { + if (info.canRecord()) { + showDvrCard = true; + break; + } + } + if (currentChannel != null && currentChannel.getInputId() != null) { + TvInputInfo inputInfo = inputManager.getTvInputInfo(currentChannel.getInputId()); + if ((inputInfo.canRecord() && inputInfo.getTunerCount() > 1)) { + showRecordCard = true; + } + } + } mViewType[0] = R.layout.menu_card_guide; int index = 1; @@ -158,10 +197,14 @@ public class ChannelsRowAdapter extends ItemListRowView.ItemListAdapter<Channel> channelList.add(dummyChannel); mViewType[index++] = R.layout.menu_card_setup; } - if (mShowDvrCard) { + if (showDvrCard) { channelList.add(dummyChannel); mViewType[index++] = R.layout.menu_card_dvr; } + if (showRecordCard) { + channelList.add(currentChannel); + mViewType[index++] = R.layout.menu_card_record; + } if (showAppLinkCard) { channelList.add(currentChannel); mViewType[index++] = R.layout.menu_card_app_link; |