aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/dvr/ui/DvrSeriesScheduledFragment.java
diff options
context:
space:
mode:
authorNick Chalko <nchalko@google.com>2016-10-26 14:03:09 -0700
committerNick Chalko <nchalko@google.com>2016-10-31 10:36:49 -0700
commitd41f0075a7d2ea826204e81fcec57d0aa57171a9 (patch)
treecb30cfbafd80e01d314868cdc36e783d39981119 /src/com/android/tv/dvr/ui/DvrSeriesScheduledFragment.java
parent5e0ec06a797e3497da94390c63c7072de442695b (diff)
downloadTV-d41f0075a7d2ea826204e81fcec57d0aa57171a9.tar.gz
Sync to ub-tv-killing at 6f6e46557accb62c9548e4177d6005aa944dbf33
Change-Id: I873644d6d9d0110c981ef6075cb4019c16bbb94b
Diffstat (limited to 'src/com/android/tv/dvr/ui/DvrSeriesScheduledFragment.java')
-rw-r--r--src/com/android/tv/dvr/ui/DvrSeriesScheduledFragment.java154
1 files changed, 154 insertions, 0 deletions
diff --git a/src/com/android/tv/dvr/ui/DvrSeriesScheduledFragment.java b/src/com/android/tv/dvr/ui/DvrSeriesScheduledFragment.java
new file mode 100644
index 00000000..1173df46
--- /dev/null
+++ b/src/com/android/tv/dvr/ui/DvrSeriesScheduledFragment.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.tv.dvr.ui;
+
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.support.v17.leanback.widget.GuidanceStylist;
+import android.support.v17.leanback.widget.GuidedAction;
+
+import com.android.tv.R;
+import com.android.tv.TvApplication;
+import com.android.tv.dvr.DvrDataManager;
+import com.android.tv.dvr.DvrScheduleManager;
+import com.android.tv.dvr.ScheduledRecording;
+import com.android.tv.dvr.SeriesRecording;
+import com.android.tv.dvr.ui.list.DvrSeriesSchedulesFragment;
+
+import java.util.List;
+
+public class DvrSeriesScheduledFragment extends DvrGuidedStepFragment {
+ private final static long SERIES_RECORDING_ID_NOT_SET = -1;
+
+ private final static int ACTION_VIEW_SCHEDULES = 1;
+
+ private DvrScheduleManager mDvrScheduleManager;
+ private SeriesRecording mSeriesRecording;
+ private boolean mShowViewScheduleOption;
+
+ private int mSchedulesAddedCount = 0;
+ private boolean mHasConflict = false;
+ private int mInThisSeriesConflictCount = 0;
+ private int mOutThisSeriesConflictCount = 0;
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ long seriesRecordingId = getArguments().getLong(
+ DvrSeriesScheduledDialogActivity.SERIES_RECORDING_ID, SERIES_RECORDING_ID_NOT_SET);
+ if (seriesRecordingId == SERIES_RECORDING_ID_NOT_SET) {
+ getActivity().finish();
+ return;
+ }
+ mShowViewScheduleOption = getArguments().getBoolean(
+ DvrSeriesScheduledDialogActivity.SHOW_VIEW_SCHEDULE_OPTION);
+ mDvrScheduleManager = TvApplication.getSingletons(context).getDvrScheduleManager();
+ mSeriesRecording = TvApplication.getSingletons(context).getDvrDataManager()
+ .getSeriesRecording(seriesRecordingId);
+ if (mSeriesRecording == null) {
+ getActivity().finish();
+ return;
+ }
+ mSchedulesAddedCount = TvApplication.getSingletons(getContext()).getDvrManager()
+ .getAvailableScheduledRecording(mSeriesRecording.getId()).size();
+ List<ScheduledRecording> conflictingRecordings =
+ mDvrScheduleManager.getConflictingSchedules(mSeriesRecording);
+ mHasConflict = !conflictingRecordings.isEmpty();
+ for (ScheduledRecording recording : conflictingRecordings) {
+ if (recording.getSeriesRecordingId() == mSeriesRecording.getId()) {
+ ++mInThisSeriesConflictCount;
+ } else {
+ ++mOutThisSeriesConflictCount;
+ }
+ }
+ }
+
+ @Override
+ public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
+ String title = getString(R.string.dvr_series_recording_dialog_title);
+ Drawable icon;
+ if (!mHasConflict) {
+ icon = getResources().getDrawable(R.drawable.ic_check_circle_white_48dp, null);
+ } else {
+ icon = getResources().getDrawable(R.drawable.ic_error_white_48dp, null);
+ }
+ return new GuidanceStylist.Guidance(title, getDescription(), null, icon);
+ }
+
+ @Override
+ public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
+ Context context = getContext();
+ actions.add(new GuidedAction.Builder(context)
+ .clickAction(GuidedAction.ACTION_ID_OK)
+ .build());
+ if (mShowViewScheduleOption) {
+ actions.add(new GuidedAction.Builder(context)
+ .id(ACTION_VIEW_SCHEDULES)
+ .title(R.string.dvr_action_view_schedules)
+ .build());
+ }
+ }
+
+ @Override
+ public void onGuidedActionClicked(GuidedAction action) {
+ if (action.getId() == ACTION_VIEW_SCHEDULES) {
+ Intent intent = new Intent(getActivity(), DvrSchedulesActivity.class);
+ intent.putExtra(DvrSchedulesActivity.KEY_SCHEDULES_TYPE, DvrSchedulesActivity
+ .TYPE_SERIES_SCHEDULE);
+ intent.putExtra(DvrSeriesSchedulesFragment.SERIES_SCHEDULES_KEY_SERIES_RECORDING,
+ mSeriesRecording);
+ startActivity(intent);
+ }
+ getActivity().finish();
+ }
+
+ private String getDescription() {
+ if (!mHasConflict) {
+ return getResources().getQuantityString(
+ R.plurals.dvr_series_recording_scheduled_no_conflict, mSchedulesAddedCount,
+ mSchedulesAddedCount, mSeriesRecording.getTitle());
+ } else {
+ // mInThisSeriesConflictCount equals 0 and mOutThisSeriesConflictCount equals 0 means
+ // mHasConflict is false. So we don't need to check that case.
+ if (mInThisSeriesConflictCount != 0 && mOutThisSeriesConflictCount != 0) {
+ return getResources().getQuantityString(R.plurals
+ .dvr_series_recording_scheduled_this_and_other_series_conflict,
+ mSchedulesAddedCount, mSchedulesAddedCount, mSeriesRecording.getTitle(),
+ mInThisSeriesConflictCount + mOutThisSeriesConflictCount);
+ } else if (mInThisSeriesConflictCount != 0) {
+ return getResources().getQuantityString(R.plurals
+ .dvr_series_recording_scheduled_only_this_series_conflict,
+ mSchedulesAddedCount, mSchedulesAddedCount, mSeriesRecording.getTitle(),
+ mInThisSeriesConflictCount);
+ } else {
+ if (mOutThisSeriesConflictCount == 1) {
+ return getResources().getQuantityString(R.plurals
+ .dvr_series_recording_scheduled_only_other_series_one_conflict,
+ mSchedulesAddedCount, mSchedulesAddedCount,
+ mSeriesRecording.getTitle());
+ } else {
+ return getResources().getQuantityString(R.plurals
+ .dvr_series_recording_scheduled_only_other_series_conflict,
+ mSchedulesAddedCount, mSchedulesAddedCount, mSeriesRecording.getTitle(),
+ mOutThisSeriesConflictCount);
+ }
+ }
+ }
+ }
+}