Пример #1
0
 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;
 }
Пример #2
0
 private static void doReadBook(Activity activity, final NetworkBookItem book, boolean demo) {
   String local = null;
   if (!demo) {
     local = book.localCopyFileName();
   } else {
     final BookUrlInfo reference = book.reference(UrlInfo.Type.BookDemo);
     if (reference != null) {
       local = reference.localCopyFileName(UrlInfo.Type.BookDemo);
     }
   }
   if (local != null) {
     activity.startActivity(
         new Intent(
                 Intent.ACTION_VIEW,
                 Uri.fromFile(new File(local)),
                 activity.getApplicationContext(),
                 FBReader.class)
             .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
   }
 }
Пример #3
0
 public static void doDownloadBook(Activity activity, final NetworkBookItem book, boolean demo) {
   final UrlInfo.Type resolvedType = demo ? UrlInfo.Type.BookDemo : UrlInfo.Type.Book;
   final BookUrlInfo ref = book.reference(resolvedType);
   if (ref != null) {
     activity.startService(
         new Intent(
                 Intent.ACTION_VIEW,
                 Uri.parse(ref.Url),
                 activity.getApplicationContext(),
                 BookDownloaderService.class)
             .putExtra(BookDownloaderService.Key.BOOK_MIME, ref.Mime.toString())
             .putExtra(BookDownloaderService.Key.BOOK_KIND, resolvedType)
             .putExtra(BookDownloaderService.Key.CLEAN_URL, ref.cleanUrl())
             .putExtra(BookDownloaderService.Key.BOOK_TITLE, book.Title));
   }
 }
 public static void doDownloadBook(Activity activity, final NetworkBookItem book, boolean demo) {
   final UrlInfo.Type resolvedType = demo ? UrlInfo.Type.BookDemo : UrlInfo.Type.Book;
   final BookUrlInfo ref = book.reference(resolvedType);
   if (ref != null) {
     activity.startService(
         new Intent(
                 Intent.ACTION_VIEW,
                 Uri.parse(ref.Url),
                 activity.getApplicationContext(),
                 BookDownloaderService.class)
             .putExtra(BookDownloaderService.BOOK_FORMAT_KEY, ref.BookFormat)
             .putExtra(BookDownloaderService.REFERENCE_TYPE_KEY, resolvedType)
             .putExtra(BookDownloaderService.CLEAN_URL_KEY, ref.cleanUrl())
             .putExtra(BookDownloaderService.TITLE_KEY, book.Title));
   }
 }
Пример #5
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;
 }
Пример #6
0
 private static boolean useDemoReferences(NetworkBookItem book) {
   return book.reference(UrlInfo.Type.BookDemo) != null
       && book.localCopyFileName() == null
       && book.reference(UrlInfo.Type.Book) == null;
 }
Пример #7
0
 private static boolean useFullReferences(NetworkBookItem book) {
   return book.reference(UrlInfo.Type.Book) != null
       || book.reference(UrlInfo.Type.BookConditional) != null;
 }
Пример #8
0
 private static void doBuyInBrowser(Activity activity, final NetworkBookItem book) {
   BookUrlInfo reference = book.reference(UrlInfo.Type.BookBuyInBrowser);
   if (reference != null) {
     Util.openInBrowser(activity, reference.Url);
   }
 }