diff options
Diffstat (limited to 'src/com/android/tv/data/ProgramDataManager.java')
-rw-r--r-- | src/com/android/tv/data/ProgramDataManager.java | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/com/android/tv/data/ProgramDataManager.java b/src/com/android/tv/data/ProgramDataManager.java index 6c167238..88db91b9 100644 --- a/src/com/android/tv/data/ProgramDataManager.java +++ b/src/com/android/tv/data/ProgramDataManager.java @@ -28,16 +28,17 @@ import android.os.Looper; import android.os.Message; import android.support.annotation.MainThread; import android.support.annotation.VisibleForTesting; +import android.util.ArraySet; import android.util.Log; import android.util.LongSparseArray; import android.util.LruCache; -import com.android.tv.common.CollectionUtils; import com.android.tv.common.MemoryManageable; +import com.android.tv.common.SoftPreconditions; +import com.android.tv.data.epg.EpgFetcher; import com.android.tv.util.AsyncDbTask; import com.android.tv.util.Clock; import com.android.tv.util.MultiLongSparseArray; -import com.android.tv.util.SoftPreconditions; import com.android.tv.util.Utils; import java.util.ArrayList; @@ -90,7 +91,7 @@ public class ProgramDataManager implements MemoryManageable { private final MultiLongSparseArray<OnCurrentProgramUpdatedListener> mChannelId2ProgramUpdatedListeners = new MultiLongSparseArray<>(); private final Handler mHandler; - private final Set<Listener> mListeners = CollectionUtils.createSmallSet(); + private final Set<Listener> mListeners = new ArraySet<>(); private final ContentObserver mProgramObserver; @@ -108,8 +109,12 @@ public class ProgramDataManager implements MemoryManageable { private boolean mPauseProgramUpdate = false; private final LruCache<Long, Program> mZeroLengthProgramCache = new LruCache<>(10); + // TODO: Change to final. + private EpgFetcher mEpgFetcher; + public ProgramDataManager(Context context) { this(context.getContentResolver(), Clock.SYSTEM, Looper.myLooper()); + mEpgFetcher = new EpgFetcher(context); } @VisibleForTesting @@ -128,8 +133,8 @@ public class ProgramDataManager implements MemoryManageable { } if (mPrefetchEnabled) { // The delay time of an existing MSG_UPDATE_PREFETCH_PROGRAM could be quite long - // up to PROGRAM_GUIDE_SNAP_TIME_MS. So we need to remove the existing message and - // send MSG_UPDATE_PREFETCH_PROGRAM again. + // up to PROGRAM_GUIDE_SNAP_TIME_MS. So we need to remove the existing message + // and send MSG_UPDATE_PREFETCH_PROGRAM again. mHandler.removeMessages(MSG_UPDATE_PREFETCH_PROGRAM); mHandler.sendEmptyMessage(MSG_UPDATE_PREFETCH_PROGRAM); } @@ -169,6 +174,9 @@ public class ProgramDataManager implements MemoryManageable { } mContentResolver.registerContentObserver(Programs.CONTENT_URI, true, mProgramObserver); + if (mEpgFetcher != null) { + mEpgFetcher.start(); + } } /** @@ -182,6 +190,9 @@ public class ProgramDataManager implements MemoryManageable { } mStarted = false; + if (mEpgFetcher != null) { + mEpgFetcher.stop(); + } mContentResolver.unregisterContentObserver(mProgramObserver); mHandler.removeCallbacksAndMessages(null); @@ -201,6 +212,18 @@ public class ProgramDataManager implements MemoryManageable { } /** + * Reloads program data. + */ + public void reload() { + if (!mHandler.hasMessages(MSG_UPDATE_CURRENT_PROGRAMS)) { + mHandler.sendEmptyMessage(MSG_UPDATE_CURRENT_PROGRAMS); + } + if (mPrefetchEnabled && !mHandler.hasMessages(MSG_UPDATE_PREFETCH_PROGRAM)) { + mHandler.sendEmptyMessage(MSG_UPDATE_PREFETCH_PROGRAM); + } + } + + /** * A listener interface to receive notification on program data retrieval from DB. */ public interface Listener { @@ -601,6 +624,22 @@ public class ProgramDataManager implements MemoryManageable { } } + /** + * Gets an single {@link Program} from {@link TvContract.Programs#CONTENT_URI}. + */ + public static class QueryProgramTask extends AsyncDbTask.AsyncQueryItemTask<Program> { + + public QueryProgramTask(ContentResolver contentResolver, long programId) { + super(contentResolver, TvContract.buildProgramUri(programId), Program.PROJECTION, null, + null, null); + } + + @Override + protected Program fromCursor(Cursor c) { + return Program.fromCursor(c); + } + } + private class MyHandler extends Handler { public MyHandler(Looper looper) { super(looper); |