Пример #1
0
 private static boolean runActionStatic(Activity activity, NetworkBookTree tree, int actionCode) {
   final NetworkBookItem book = tree.Book;
   switch (actionCode) {
     case ActionCode.DOWNLOAD_BOOK:
       Util.doDownloadBook(activity, book, false);
       return true;
     case ActionCode.DOWNLOAD_DEMO:
       Util.doDownloadBook(activity, book, true);
       return true;
     case ActionCode.READ_BOOK:
       doReadBook(activity, book, false);
       return true;
     case ActionCode.READ_DEMO:
       doReadBook(activity, book, true);
       return true;
     case ActionCode.DELETE_BOOK:
       tryToDeleteBook(activity, book, false);
       return true;
     case ActionCode.DELETE_DEMO:
       tryToDeleteBook(activity, book, true);
       return true;
     case ActionCode.BUY_DIRECTLY:
       doBuyDirectly(activity, tree);
       return true;
     case ActionCode.BUY_IN_BROWSER:
       doBuyInBrowser(activity, book);
       return true;
     case ActionCode.ADD_BOOK_TO_BASKET:
       book.Link.getBasketItem().add(book);
       return true;
     case ActionCode.REMOVE_BOOK_FROM_BASKET:
       book.Link.getBasketItem().remove(book);
       return true;
     case ActionCode.OPEN_BASKET:
       new OpenCatalogAction(activity)
           .run(NetworkLibrary.Instance().getFakeBasketTree(book.Link.getBasketItem()));
       return true;
   }
   return false;
 }
Пример #2
0
 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;
 }