Advertisement
Guest User

Untitled

a guest
May 4th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. private Handler mHandler = new Handler();
  2.  
  3. /**
  4. * Adds to the cache WatchLater List a {@link WatchLaterItem}
  5. *
  6. * @param itemToAdd {@link WatchLaterItem}
  7. */
  8. private void addItemToWatchLaterList(WatchLaterItem itemToAdd) {
  9. final Map<String, WatchLaterItem> itemsByEditorialVersionIdMap = new HashMap<>();
  10. final List<WatchLaterItem> watchLaterItems = new ArrayList<>();
  11. watchLaterItems.addAll(mRetrievedWatchLaterList);
  12. itemsByEditorialVersionIdMap.putAll(mItemsByEditorialVersionIdMap);
  13.  
  14. if (itemToAdd.href == null || itemToAdd.href.isEmpty()) {
  15. itemToAdd.href = generateRandomHRef();
  16. }
  17. final String editorialVersionId = itemToAdd.editorialVersionId;
  18. itemsByEditorialVersionIdMap.put(editorialVersionId, itemToAdd);
  19. watchLaterItems.add(itemToAdd);
  20. // Assign in UI Thread
  21. mHandler.post(new Runnable() {
  22. @Override
  23. public void run() {
  24. synchronized (WatchLaterListManager.this) {
  25. mRetrievedWatchLaterList.clear();
  26. mRetrievedWatchLaterList.addAll(watchLaterItems);
  27. mItemsByEditorialVersionIdMap.clear();
  28. mItemsByEditorialVersionIdMap.putAll(itemsByEditorialVersionIdMap);
  29. Log.d(TAG, "Add to WatchLater list cache: " + editorialVersionId);
  30. }
  31. }
  32. });
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement