Home | History | Annotate | Download | only in ui
      1 package com.android.tv.dvr.ui;
      2 
      3 import android.app.Activity;
      4 import android.os.Bundle;
      5 import android.view.LayoutInflater;
      6 import android.view.View;
      7 import android.view.ViewGroup;
      8 import com.android.tv.MainActivity;
      9 import com.android.tv.R;
     10 
     11 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
     12 import android.support.v17.leanback.widget.GuidedAction;
     13 
     14 import com.android.tv.data.Channel;
     15 import com.android.tv.data.ChannelDataManager;
     16 import com.android.tv.data.Program;
     17 import com.android.tv.dvr.ScheduledRecording;
     18 import com.android.tv.guide.ProgramManager.TableEntry;
     19 
     20 import java.text.DateFormat;
     21 import java.util.Date;
     22 import java.util.List;
     23 
     24 public class DvrRecordConflictFragment extends DvrGuidedStepFragment {
     25     private static final int DVR_EPG_RECORD = 1;
     26     private static final int DVR_EPG_NOT_RECORD = 2;
     27 
     28     private List<ScheduledRecording> mConflicts;
     29 
     30     public DvrRecordConflictFragment(TableEntry entry) {
     31         super(entry);
     32     }
     33 
     34     @Override
     35     public View onCreateView(LayoutInflater inflater, ViewGroup container,
     36             Bundle savedInstanceState) {
     37         mConflicts = getDvrManager().getScheduledRecordingsThatConflict(getEntry().program);
     38         return super.onCreateView(inflater, container, savedInstanceState);
     39     }
     40 
     41     @Override
     42     public Guidance onCreateGuidance(Bundle savedInstanceState) {
     43         final MainActivity tvActivity = (MainActivity) getActivity();
     44         final ChannelDataManager channelDataManager = tvActivity.getChannelDataManager();
     45         StringBuilder sb = new StringBuilder();
     46         for (ScheduledRecording r : mConflicts) {
     47             Channel channel = channelDataManager.getChannel(r.getChannelId());
     48             if (channel == null) {
     49                 continue;
     50             }
     51             sb.append(channel.getDisplayName())
     52                     .append(" : ")
     53                     .append(DateFormat.getDateTimeInstance().format(new Date(r.getStartTimeMs())))
     54                     .append("\n");
     55         }
     56         String title = getResources().getString(R.string.dvr_epg_conflict_dialog_title);
     57         String description = sb.toString();
     58         return new Guidance(title, description, null, null);
     59     }
     60 
     61     @Override
     62     public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
     63         Activity activity = getActivity();
     64         actions.add(new GuidedAction.Builder(activity)
     65                 .id(DVR_EPG_RECORD)
     66                 .title(getResources().getString(R.string.dvr_epg_record))
     67                 .build());
     68         actions.add(new GuidedAction.Builder(activity)
     69                 .id(DVR_EPG_NOT_RECORD)
     70                 .title(getResources().getString(R.string.dvr_epg_do_not_record))
     71                 .build());
     72     }
     73 
     74     @Override
     75     public void onGuidedActionClicked(GuidedAction action) {
     76         Program program = getEntry().program;
     77         if (action.getId() == DVR_EPG_RECORD) {
     78             getDvrManager().addSchedule(program, mConflicts);
     79         }
     80         dismissDialog();
     81     }
     82 }
     83