static void initLibrary(final Activity activity) {
    final NetworkLibrary library = NetworkLibrary.Instance();
    if (library.isInitialized()) {
      return;
    }

    Config.Instance()
        .runOnStart(
            new Runnable() {
              public void run() {
                UIUtil.wait(
                    "loadingNetworkLibrary",
                    new Runnable() {
                      public void run() {
                        if (SQLiteNetworkDatabase.Instance() == null) {
                          new SQLiteNetworkDatabase(activity.getApplication());
                        }

                        library.initialize();
                      }
                    },
                    activity);
              }
            });
  }
  ZLNetworkRequest createNetworkData(String url, final OPDSCatalogItem.State result) {
    if (url == null) {
      return null;
    }
    final NetworkLibrary library = NetworkLibrary.Instance();
    final NetworkCatalogItem catalogItem = result.Loader.getTree().Item;
    library.startLoading(catalogItem);
    url = rewriteUrl(url, false);
    return new ZLNetworkRequest(url) {
      @Override
      public void handleStream(InputStream inputStream, int length)
          throws IOException, ZLNetworkException {
        if (result.Loader.confirmInterruption()) {
          return;
        }

        new OPDSXMLReader(new OPDSFeedHandler(getURL(), result), false).read(inputStream);

        if (result.Loader.confirmInterruption() && result.LastLoadedId != null) {
          // reset state to load current page from the beginning
          result.LastLoadedId = null;
        } else {
          result.Loader.getTree().confirmAllItems();
        }
      }

      @Override
      public void doAfter(boolean success) {
        library.stopLoading(catalogItem);
      }
    };
  }
Beispiel #3
0
 protected BasketItem(INetworkLink link) {
   super(
       link,
       NetworkLibrary.resource().getResource("basket").getValue(),
       NetworkLibrary.resource().getResource("basketSummaryEmpty").getValue(),
       new UrlInfoCollection<UrlInfo>(),
       Accessibility.ALWAYS,
       FLAGS_DEFAULT & ~FLAGS_GROUP);
   myBooksInBasketOption = new ZLStringListOption(Link.getSiteName(), "Basket", null);
 }
 void prepareView() {
   if (myTree == null) {
     myTree = NetworkLibrary.Instance().getRootTree();
     setListAdapter(new LibraryAdapter());
     getListView().invalidateViews();
   }
 }
  @Override
  public void runSearch(NetworkItemsLoader loader, String pattern) throws ZLNetworkException {
    final LinkedList<ZLNetworkRequest> requestList = new LinkedList<ZLNetworkRequest>();
    final LinkedList<NetworkOperationData> dataList = new LinkedList<NetworkOperationData>();

    for (INetworkLink link : NetworkLibrary.Instance().activeLinks()) {
      final NetworkOperationData data = link.createOperationData(loader);
      final ZLNetworkRequest request = link.simpleSearchRequest(pattern, data);
      if (request != null && MimeType.APP_ATOM_XML.weakEquals(request.Mime)) {
        dataList.add(data);
        requestList.add(request);
      }
    }

    while (!requestList.isEmpty()) {
      ZLNetworkManager.Instance().perform(requestList);

      requestList.clear();

      if (loader.confirmInterruption()) {
        return;
      }
      for (NetworkOperationData data : dataList) {
        ZLNetworkRequest request = data.resume();
        if (request != null) {
          requestList.add(request);
        }
      }
    }
  }
  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 AllCatalogsSearchItem() {
   super(
       null,
       NetworkLibrary.resource()
           .getResource("search")
           .getResource("summaryAllCatalogs")
           .getValue());
 }
Beispiel #8
0
 protected SearchItem(INetworkLink link, String summary) {
   super(
       link,
       NetworkLibrary.resource().getResource("search").getValue(),
       summary,
       new UrlInfoCollection<UrlInfo>(),
       Accessibility.ALWAYS,
       FLAGS_DEFAULT);
 }
 @Override
 public boolean onSearchRequested() {
   if (searchIsInProgress()) {
     return false;
   }
   final NetworkLibrary library = NetworkLibrary.Instance();
   startSearch(library.NetworkSearchPatternOption.getValue(), true, null, false);
   return true;
 }
Beispiel #10
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);
   }
 }
