mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
changes to call autoregistration dialog
This commit is contained in:
parent
bfe46be8cf
commit
a66e83a956
3 changed files with 79 additions and 8 deletions
|
@ -670,6 +670,12 @@
|
|||
<node name="title" value="Purchase book" />
|
||||
<node name="message" value="Book is already bought" />
|
||||
</node>
|
||||
<node name="purchaseActions">
|
||||
<node name="title" value="Choose action" />
|
||||
<node name="signIn" value="Sign in" />
|
||||
<node name="signUp" value="Sign up" />
|
||||
<node name="quickBuy" value="Quick buy" />
|
||||
</node>
|
||||
</node>
|
||||
<node name="errorMessage">
|
||||
<node name="cannotRunAndroidMarket" value="Cannot access Android Market. Please, install %s manually"/>
|
||||
|
|
|
@ -43,6 +43,8 @@ import org.geometerplus.android.util.PackageUtil;
|
|||
public abstract class Util implements UserRegistrationConstants {
|
||||
private static final String REGISTRATION_ACTION =
|
||||
"android.fbreader.action.NETWORK_LIBRARY_REGISTER";
|
||||
private static final String AUTOREGISTRATION_ACTION =
|
||||
"android.fbreader.action.NETWORK_LIBRARY_AUTOREGISTER";
|
||||
|
||||
static INetworkLink linkByIntent(Intent intent) {
|
||||
return NetworkLibrary.Instance().getLinkByUrl(intent.getData().toString());
|
||||
|
@ -64,6 +66,14 @@ public abstract class Util implements UserRegistrationConstants {
|
|||
);
|
||||
}
|
||||
|
||||
public static boolean isAutoregistrationSupported(Activity activity, INetworkLink link) {
|
||||
return testService(
|
||||
activity,
|
||||
AUTOREGISTRATION_ACTION,
|
||||
link.getUrl(UrlInfo.Type.SignUp)
|
||||
);
|
||||
}
|
||||
|
||||
public static void runRegistrationDialog(Activity activity, INetworkLink link) {
|
||||
try {
|
||||
final Intent intent = new Intent(
|
||||
|
@ -71,10 +81,20 @@ public abstract class Util implements UserRegistrationConstants {
|
|||
Uri.parse(link.getUrl(UrlInfo.Type.SignUp))
|
||||
);
|
||||
if (PackageUtil.canBeStarted(activity, intent, true)) {
|
||||
activity.startActivityForResult(new Intent(
|
||||
REGISTRATION_ACTION,
|
||||
Uri.parse(link.getUrl(UrlInfo.Type.SignUp))
|
||||
), NetworkLibraryActivity.SIGNUP_CODE);
|
||||
activity.startActivityForResult(intent, NetworkLibraryActivity.SIGNUP_CODE);
|
||||
}
|
||||
} catch (ActivityNotFoundException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void runAutoregistrationDialog(Activity activity, INetworkLink link) {
|
||||
try {
|
||||
final Intent intent = new Intent(
|
||||
AUTOREGISTRATION_ACTION,
|
||||
Uri.parse(link.getUrl(UrlInfo.Type.SignUp))
|
||||
);
|
||||
if (PackageUtil.canBeStarted(activity, intent, true)) {
|
||||
activity.startActivityForResult(intent, NetworkLibraryActivity.SIGNUP_CODE);
|
||||
}
|
||||
} catch (ActivityNotFoundException e) {
|
||||
}
|
||||
|
|
|
@ -381,11 +381,56 @@ public abstract class NetworkBookActions {
|
|||
if (mgr.isAuthorised(true)) {
|
||||
buyDialogRunnable.run();
|
||||
} else {
|
||||
Util.runAuthenticationDialog(activity, book.Link, new Runnable() {
|
||||
public void run() {
|
||||
activity.runOnUiThread(buyDialogRunnable);
|
||||
final String signInKey = "signIn";
|
||||
final String registerKey = "signUp";
|
||||
final String autoregisterKey = "quickBuy";
|
||||
|
||||
final ArrayList<String> items = new ArrayList<String>();
|
||||
items.add(signInKey);
|
||||
if (Util.isRegistrationSupported(activity, book.Link)) {
|
||||
items.add(registerKey);
|
||||
}
|
||||
if (Util.isAutoregistrationSupported(activity, book.Link)) {
|
||||
items.add(autoregisterKey);
|
||||
}
|
||||
|
||||
if (items.size() > 1) {
|
||||
final ZLResource box = dialogResource.getResource("purchaseActions");
|
||||
|
||||
CharSequence[] names = new CharSequence[items.size()];
|
||||
for (int i = 0; i < names.length; ++i) {
|
||||
names[i] = box.getResource(items.get(i)).getValue();
|
||||
}
|
||||
});
|
||||
|
||||
new AlertDialog.Builder(activity)
|
||||
.setIcon(0)
|
||||
.setTitle(box.getResource("title").getValue())
|
||||
.setItems(names, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final String item = items.get(which);
|
||||
if (signInKey.equals(item)) {
|
||||
Util.runAuthenticationDialog(activity, book.Link, new Runnable() {
|
||||
public void run() {
|
||||
activity.runOnUiThread(buyDialogRunnable);
|
||||
}
|
||||
});
|
||||
} else if (registerKey.equals(item)) {
|
||||
Util.runRegistrationDialog(activity, book.Link);
|
||||
// TODO: buy on success
|
||||
} else if (autoregisterKey.equals(item)) {
|
||||
Util.runAutoregistrationDialog(activity, book.Link);
|
||||
// TODO: buy on success
|
||||
}
|
||||
}
|
||||
})
|
||||
.create().show();
|
||||
} else {
|
||||
Util.runAuthenticationDialog(activity, book.Link, new Runnable() {
|
||||
public void run() {
|
||||
activity.runOnUiThread(buyDialogRunnable);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (ZLNetworkException e) {
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue