Esempio n. 1
0
 public final void remove(NetworkBookItem book) {
   List<String> ids = bookIds();
   if (ids.contains(book.Id)) {
     ids = new ArrayList<String>(ids);
     ids.remove(book.Id);
     myBooksInBasketOption.setValue(ids);
     myBooks.remove(book);
     ++myGeneration;
     NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
   }
 }
  private void runLanguageFilterDialog() {
    final NetworkLibrary library = NetworkLibrary.Instance();

    final List<String> allLanguageCodes = library.languageCodes();
    Collections.sort(allLanguageCodes, new ZLLanguageUtil.CodeComparator());
    final Collection<String> activeLanguageCodes = library.activeLanguageCodes();
    final CharSequence[] languageNames = new CharSequence[allLanguageCodes.size()];
    final boolean[] checked = new boolean[allLanguageCodes.size()];

    for (int i = 0; i < allLanguageCodes.size(); ++i) {
      final String code = allLanguageCodes.get(i);
      languageNames[i] = ZLLanguageUtil.languageName(code);
      checked[i] = activeLanguageCodes.contains(code);
    }

    final DialogInterface.OnMultiChoiceClickListener listener =
        new DialogInterface.OnMultiChoiceClickListener() {
          public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            checked[which] = isChecked;
          }
        };
    final ZLResource dialogResource = ZLResource.resource("dialog");
    final AlertDialog dialog =
        new AlertDialog.Builder(this)
            .setMultiChoiceItems(languageNames, checked, listener)
            .setTitle(
                dialogResource.getResource("languageFilterDialog").getResource("title").getValue())
            .setPositiveButton(
                dialogResource.getResource("button").getResource("ok").getValue(),
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    final TreeSet<String> newActiveCodes =
                        new TreeSet<String>(new ZLLanguageUtil.CodeComparator());
                    for (int i = 0; i < checked.length; ++i) {
                      if (checked[i]) {
                        newActiveCodes.add(allLanguageCodes.get(i));
                      }
                    }
                    library.setActiveLanguageCodes(newActiveCodes);
                    library.synchronize();
                    NetworkView.Instance().fireModelChanged();
                  }
                })
            .create();
    dialog.show();
  }
 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;
 }