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;
}
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;
}
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();
}
}
};
}
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);
}
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);
}
}
Aggregations