Search in sources :

Example 1 with NetworkLibrary

use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.

the class NetworkItemsLoader method run.

public final void run() {
    final NetworkLibrary library = Tree.Library;
    synchronized (library) {
        if (library.isLoadingInProgress(Tree)) {
            return;
        }
        library.storeLoader(Tree, this);
    }
    try {
        library.fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
        try {
            doBefore();
        } catch (ZLNetworkException e) {
            onFinish(e, false);
            return;
        }
        try {
            load();
            onFinish(null, isLoadingInterrupted());
        } catch (ZLNetworkException e) {
            onFinish(e, isLoadingInterrupted());
        }
    } finally {
        library.removeStoredLoader(Tree);
        library.fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
        synchronized (this) {
            if (myPostRunnable != null) {
                myPostRunnable.run();
                myFinishedFlag = true;
            }
        }
    }
}
Also used : ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException) NetworkLibrary(org.geometerplus.fbreader.network.NetworkLibrary)

Example 2 with NetworkLibrary

use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.

the class ProcessHyperlinkAction method openInBrowser.

private void openInBrowser(final String url) {
    final Intent intent = new Intent(Intent.ACTION_VIEW);
    final boolean externalUrl;
    if (BookDownloader.acceptsUri(Uri.parse(url), null)) {
        intent.setClass(BaseActivity, BookDownloader.class);
        intent.putExtra(BookDownloaderService.Key.SHOW_NOTIFICATIONS, BookDownloaderService.Notifications.ALL);
        externalUrl = false;
    } else {
        externalUrl = true;
    }
    final NetworkLibrary nLibrary = NetworkLibrary.Instance(Paths.systemInfo(BaseActivity));
    new Thread(new Runnable() {

        public void run() {
            if (!url.startsWith("fbreader-action:")) {
                try {
                    nLibrary.initialize(new ActivityNetworkContext(BaseActivity));
                } catch (ZLNetworkException e) {
                    e.printStackTrace();
                    UIMessageUtil.showMessageText(BaseActivity, e.getMessage());
                    return;
                }
            }
            intent.setData(Util.rewriteUri(Uri.parse(nLibrary.rewriteUrl(url, externalUrl))));
            BaseActivity.runOnUiThread(new Runnable() {

                public void run() {
                    try {
                        OrientationUtil.startActivity(BaseActivity, intent);
                    } catch (ActivityNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    }).start();
}
Also used : ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) ActivityNetworkContext(org.geometerplus.android.fbreader.network.auth.ActivityNetworkContext) NetworkLibrary(org.geometerplus.fbreader.network.NetworkLibrary)

Example 3 with NetworkLibrary

use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.

the class NetworkSearchActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
    final Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        final Bundle data = intent.getBundleExtra(SearchManager.APP_DATA);
        if (data != null) {
            final NetworkLibrary library = Util.networkLibrary(this);
            final NetworkTree.Key key = (NetworkTree.Key) data.getSerializable(NetworkLibraryActivity.TREE_KEY_KEY);
            final NetworkTree tree = library.getTreeByKey(key);
            if (tree instanceof SearchCatalogTree) {
                final SearchCatalogTree searchTree = (SearchCatalogTree) tree;
                final String pattern = intent.getStringExtra(SearchManager.QUERY);
                final MimeType mime = searchTree.getMimeType();
                if (MimeType.APP_ATOM_XML.weakEquals(mime)) {
                    searchTree.startItemsLoader(myNetworkContext, pattern);
                } else if (MimeType.TEXT_HTML.weakEquals(mime)) {
                    Util.openInBrowser(this, searchTree.getUrl(pattern));
                }
            }
        }
    }
    finish();
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) MimeType(org.geometerplus.zlibrary.core.util.MimeType) NetworkLibrary(org.geometerplus.fbreader.network.NetworkLibrary) SearchCatalogTree(org.geometerplus.fbreader.network.tree.SearchCatalogTree) NetworkTree(org.geometerplus.fbreader.network.NetworkTree)

Example 4 with NetworkLibrary

use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.

the class RunSearchAction method run.

@Override
public void run(NetworkTree tree) {
    final Bundle bundle = new Bundle();
    bundle.putSerializable(NetworkLibraryActivity.TREE_KEY_KEY, getSearchTree(tree).getUniqueKey());
    final NetworkLibrary library = myLibrary;
    if (DeviceType.Instance().hasStandardSearchDialog()) {
        myActivity.startSearch(library.NetworkSearchPatternOption.getValue(), true, bundle, false);
    } else {
        SearchDialogUtil.showDialog(myActivity, NetworkSearchActivity.class, library.NetworkSearchPatternOption.getValue(), null, bundle);
    }
}
Also used : Bundle(android.os.Bundle) NetworkLibrary(org.geometerplus.fbreader.network.NetworkLibrary)

Example 5 with NetworkLibrary

use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.

the class BookElementManager method startLoading.

private void startLoading(final String url, final List<BookElement> elements) {
    final NetworkLibrary library = NetworkLibrary.Instance(myView.Application.SystemInfo);
    new Thread() {

        public void run() {
            final SimpleOPDSFeedHandler handler = new SimpleOPDSFeedHandler(library, url);
            try {
                new QuietNetworkContext().perform(new ZLNetworkRequest.Get(url, true) {

                    @Override
                    public void handleStream(InputStream inputStream, int length) throws IOException, ZLNetworkException {
                        new OPDSXMLReader(library, handler, false).read(inputStream);
                    }
                });
                if (handler.books().isEmpty()) {
                    throw new RuntimeException();
                }
                myTimer = null;
                final List<OPDSBookItem> items = handler.books();
                int index = 0;
                for (BookElement book : elements) {
                    book.setData(items.get(index));
                    index = (index + 1) % items.size();
                    myScreenRefresher.run();
                }
            } catch (Exception e) {
                if (myTimer == null) {
                    myTimer = new Timer();
                }
                myTimer.schedule(new TimerTask() {

                    @Override
                    public void run() {
                        startLoading(url, elements);
                    }
                }, 10000);
                e.printStackTrace();
            }
        }
    }.start();
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) NetworkLibrary(org.geometerplus.fbreader.network.NetworkLibrary)

Aggregations

NetworkLibrary (org.geometerplus.fbreader.network.NetworkLibrary)7 Intent (android.content.Intent)3 ZLNetworkException (org.geometerplus.zlibrary.core.network.ZLNetworkException)3 Bundle (android.os.Bundle)2 NetworkAuthenticationManager (org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 View (android.view.View)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ActivityNetworkContext (org.geometerplus.android.fbreader.network.auth.ActivityNetworkContext)1 NetworkTree (org.geometerplus.fbreader.network.NetworkTree)1 SearchCatalogTree (org.geometerplus.fbreader.network.tree.SearchCatalogTree)1 ZLResource (org.geometerplus.zlibrary.core.resources.ZLResource)1 MimeType (org.geometerplus.zlibrary.core.util.MimeType)1