mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 12:00:17 +02:00
see previous comment
This commit is contained in:
parent
d72b9d5596
commit
f6ff196930
12 changed files with 116 additions and 75 deletions
|
@ -390,7 +390,7 @@ class NetworkBookActions extends NetworkTreeActions {
|
||||||
buttonKey = "refillAccount";
|
buttonKey = "refillAccount";
|
||||||
action = new DialogInterface.OnClickListener() {
|
action = new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
new RefillAccountActions().runStandalone(activity, book.Link);
|
new TopupActions().runStandalone(activity, book.Link);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -126,12 +126,12 @@ public class NetworkBookInfoActivity extends Activity implements NetworkView.Eve
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||||
NetworkView.Instance().getTopUpActions().buildContextMenu(this, menu, myBook.Link);
|
NetworkView.Instance().getTopupActions().buildContextMenu(this, menu, myBook.Link);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
RefillAccountActions.runAction(this, myBook.Link, item.getItemId());
|
TopupActions.runAction(this, myBook.Link, item.getItemId());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
public static final int SIGNUP_ITEM_ID = 3;
|
public static final int SIGNUP_ITEM_ID = 3;
|
||||||
public static final int SIGNIN_ITEM_ID = 4;
|
public static final int SIGNIN_ITEM_ID = 4;
|
||||||
public static final int SIGNOUT_ITEM_ID = 5;
|
public static final int SIGNOUT_ITEM_ID = 5;
|
||||||
public static final int REFILL_ACCOUNT_ITEM_ID = 6;
|
public static final int TOPUP_ITEM_ID = 6;
|
||||||
|
|
||||||
public static final int CUSTOM_CATALOG_EDIT = 7;
|
public static final int CUSTOM_CATALOG_EDIT = 7;
|
||||||
public static final int CUSTOM_CATALOG_REMOVE = 8;
|
public static final int CUSTOM_CATALOG_REMOVE = 8;
|
||||||
|
@ -95,10 +95,10 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
if (mgr != null) {
|
if (mgr != null) {
|
||||||
if (mgr.mayBeAuthorised(false)) {
|
if (mgr.mayBeAuthorised(false)) {
|
||||||
addMenuItem(menu, SIGNOUT_ITEM_ID, "signOut", mgr.currentUserName());
|
addMenuItem(menu, SIGNOUT_ITEM_ID, "signOut", mgr.currentUserName());
|
||||||
if (mgr.refillAccountLink() != null) {
|
if (Util.isTopupSupported(activity, item.Link)) {
|
||||||
final String account = mgr.currentAccount();
|
final String account = mgr.currentAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
addMenuItem(menu, REFILL_ACCOUNT_ITEM_ID, "refillAccount", account);
|
addMenuItem(menu, TOPUP_ITEM_ID, "refillAccount", account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -161,7 +161,7 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
addOptionsItem(menu, SIGNIN_ITEM_ID, "signIn");
|
addOptionsItem(menu, SIGNIN_ITEM_ID, "signIn");
|
||||||
addOptionsItem(menu, SIGNUP_ITEM_ID, "signUp");
|
addOptionsItem(menu, SIGNUP_ITEM_ID, "signUp");
|
||||||
addOptionsItem(menu, SIGNOUT_ITEM_ID, "signOut", "");
|
addOptionsItem(menu, SIGNOUT_ITEM_ID, "signOut", "");
|
||||||
addOptionsItem(menu, REFILL_ACCOUNT_ITEM_ID, "refillAccount");
|
addOptionsItem(menu, TOPUP_ITEM_ID, "refillAccount");
|
||||||
if (((NetworkCatalogTree)tree).Item instanceof BasketItem) {
|
if (((NetworkCatalogTree)tree).Item instanceof BasketItem) {
|
||||||
addOptionsItem(menu, BASKET_CLEAR, "clearBasket");
|
addOptionsItem(menu, BASKET_CLEAR, "clearBasket");
|
||||||
addOptionsItem(menu, BASKET_BUY_ALL_BOOKS, "buyAllBooks");
|
addOptionsItem(menu, BASKET_BUY_ALL_BOOKS, "buyAllBooks");
|
||||||
|
@ -182,7 +182,7 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
|
|
||||||
boolean signIn = false;
|
boolean signIn = false;
|
||||||
boolean signOut = false;
|
boolean signOut = false;
|
||||||
boolean refill = false;
|
boolean topup = false;
|
||||||
String userName = null;
|
String userName = null;
|
||||||
String account = null;
|
String account = null;
|
||||||
NetworkAuthenticationManager mgr = item.Link.authenticationManager();
|
NetworkAuthenticationManager mgr = item.Link.authenticationManager();
|
||||||
|
@ -191,8 +191,8 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
userName = mgr.currentUserName();
|
userName = mgr.currentUserName();
|
||||||
signOut = true;
|
signOut = true;
|
||||||
account = mgr.currentAccount();
|
account = mgr.currentAccount();
|
||||||
if (mgr.refillAccountLink() != null && account != null) {
|
if (account != null && Util.isTopupSupported(activity, item.Link)) {
|
||||||
refill = true;
|
topup = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
signIn = true;
|
signIn = true;
|
||||||
|
@ -204,7 +204,7 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
prepareOptionsItem(menu, SIGNIN_ITEM_ID, signIn);
|
prepareOptionsItem(menu, SIGNIN_ITEM_ID, signIn);
|
||||||
prepareOptionsItem(menu, SIGNUP_ITEM_ID, signIn & Util.isRegistrationSupported(activity, item.Link));
|
prepareOptionsItem(menu, SIGNUP_ITEM_ID, signIn & Util.isRegistrationSupported(activity, item.Link));
|
||||||
prepareOptionsItem(menu, SIGNOUT_ITEM_ID, signOut, "signOut", userName);
|
prepareOptionsItem(menu, SIGNOUT_ITEM_ID, signOut, "signOut", userName);
|
||||||
prepareOptionsItem(menu, REFILL_ACCOUNT_ITEM_ID, refill);
|
prepareOptionsItem(menu, TOPUP_ITEM_ID, topup);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,8 +267,8 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
case SIGNOUT_ITEM_ID:
|
case SIGNOUT_ITEM_ID:
|
||||||
doSignOut(activity, catalogTree);
|
doSignOut(activity, catalogTree);
|
||||||
return true;
|
return true;
|
||||||
case REFILL_ACCOUNT_ITEM_ID:
|
case TOPUP_ITEM_ID:
|
||||||
new RefillAccountActions().runStandalone(activity, item.Link);
|
new TopupActions().runStandalone(activity, item.Link);
|
||||||
return true;
|
return true;
|
||||||
case CUSTOM_CATALOG_EDIT:
|
case CUSTOM_CATALOG_EDIT:
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,8 +66,8 @@ public class NetworkCatalogActivity extends NetworkBaseActivity implements UserR
|
||||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||||
if (menuInfo == null && myTree instanceof NetworkCatalogTree) {
|
if (menuInfo == null && myTree instanceof NetworkCatalogTree) {
|
||||||
final INetworkLink link = ((NetworkCatalogTree)myTree).Item.Link;
|
final INetworkLink link = ((NetworkCatalogTree)myTree).Item.Link;
|
||||||
if (Util.isAccountRefillingSupported(this, link)) {
|
if (Util.isTopupSupported(this, link)) {
|
||||||
final RefillAccountActions actions = NetworkView.Instance().getTopUpActions();
|
final TopupActions actions = NetworkView.Instance().getTopupActions();
|
||||||
if (actions != null) {
|
if (actions != null) {
|
||||||
actions.buildContextMenu(this, menu, link);
|
actions.buildContextMenu(this, menu, link);
|
||||||
return;
|
return;
|
||||||
|
@ -81,8 +81,8 @@ public class NetworkCatalogActivity extends NetworkBaseActivity implements UserR
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
if ((item == null || item.getMenuInfo() == null) && myTree instanceof NetworkCatalogTree) {
|
if ((item == null || item.getMenuInfo() == null) && myTree instanceof NetworkCatalogTree) {
|
||||||
final INetworkLink link = ((NetworkCatalogTree)myTree).Item.Link;
|
final INetworkLink link = ((NetworkCatalogTree)myTree).Item.Link;
|
||||||
if (Util.isAccountRefillingSupported(this, link)) {
|
if (Util.isTopupSupported(this, link)) {
|
||||||
final RefillAccountActions actions = NetworkView.Instance().getTopUpActions();
|
final TopupActions actions = NetworkView.Instance().getTopupActions();
|
||||||
if (actions != null && actions.runAction(this, link, item.getItemId())) {
|
if (actions != null && actions.runAction(this, link, item.getItemId())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ class NetworkView {
|
||||||
|
|
||||||
private volatile boolean myInitialized;
|
private volatile boolean myInitialized;
|
||||||
private final ArrayList<NetworkTreeActions> myActions = new ArrayList<NetworkTreeActions>();
|
private final ArrayList<NetworkTreeActions> myActions = new ArrayList<NetworkTreeActions>();
|
||||||
private RefillAccountActions myTopUpActions;
|
private TopupActions myTopupActions;
|
||||||
|
|
||||||
private NetworkView() {
|
private NetworkView() {
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,8 @@ class NetworkView {
|
||||||
myActions.add(new NetworkBookActions());
|
myActions.add(new NetworkBookActions());
|
||||||
myActions.add(new NetworkCatalogActions());
|
myActions.add(new NetworkCatalogActions());
|
||||||
myActions.add(new SearchItemActions());
|
myActions.add(new SearchItemActions());
|
||||||
myTopUpActions = new RefillAccountActions();
|
myTopupActions = new TopupActions();
|
||||||
myActions.add(myTopUpActions);
|
myActions.add(myTopupActions);
|
||||||
myActions.add(new AddCustomCatalogItemActions());
|
myActions.add(new AddCustomCatalogItemActions());
|
||||||
myActions.trimToSize();
|
myActions.trimToSize();
|
||||||
|
|
||||||
|
@ -91,8 +91,8 @@ class NetworkView {
|
||||||
* NetworkItem's actions
|
* NetworkItem's actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public RefillAccountActions getTopUpActions() {
|
public TopupActions getTopupActions() {
|
||||||
return myTopUpActions;
|
return myTopupActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkTreeActions getActions(NetworkTree tree) {
|
public NetworkTreeActions getActions(NetworkTree tree) {
|
||||||
|
|
|
@ -29,10 +29,10 @@ import org.geometerplus.fbreader.network.NetworkTree;
|
||||||
import org.geometerplus.fbreader.network.tree.TopUpTree;
|
import org.geometerplus.fbreader.network.tree.TopUpTree;
|
||||||
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
||||||
|
|
||||||
class RefillAccountActions extends NetworkTreeActions {
|
class TopupActions extends NetworkTreeActions {
|
||||||
public static final int REFILL_VIA_SMS_ITEM_ID = 0;
|
public static final int TOPUP_VIA_SMS_ITEM_ID = 0;
|
||||||
public static final int REFILL_VIA_BROWSER_ITEM_ID = 1;
|
public static final int TOPUP_VIA_BROWSER_ITEM_ID = 1;
|
||||||
|
public static final int TOPUP_VIA_CREDIT_CARD_ITEM_ID = 2;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canHandleTree(NetworkTree tree) {
|
public boolean canHandleTree(NetworkTree tree) {
|
||||||
|
@ -47,11 +47,14 @@ class RefillAccountActions extends NetworkTreeActions {
|
||||||
void buildContextMenu(Activity activity, ContextMenu menu, INetworkLink link) {
|
void buildContextMenu(Activity activity, ContextMenu menu, INetworkLink link) {
|
||||||
menu.setHeaderTitle(getTitleValue("refillTitle"));
|
menu.setHeaderTitle(getTitleValue("refillTitle"));
|
||||||
|
|
||||||
if (Util.isSmsAccountRefillingSupported(activity, link)) {
|
if (Util.isSmsTopupSupported(activity, link)) {
|
||||||
addMenuItem(menu, REFILL_VIA_SMS_ITEM_ID, "refillViaSms");
|
addMenuItem(menu, TOPUP_VIA_CREDIT_CARD_ITEM_ID, "refillViaCreditCard");
|
||||||
}
|
}
|
||||||
if (Util.isBrowserAccountRefillingSupported(activity, link)) {
|
if (Util.isSmsTopupSupported(activity, link)) {
|
||||||
addMenuItem(menu, REFILL_VIA_BROWSER_ITEM_ID, "refillViaBrowser");
|
addMenuItem(menu, TOPUP_VIA_SMS_ITEM_ID, "refillViaSms");
|
||||||
|
}
|
||||||
|
if (Util.isBrowserTopupSupported(activity, link)) {
|
||||||
|
addMenuItem(menu, TOPUP_VIA_BROWSER_ITEM_ID, "refillViaBrowser");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,15 +63,22 @@ class RefillAccountActions extends NetworkTreeActions {
|
||||||
return getDefaultActionCode(activity, ((TopUpTree)tree).Item.Link);
|
return getDefaultActionCode(activity, ((TopUpTree)tree).Item.Link);
|
||||||
}
|
}
|
||||||
private int getDefaultActionCode(Activity activity, INetworkLink link) {
|
private int getDefaultActionCode(Activity activity, INetworkLink link) {
|
||||||
final boolean sms = Util.isSmsAccountRefillingSupported(activity, link);
|
final boolean sms = Util.isSmsTopupSupported(activity, link);
|
||||||
final boolean browser = Util.isBrowserAccountRefillingSupported(activity, link);
|
final boolean browser = Util.isBrowserTopupSupported(activity, link);
|
||||||
|
final boolean creditCard = Util.isCreditCardTopupSupported(activity, link);
|
||||||
|
final int count =
|
||||||
|
(sms ? 1 : 0) +
|
||||||
|
(browser ? 1 : 0) +
|
||||||
|
(creditCard ? 1 : 0);
|
||||||
|
|
||||||
if (sms && browser) {
|
if (count > 1) {
|
||||||
return TREE_SHOW_CONTEXT_MENU;
|
return TREE_SHOW_CONTEXT_MENU;
|
||||||
} else if (sms) {
|
} else if (sms) {
|
||||||
return REFILL_VIA_SMS_ITEM_ID;
|
return TOPUP_VIA_SMS_ITEM_ID;
|
||||||
|
} else if (creditCard) {
|
||||||
|
return TOPUP_VIA_CREDIT_CARD_ITEM_ID;
|
||||||
} else /* if (browser) */ {
|
} else /* if (browser) */ {
|
||||||
return REFILL_VIA_BROWSER_ITEM_ID;
|
return TOPUP_VIA_BROWSER_ITEM_ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,51 +104,62 @@ class RefillAccountActions extends NetworkTreeActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean runAction(Activity activity, INetworkLink link, int actionCode) {
|
static boolean runAction(Activity activity, INetworkLink link, int actionCode) {
|
||||||
Runnable refillRunnable = null;
|
Runnable topupRunnable = null;
|
||||||
switch (actionCode) {
|
switch (actionCode) {
|
||||||
case REFILL_VIA_SMS_ITEM_ID:
|
case TOPUP_VIA_SMS_ITEM_ID:
|
||||||
refillRunnable = smsRefillRunnable(activity, link);
|
topupRunnable = smsTopupRunnable(activity, link);
|
||||||
break;
|
break;
|
||||||
case REFILL_VIA_BROWSER_ITEM_ID:
|
case TOPUP_VIA_BROWSER_ITEM_ID:
|
||||||
refillRunnable = browserRefillRunnable(activity, link);
|
topupRunnable = browserTopupRunnable(activity, link);
|
||||||
|
break;
|
||||||
|
case TOPUP_VIA_CREDIT_CARD_ITEM_ID:
|
||||||
|
topupRunnable = creditCardTopupRunnable(activity, link);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refillRunnable == null) {
|
if (topupRunnable == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
doRefill(activity, link, refillRunnable);
|
doTopup(activity, link, topupRunnable);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Runnable browserRefillRunnable(final Activity activity, final INetworkLink link) {
|
private static Runnable browserTopupRunnable(final Activity activity, final INetworkLink link) {
|
||||||
return new Runnable() {
|
return new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Util.openInBrowser(
|
Util.openInBrowser(
|
||||||
activity,
|
activity,
|
||||||
link.authenticationManager().refillAccountLink()
|
link.authenticationManager().topupLink()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Runnable smsRefillRunnable(final Activity activity, final INetworkLink link) {
|
private static Runnable smsTopupRunnable(final Activity activity, final INetworkLink link) {
|
||||||
return new Runnable() {
|
return new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Util.runSmsDialog(activity, link);
|
Util.runSmsTopupDialog(activity, link);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doRefill(final Activity activity, final INetworkLink link, final Runnable refiller) {
|
private static Runnable creditCardTopupRunnable(final Activity activity, final INetworkLink link) {
|
||||||
|
return new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
Util.runCreditCardTopupDialog(activity, link);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void doTopup(final Activity activity, final INetworkLink link, final Runnable action) {
|
||||||
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||||
if (mgr.mayBeAuthorised(false)) {
|
if (mgr.mayBeAuthorised(false)) {
|
||||||
refiller.run();
|
action.run();
|
||||||
} else {
|
} else {
|
||||||
AuthenticationDialog.show(activity, link, new Runnable() {
|
AuthenticationDialog.show(activity, link, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (mgr.mayBeAuthorised(false)) {
|
if (mgr.mayBeAuthorised(false)) {
|
||||||
refiller.run();
|
action.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -146,8 +167,8 @@ class RefillAccountActions extends NetworkTreeActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runStandalone(Activity activity, INetworkLink link) {
|
public void runStandalone(Activity activity, INetworkLink link) {
|
||||||
final int refillActionCode = getDefaultActionCode(activity, link);
|
final int topupActionCode = getDefaultActionCode(activity, link);
|
||||||
if (refillActionCode == TREE_SHOW_CONTEXT_MENU) {
|
if (topupActionCode == TREE_SHOW_CONTEXT_MENU) {
|
||||||
//activity.getListView().showContextMenu();
|
//activity.getListView().showContextMenu();
|
||||||
View view = null;
|
View view = null;
|
||||||
if (activity instanceof NetworkBaseActivity) {
|
if (activity instanceof NetworkBaseActivity) {
|
||||||
|
@ -158,8 +179,8 @@ class RefillAccountActions extends NetworkTreeActions {
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
view.showContextMenu();
|
view.showContextMenu();
|
||||||
}
|
}
|
||||||
} else if (refillActionCode >= 0) {
|
} else if (topupActionCode >= 0) {
|
||||||
runAction(activity, link, refillActionCode);
|
runAction(activity, link, topupActionCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,10 @@ import org.geometerplus.android.util.PackageUtil;
|
||||||
abstract class Util implements UserRegistrationConstants {
|
abstract class Util implements UserRegistrationConstants {
|
||||||
private static final String REGISTRATION_ACTION =
|
private static final String REGISTRATION_ACTION =
|
||||||
"android.fbreader.action.NETWORK_LIBRARY_REGISTER";
|
"android.fbreader.action.NETWORK_LIBRARY_REGISTER";
|
||||||
private static final String SMS_REFILLING_ACTION =
|
private static final String SMS_TOPUP_ACTION =
|
||||||
"android.fbreader.action.NETWORK_LIBRARY_SMS_REFILLING";
|
"android.fbreader.action.NETWORK_LIBRARY_SMS_REFILLING";
|
||||||
|
private static final String CREDIT_CARD_TOPUP_ACTION =
|
||||||
|
"android.fbreader.action.NETWORK_LIBRARY_CREDIT_CARD_TOPUP";
|
||||||
|
|
||||||
private static boolean testService(Activity activity, String action, String url) {
|
private static boolean testService(Activity activity, String action, String url) {
|
||||||
return url != null && PackageUtil.canBeStarted(activity, new Intent(action, Uri.parse(url)), true);
|
return url != null && PackageUtil.canBeStarted(activity, new Intent(action, Uri.parse(url)), true);
|
||||||
|
@ -83,29 +85,46 @@ abstract class Util implements UserRegistrationConstants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isAccountRefillingSupported(Activity activity, INetworkLink link) {
|
static boolean isTopupSupported(Activity activity, INetworkLink link) {
|
||||||
return
|
return
|
||||||
isBrowserAccountRefillingSupported(activity, link) ||
|
isBrowserTopupSupported(activity, link) ||
|
||||||
isSmsAccountRefillingSupported(activity, link);
|
isCreditCardTopupSupported(activity, link) ||
|
||||||
|
isSmsTopupSupported(activity, link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isSmsAccountRefillingSupported(Activity activity, INetworkLink link) {
|
static boolean isSmsTopupSupported(Activity activity, INetworkLink link) {
|
||||||
return testService(
|
return testService(
|
||||||
activity,
|
activity,
|
||||||
SMS_REFILLING_ACTION,
|
SMS_TOPUP_ACTION,
|
||||||
link.getUrlInfo(INetworkLink.URL_MAIN).URL
|
link.getUrlInfo(INetworkLink.URL_MAIN).URL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void runSmsDialog(Activity activity, INetworkLink link) {
|
static boolean isCreditCardTopupSupported(Activity activity, INetworkLink link) {
|
||||||
|
return testService(
|
||||||
|
activity,
|
||||||
|
CREDIT_CARD_TOPUP_ACTION,
|
||||||
|
link.getUrlInfo(INetworkLink.URL_MAIN).URL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void runSmsTopupDialog(Activity activity, INetworkLink link) {
|
||||||
|
runTopupDialog(activity, link, SMS_TOPUP_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void runCreditCardTopupDialog(Activity activity, INetworkLink link) {
|
||||||
|
runTopupDialog(activity, link, CREDIT_CARD_TOPUP_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void runTopupDialog(Activity activity, INetworkLink link, String action) {
|
||||||
try {
|
try {
|
||||||
final Intent intent = new Intent(
|
final Intent intent = new Intent(
|
||||||
SMS_REFILLING_ACTION,
|
action,
|
||||||
Uri.parse(link.getUrlInfo(INetworkLink.URL_MAIN).URL)
|
Uri.parse(link.getUrlInfo(INetworkLink.URL_MAIN).URL)
|
||||||
);
|
);
|
||||||
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||||
if (mgr != null) {
|
if (mgr != null) {
|
||||||
for (Map.Entry<String,String> entry : mgr.getSmsRefillingData().entrySet()) {
|
for (Map.Entry<String,String> entry : mgr.getTopupData().entrySet()) {
|
||||||
intent.putExtra(entry.getKey(), entry.getValue());
|
intent.putExtra(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,8 +135,8 @@ abstract class Util implements UserRegistrationConstants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isBrowserAccountRefillingSupported(Activity activity, INetworkLink link) {
|
static boolean isBrowserTopupSupported(Activity activity, INetworkLink link) {
|
||||||
return link.getUrlInfo(INetworkLink.URL_REFILL_ACCOUNT).URL != null;
|
return link.getUrlInfo(INetworkLink.URL_TOPUP).URL != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void openInBrowser(Context context, String url) {
|
static void openInBrowser(Context context, String url) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ public interface INetworkLink {
|
||||||
String URL_SIGN_IN = "signIn";
|
String URL_SIGN_IN = "signIn";
|
||||||
String URL_SIGN_OUT = "signOut";
|
String URL_SIGN_OUT = "signOut";
|
||||||
String URL_SIGN_UP = "signUp";
|
String URL_SIGN_UP = "signUp";
|
||||||
String URL_REFILL_ACCOUNT = "refillAccount";
|
String URL_TOPUP = "topup";
|
||||||
String URL_RECOVER_PASSWORD = "recoverPassword";
|
String URL_RECOVER_PASSWORD = "recoverPassword";
|
||||||
|
|
||||||
String getSiteName();
|
String getSiteName();
|
||||||
|
|
|
@ -63,8 +63,6 @@ public abstract class NetworkAuthenticationManager {
|
||||||
public abstract void authorise(String password) throws ZLNetworkException;
|
public abstract void authorise(String password) throws ZLNetworkException;
|
||||||
public abstract void logOut();
|
public abstract void logOut();
|
||||||
public abstract BookReference downloadReference(NetworkBookItem book);
|
public abstract BookReference downloadReference(NetworkBookItem book);
|
||||||
public abstract Map<String,String> getSmsRefillingData();
|
|
||||||
|
|
||||||
|
|
||||||
public final boolean mayBeAuthorised(boolean useNetwork) {
|
public final boolean mayBeAuthorised(boolean useNetwork) {
|
||||||
try {
|
try {
|
||||||
|
@ -107,12 +105,15 @@ public abstract class NetworkAuthenticationManager {
|
||||||
//public abstract ZLNetworkSSLCertificate certificate();
|
//public abstract ZLNetworkSSLCertificate certificate();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* refill account
|
* topup account
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public String refillAccountLink() {
|
public String topupLink() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public Map<String,String> getTopupData() {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void initUser(String userName, String sid) throws ZLNetworkException;
|
public abstract void initUser(String userName, String sid) throws ZLNetworkException;
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String refillAccountLink() {
|
public String topupLink() {
|
||||||
final String sid;
|
final String sid;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
sid = mySidOption.getValue();
|
sid = mySidOption.getValue();
|
||||||
|
@ -241,7 +241,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
||||||
if (sid.length() == 0) {
|
if (sid.length() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final String url = Link.getUrlInfo(INetworkLink.URL_REFILL_ACCOUNT).URL;
|
final String url = Link.getUrlInfo(INetworkLink.URL_TOPUP).URL;
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -411,7 +411,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String,String> getSmsRefillingData() {
|
public Map<String,String> getTopupData() {
|
||||||
final HashMap<String,String> map = new HashMap<String,String>();
|
final HashMap<String,String> map = new HashMap<String,String>();
|
||||||
map.put("litres:userId", myUserIdOption.getValue());
|
map.put("litres:userId", myUserIdOption.getValue());
|
||||||
map.put("litres:sid", mySidOption.getValue());
|
map.put("litres:sid", mySidOption.getValue());
|
||||||
|
|
|
@ -57,7 +57,7 @@ interface OPDSConstants {
|
||||||
String REL_LINK_SIGN_IN = "http://data.fbreader.org/catalog/sign-in";
|
String REL_LINK_SIGN_IN = "http://data.fbreader.org/catalog/sign-in";
|
||||||
String REL_LINK_SIGN_OUT = "http://data.fbreader.org/catalog/sign-out";
|
String REL_LINK_SIGN_OUT = "http://data.fbreader.org/catalog/sign-out";
|
||||||
String REL_LINK_SIGN_UP = "http://data.fbreader.org/catalog/sign-up";
|
String REL_LINK_SIGN_UP = "http://data.fbreader.org/catalog/sign-up";
|
||||||
String REL_LINK_REFILL_ACCOUNT = "http://data.fbreader.org/catalog/refill-account";
|
String REL_LINK_TOPUP = "http://data.fbreader.org/catalog/refill-account";
|
||||||
String REL_LINK_RECOVER_PASSWORD = "http://data.fbreader.org/catalog/recover-password";
|
String REL_LINK_RECOVER_PASSWORD = "http://data.fbreader.org/catalog/recover-password";
|
||||||
|
|
||||||
// Entry level / OPDS Link Conditions
|
// Entry level / OPDS Link Conditions
|
||||||
|
|
|
@ -133,8 +133,8 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
|
||||||
infos.put(INetworkLink.URL_SIGN_OUT, new UrlInfo(href));
|
infos.put(INetworkLink.URL_SIGN_OUT, new UrlInfo(href));
|
||||||
} else if (rel == REL_LINK_SIGN_UP) {
|
} else if (rel == REL_LINK_SIGN_UP) {
|
||||||
infos.put(INetworkLink.URL_SIGN_UP, new UrlInfo(href));
|
infos.put(INetworkLink.URL_SIGN_UP, new UrlInfo(href));
|
||||||
} else if (rel == REL_LINK_REFILL_ACCOUNT) {
|
} else if (rel == REL_LINK_TOPUP) {
|
||||||
infos.put(INetworkLink.URL_REFILL_ACCOUNT, new UrlInfo(href));
|
infos.put(INetworkLink.URL_TOPUP, new UrlInfo(href));
|
||||||
} else if (rel == REL_LINK_RECOVER_PASSWORD) {
|
} else if (rel == REL_LINK_RECOVER_PASSWORD) {
|
||||||
infos.put(INetworkLink.URL_RECOVER_PASSWORD, new UrlInfo(href));
|
infos.put(INetworkLink.URL_RECOVER_PASSWORD, new UrlInfo(href));
|
||||||
} else if (rel == REL_CONDITION_NEVER) {
|
} else if (rel == REL_CONDITION_NEVER) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue