Search in sources :

Example 6 with NetworkAuthenticationManager

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

the class SignOutAction method accountName.

private String accountName(NetworkTree tree) {
    final INetworkLink link = tree.getLink();
    if (link instanceof ISyncNetworkLink) {
        return SyncUtil.getAccountName(myNetworkContext);
    }
    final NetworkAuthenticationManager mgr = link.authenticationManager();
    return mgr != null && mgr.mayBeAuthorised(false) ? mgr.getVisibleUserName() : null;
}
Also used : NetworkAuthenticationManager(org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager)

Example 7 with NetworkAuthenticationManager

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

the class TopUpTree method getSummary.

@Override
public String getSummary() {
    final NetworkAuthenticationManager mgr = getLink().authenticationManager();
    try {
        if (mgr != null && mgr.isAuthorised(false)) {
            final Money account = mgr.currentAccount();
            final CharSequence summary = Item.getSummary();
            if (account != null && summary != null) {
                return summary.toString().replace("%s", account.toString());
            }
        }
    } catch (ZLNetworkException e) {
    }
    return null;
}
Also used : NetworkAuthenticationManager(org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager) ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException) Money(org.geometerplus.zlibrary.core.money.Money)

Example 8 with NetworkAuthenticationManager

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

the class BuyBooksActivity method buyRunnable.

private Runnable buyRunnable() {
    return new Runnable() {

        public void run() {
            try {
                final NetworkAuthenticationManager mgr = myLink.authenticationManager();
                for (final NetworkBookItem b : myBooks) {
                    if (b.getStatus(myBookCollection) != NetworkBookItem.Status.CanBePurchased) {
                        continue;
                    }
                    mgr.purchaseBook(b);
                    runOnUiThread(new Runnable() {

                        public void run() {
                            Util.doDownloadBook(BuyBooksActivity.this, b, false);
                        }
                    });
                }
                finish();
            } catch (final ZLNetworkException e) {
                final ZLResource dialogResource = ZLResource.resource("dialog");
                final ZLResource buttonResource = dialogResource.getResource("button");
                final ZLResource boxResource = dialogResource.getResource("networkError");
                runOnUiThread(new Runnable() {

                    public void run() {
                        new AlertDialog.Builder(BuyBooksActivity.this).setTitle(boxResource.getResource("title").getValue()).setMessage(e.getMessage()).setIcon(0).setPositiveButton(buttonResource.getResource("ok").getValue(), null).create().show();
                    }
                });
            } finally {
                myLibrary.invalidateVisibility();
                myLibrary.synchronize();
            }
        }
    };
}
Also used : NetworkAuthenticationManager(org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager) ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException) ZLResource(org.geometerplus.zlibrary.core.resources.ZLResource)

Example 9 with NetworkAuthenticationManager

use of org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager 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)

Example 10 with NetworkAuthenticationManager

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

the class ListenerCallback method onReceive.

@Override
public void onReceive(Context context, final Intent intent) {
    final NetworkLibrary library = Util.networkLibrary(context);
    if (Util.SIGNIN_ACTION.equals(intent.getAction())) {
        final String url = intent.getStringExtra(CATALOG_URL);
        final INetworkLink link = library.getLinkByUrl(url);
        if (link != null) {
            final NetworkAuthenticationManager mgr = link.authenticationManager();
            if (mgr instanceof LitResAuthenticationManager) {
                new Thread(new Runnable() {

                    public void run() {
                        try {
                            processSignup((LitResAuthenticationManager) mgr, intent);
                        } catch (ZLNetworkException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        }
    } else {
        library.fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
    }
}
Also used : NetworkAuthenticationManager(org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager) ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException) LitResAuthenticationManager(org.geometerplus.fbreader.network.authentication.litres.LitResAuthenticationManager)

Aggregations

NetworkAuthenticationManager (org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager)12 ZLNetworkException (org.geometerplus.zlibrary.core.network.ZLNetworkException)6 Intent (android.content.Intent)2 NetworkLibrary (org.geometerplus.fbreader.network.NetworkLibrary)2 NetworkCatalogRootTree (org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree)2 Money (org.geometerplus.zlibrary.core.money.Money)2 ZLResource (org.geometerplus.zlibrary.core.resources.ZLResource)2 View (android.view.View)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 INetworkLink (org.geometerplus.fbreader.network.INetworkLink)1 LitResAuthenticationManager (org.geometerplus.fbreader.network.authentication.litres.LitResAuthenticationManager)1 NetworkBookTree (org.geometerplus.fbreader.network.tree.NetworkBookTree)1