Beispiel #11
0
 @Override
 public CharSequence getSummary() {
   final int size = bookIds().size();
   if (size == 0) {
     return super.getSummary();
   } else {
     final Money basketCost = cost();
     if (basketCost != null) {
       return NetworkLibrary.resource()
           .getResource("basketSummary")
           .getValue()
           .replace("%0", String.valueOf(size))
           .replace("%1", basketCost.toString());
     } else {
       return NetworkLibrary.resource()
           .getResource("basketSummaryCountOnly")
           .getValue()
           .replace("%0", String.valueOf(size));
     }
   }
 }
  @Override
  protected void onStart() {
    super.onStart();

    myAllItems.clear();

    final Intent intent = getIntent();

    myAllItems.add(new SectionItem("enabled"));
    final List<String> enabledIds =
        intent.getStringArrayListExtra(NetworkLibraryActivity.ENABLED_CATALOG_IDS_KEY);
    if (enabledIds.size() > 0) {
      final TreeSet<CatalogItem> cItems = new TreeSet<CatalogItem>();
      for (String id : enabledIds) {
        final NetworkTree tree = NetworkLibrary.Instance().getCatalogTreeByUrlAll(id);
        if (tree != null && tree.getLink() != null) {
          cItems.add(new CatalogItem(id, true, tree));
        }
      }
      myAllItems.addAll(cItems);
      mySelectedItems.addAll(cItems);
    }

    myAllItems.add(new SectionItem("disabled"));
    final List<String> disabledIds =
        intent.getStringArrayListExtra(NetworkLibraryActivity.DISABLED_CATALOG_IDS_KEY);
    if (disabledIds.size() > 0) {
      final TreeSet<CatalogItem> cItems = new TreeSet<CatalogItem>();
      for (String id : disabledIds) {
        cItems.add(
            new CatalogItem(id, false, NetworkLibrary.Instance().getCatalogTreeByUrlAll(id)));
      }
      myAllItems.addAll(cItems);
    }

    setListAdapter(new CatalogsListAdapter());
  }
Beispiel #13
0
 private void doExpandCatalog(final NetworkCatalogTree tree) {
   final NetworkItemsLoader loader = NetworkLibrary.Instance().getStoredLoader(tree);
   if (loader != null && loader.canResumeLoading()) {
     doOpenTree(tree);
   } else if (loader != null) {
     loader.setPostRunnable(
         new Runnable() {
           public void run() {
             doLoadCatalog(tree);
           }
         });
   } else {
     doLoadCatalog(tree);
   }
 }
Beispiel #14
0
 public static CharSequence getHtmlText(String text) {
   // fixes an android bug (?): text layout fails on text with nested style tags
   text = removeNestedTags(text, new String[] {"i", "b", "strong"});
   final Spanned htmlText = Html.fromHtml(text);
   if (htmlText.getSpans(0, htmlText.length(), URLSpan.class).length == 0) {
     return htmlText;
   }
   final Spannable newHtmlText = Spannable.Factory.getInstance().newSpannable(htmlText);
   for (URLSpan span : newHtmlText.getSpans(0, newHtmlText.length(), URLSpan.class)) {
     final int start = newHtmlText.getSpanStart(span);
     final int end = newHtmlText.getSpanEnd(span);
     final int flags = newHtmlText.getSpanFlags(span);
     final String url = NetworkLibrary.Instance().rewriteUrl(span.getURL(), true);
     newHtmlText.removeSpan(span);
     newHtmlText.setSpan(new URLSpan(url), start, end, flags);
   }
   return newHtmlText;
 }
 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;
 }
Beispiel #16
0
 public final void clear() {
   myBooksInBasketOption.setValue(null);
   myBooks.clear();
   ++myGeneration;
   NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
 }
 private static boolean searchIsInProgress() {
   return ItemsLoadingService.getRunnable(NetworkLibrary.Instance().getSearchItemTree()) != null;
 }
 public SectionItem(String key) {
   Title = NetworkLibrary.resource().getResource("manageCatalogs").getResource(key).getValue();
 }
Beispiel #19
0
 public static void openInBrowser(Activity activity, String url) {
   if (url != null) {
     url = NetworkLibrary.Instance().rewriteUrl(url, true);
     activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
   }
 }