Search in sources :

Example 1 with NetworkBookTree

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

the class BuyBooksActivity method run.

public static void run(Activity activity, List<NetworkBookTree> trees) {
    if (trees.isEmpty()) {
        return;
    }
    final Intent intent = new Intent(activity, BuyBooksActivity.class);
    final ArrayList<NetworkTree.Key> keys = new ArrayList<NetworkTree.Key>(trees.size());
    for (NetworkBookTree t : trees) {
        keys.add(t.getUniqueKey());
    }
    intent.putExtra(NetworkLibraryActivity.TREE_KEY_KEY, keys);
    activity.startActivity(intent);
}
Also used : NetworkBookTree(org.geometerplus.fbreader.network.tree.NetworkBookTree) Intent(android.content.Intent)

Example 2 with NetworkBookTree

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

the class BuyBooksActivity method onCreate.

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
    myBookCollection.bindToService(this, null);
    myLibrary = Util.networkLibrary(this);
    final List<NetworkTree.Key> keys = (List<NetworkTree.Key>) getIntent().getSerializableExtra(NetworkLibraryActivity.TREE_KEY_KEY);
    if (keys == null || keys.isEmpty()) {
        finish();
        return;
    }
    myBooks = new ArrayList<NetworkBookItem>(keys.size());
    for (NetworkTree.Key k : keys) {
        final NetworkTree tree = myLibrary.getTreeByKey(k);
        if (tree instanceof NetworkBookTree) {
            myBooks.add(((NetworkBookTree) tree).Book);
        } else {
            finish();
            return;
        }
    }
    myLink = myBooks.get(0).Link;
    final NetworkAuthenticationManager mgr = myLink.authenticationManager();
    if (mgr == null) {
        finish();
        return;
    }
    try {
        if (!mgr.isAuthorised(true)) {
            buttonsView().setVisibility(View.GONE);
            AuthorisationMenuActivity.runMenu(this, myLink, 1);
        }
    } catch (ZLNetworkException e) {
    }
    myCost = calculateCost();
    if (myCost == null) {
        // TODO: error message
        finish();
        return;
    }
    myAccount = mgr.currentAccount();
    setupUI(AuthorisationState.Authorised);
    myLibrary.addChangeListener(this);
}
Also used : NetworkAuthenticationManager(org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager) ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException) NetworkBookTree(org.geometerplus.fbreader.network.tree.NetworkBookTree)

Aggregations

NetworkBookTree (org.geometerplus.fbreader.network.tree.NetworkBookTree)2 Intent (android.content.Intent)1 NetworkAuthenticationManager (org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager)1 ZLNetworkException (org.geometerplus.zlibrary.core.network.ZLNetworkException)1