public static List<NBAction> getContextMenuActions( Activity activity, NetworkBookTree tree, BookDownloaderServiceConnection connection) { final NetworkBookItem book = tree.Book; List<NBAction> actions = new LinkedList<NBAction>(); if (useFullReferences(book)) { final BookUrlInfo reference = book.reference(UrlInfo.Type.Book); if (reference != null && connection != null && connection.isBeingDownloaded(reference.Url)) { actions.add(new NBAction(activity, ActionCode.TREE_NO_ACTION, "alreadyDownloading")); } else if (book.localCopyFileName() != null) { actions.add(new NBAction(activity, ActionCode.READ_BOOK, "read")); actions.add(new NBAction(activity, ActionCode.DELETE_BOOK, "delete")); } else if (reference != null) { actions.add(new NBAction(activity, ActionCode.DOWNLOAD_BOOK, "download")); } } if (useDemoReferences(book)) { final BookUrlInfo reference = book.reference(UrlInfo.Type.BookDemo); if (connection != null && connection.isBeingDownloaded(reference.Url)) { actions.add(new NBAction(activity, ActionCode.TREE_NO_ACTION, "alreadyDownloadingDemo")); } else if (reference.localCopyFileName(UrlInfo.Type.BookDemo) != null) { actions.add(new NBAction(activity, ActionCode.READ_DEMO, "readDemo")); actions.add(new NBAction(activity, ActionCode.DELETE_DEMO, "deleteDemo")); } else { actions.add(new NBAction(activity, ActionCode.DOWNLOAD_DEMO, "downloadDemo")); } } if (book.getStatus() == NetworkBookItem.Status.CanBePurchased) { final BookBuyUrlInfo reference = book.buyInfo(); final int id = reference.InfoType == UrlInfo.Type.BookBuy ? ActionCode.BUY_DIRECTLY : ActionCode.BUY_IN_BROWSER; final String priceString = reference.Price != null ? reference.Price.toString() : ""; actions.add(new NBAction(activity, id, "buy", priceString)); final BasketItem basketItem = book.Link.getBasketItem(); if (basketItem != null) { if (basketItem.contains(book)) { if (tree.Parent instanceof BasketCatalogTree || activity instanceof NetworkLibraryActivity) { actions.add( new NBAction(activity, ActionCode.REMOVE_BOOK_FROM_BASKET, "removeFromBasket")); } else { actions.add(new NBAction(activity, ActionCode.OPEN_BASKET, "openBasket")); } } else { actions.add(new NBAction(activity, ActionCode.ADD_BOOK_TO_BASKET, "addToBasket")); } } } return actions; }
public static int getBookStatus( NetworkBookItem book, BookDownloaderServiceConnection connection) { if (useFullReferences(book)) { final BookUrlInfo reference = book.reference(UrlInfo.Type.Book); if (reference != null && connection != null && connection.isBeingDownloaded(reference.Url)) { return R.drawable.ic_list_downloading; } else if (book.localCopyFileName() != null) { return R.drawable.ic_list_flag; } else if (reference != null) { return R.drawable.ic_list_download; } } if (book.getStatus() == NetworkBookItem.Status.CanBePurchased) { return R.drawable.ic_list_buy; } return 0; }