1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 2 * This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 package org.mozilla.gecko.activitystream.homepanel.model; 7 8 import android.support.annotation.Nullable; 9 10 import org.mozilla.gecko.activitystream.Utils; 11 import org.mozilla.gecko.activitystream.homepanel.StreamRecyclerAdapter; 12 13 public class TopStory implements WebpageRowModel { 14 private @Nullable Boolean isBookmarked; 15 private @Nullable Boolean isPinned; 16 17 private final String title; 18 private final String url; 19 private final String imageUrl; 20 TopStory(String title, String url, String imageUrl)21 public TopStory(String title, String url, String imageUrl) { 22 this.title = title; 23 this.url = url; 24 this.imageUrl = imageUrl; 25 } 26 27 @Override getTitle()28 public String getTitle() { 29 return title; 30 } 31 32 @Override getUrl()33 public String getUrl() { 34 return url; 35 } 36 37 @Override getImageUrl()38 public String getImageUrl() { 39 return imageUrl; 40 } 41 42 @Override getRowItemType()43 public StreamRecyclerAdapter.RowItemType getRowItemType() { 44 return StreamRecyclerAdapter.RowItemType.TOP_STORIES_ITEM; 45 } 46 47 @Override isBookmarked()48 public Boolean isBookmarked() { 49 return isBookmarked; 50 } 51 52 @Override isPinned()53 public Boolean isPinned() { 54 return isPinned; 55 } 56 57 @Override updateBookmarked(boolean bookmarked)58 public void updateBookmarked(boolean bookmarked) { 59 this.isBookmarked = bookmarked; 60 } 61 62 @Override updatePinned(boolean pinned)63 public void updatePinned(boolean pinned) { 64 this.isPinned = pinned; 65 } 66 67 @Override getSource()68 public Utils.HighlightSource getSource() { 69 return Utils.HighlightSource.POCKET; 70 } 71 72 @Override getUniqueId()73 public long getUniqueId() { 74 return getUrl().hashCode(); 75 } 76 77 /** 78 * Pinned and Bookmarked state are loaded in {@link org.mozilla.gecko.activitystream.homepanel.menu.ActivityStreamContextMenu#postInit()}, 79 * and will be fetched if the state cached in {@link TopStory} is null (See {@link WebpageModel#isPinned} 80 * and {@link WebpageModel#isBookmarked} 81 **/ 82 @Override onStateCommitted()83 public void onStateCommitted() { 84 // Since Top Stories are not loaded from a cursor that automatically notifies of 85 // changes to bookmark or pin state, trash this cached state once we've committed it 86 // so it will be fetched every time. 87 isPinned = null; 88 isBookmarked = null; 89 } 90 } 91