1 /* 2 * Copyright (C) 2016 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 17 package com.android.tv.dvr.ui; 18 19 import android.support.v17.leanback.widget.PresenterSelector; 20 21 import com.android.tv.common.recording.RecordedProgram; 22 import com.android.tv.dvr.DvrDataManager; 23 24 /** 25 * Adapter for {@link RecordedProgram}. 26 */ 27 final class RecordedProgramsAdapter extends SortedArrayAdapter<RecordedProgram> 28 implements DvrDataManager.RecordedProgramListener { 29 private final DvrDataManager mDataManager; 30 31 RecordedProgramsAdapter(DvrDataManager dataManager, PresenterSelector presenterSelector) { 32 super(presenterSelector, RecordedProgram.START_TIME_THEN_ID_COMPARATOR); 33 mDataManager = dataManager; 34 } 35 36 public void start() { 37 clear(); 38 addAll(mDataManager.getRecordedPrograms()); 39 mDataManager.addRecordedProgramListener(this); 40 } 41 42 public void stop() { 43 mDataManager.removeRecordedProgramListener(this); 44 } 45 46 @Override 47 long getId(RecordedProgram item) { 48 return item.getId(); 49 } 50 51 @Override // DvrDataManager.RecordedProgramListener 52 public void onRecordedProgramAdded(RecordedProgram recordedProgram) { 53 add(recordedProgram); 54 } 55 56 @Override // DvrDataManager.RecordedProgramListener 57 public void onRecordedProgramChanged(RecordedProgram recordedProgram) { 58 change(recordedProgram); 59 } 60 61 @Override // DvrDataManager.RecordedProgramListener 62 public void onRecordedProgramRemoved(RecordedProgram recordedProgram) { 63 remove(recordedProgram); 64 } 65 } 66