Search in sources :

Example 1 with NetworkAuthenticationManager

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

the class TopupAction method getContextLabel.

@Override
public String getContextLabel(NetworkTree tree) {
    final INetworkLink link = tree.getLink();
    Money account = null;
    if (link != null) {
        final NetworkAuthenticationManager mgr = link.authenticationManager();
        if (mgr != null && mgr.mayBeAuthorised(false)) {
            account = mgr.currentAccount();
        }
    }
    return super.getContextLabel(tree).replace("%s", account != null ? account.toString() : "");
}
Also used : NetworkAuthenticationManager(org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager) Money(org.geometerplus.zlibrary.core.money.Money) INetworkLink(org.geometerplus.fbreader.network.INetworkLink)

Example 2 with NetworkAuthenticationManager

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

the class BuyBooksActivity method updateAuthorisationState.

private void updateAuthorisationState() {
    new Thread(new Runnable() {

        public void run() {
            final NetworkAuthenticationManager mgr = myLink.authenticationManager();
            try {
                if (mgr.isAuthorised(true)) {
                    setupUI(AuthorisationState.Authorised);
                    refreshAccountInformation();
                } else {
                    setupUI(AuthorisationState.NotAuthorised);
                }
            } catch (ZLNetworkException e) {
                e.printStackTrace();
                setupUI(AuthorisationState.NotAuthorised);
            }
        }
    }).start();
}
Also used : NetworkAuthenticationManager(org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager) ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException)

Example 3 with NetworkAuthenticationManager

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

the class Util method runAuthenticationDialog.

public static void runAuthenticationDialog(Activity activity, INetworkLink link, Runnable onSuccess) {
    final NetworkAuthenticationManager mgr = link.authenticationManager();
    final Intent intent = intentByLink(new Intent(activity, AuthenticationActivity.class), link);
    AuthenticationActivity.registerRunnable(intent, onSuccess);
    intent.putExtra(AuthenticationActivity.USERNAME_KEY, mgr.getUserName());
    intent.putExtra(AuthenticationActivity.SCHEME_KEY, "https");
    intent.putExtra(AuthenticationActivity.CUSTOM_AUTH_KEY, true);
    activity.startActivity(intent);
}
Also used : NetworkAuthenticationManager(org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager) Intent(android.content.Intent)

Example 4 with NetworkAuthenticationManager

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

the class SignOutAction method isVisible.

@Override
public boolean isVisible(NetworkTree tree) {
    if (!(tree instanceof NetworkCatalogRootTree)) {
        return false;
    }
    final INetworkLink link = tree.getLink();
    if (link instanceof ISyncNetworkLink) {
        return ((ISyncNetworkLink) link).isLoggedIn(myNetworkContext);
    }
    final NetworkAuthenticationManager mgr = link.authenticationManager();
    return mgr != null && mgr.mayBeAuthorised(false);
}
Also used : NetworkAuthenticationManager(org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager) NetworkCatalogRootTree(org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree)

Example 5 with NetworkAuthenticationManager

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

the class SignOutAction method run.

@Override
public void run(NetworkTree tree) {
    final INetworkLink link = tree.getLink();
    if (link instanceof ISyncNetworkLink) {
        ((ISyncNetworkLink) link).logout(myNetworkContext);
        ((NetworkCatalogRootTree) tree).clearCatalog();
        return;
    }
    final NetworkAuthenticationManager mgr = link.authenticationManager();
    final Runnable runnable = new Runnable() {

        public void run() {
            if (mgr.mayBeAuthorised(false)) {
                mgr.logOut();
                myActivity.runOnUiThread(new Runnable() {

                    public void run() {
                        myLibrary.invalidateVisibility();
                        myLibrary.synchronize();
                    }
                });
            }
        }
    };
    UIUtil.wait("signOut", runnable, myActivity);
}
Also used : NetworkAuthenticationManager(org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager) NetworkCatalogRootTree(org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree)

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