mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +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="title" value="Purchase book" />
|
||||||
<node name="message" value="Book is already bought" />
|
<node name="message" value="Book is already bought" />
|
||||||
</node>
|
</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>
|
||||||
<node name="errorMessage">
|
<node name="errorMessage">
|
||||||
<node name="cannotRunAndroidMarket" value="Cannot access Android Market. Please, install %s manually"/>
|
<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 {
|
public 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 AUTOREGISTRATION_ACTION =
|
||||||
|
"android.fbreader.action.NETWORK_LIBRARY_AUTOREGISTER";
|
||||||
|
|
||||||
static INetworkLink linkByIntent(Intent intent) {
|
static INetworkLink linkByIntent(Intent intent) {
|
||||||
return NetworkLibrary.Instance().getLinkByUrl(intent.getData().toString());
|
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) {
|
public static void runRegistrationDialog(Activity activity, INetworkLink link) {
|
||||||
try {
|
try {
|
||||||
final Intent intent = new Intent(
|
final Intent intent = new Intent(
|
||||||
|
@ -71,10 +81,20 @@ public abstract class Util implements UserRegistrationConstants {
|
||||||
Uri.parse(link.getUrl(UrlInfo.Type.SignUp))
|
Uri.parse(link.getUrl(UrlInfo.Type.SignUp))
|
||||||
);
|
);
|
||||||
if (PackageUtil.canBeStarted(activity, intent, true)) {
|
if (PackageUtil.canBeStarted(activity, intent, true)) {
|
||||||
activity.startActivityForResult(new Intent(
|
activity.startActivityForResult(intent, NetworkLibraryActivity.SIGNUP_CODE);
|
||||||
REGISTRATION_ACTION,
|
}
|
||||||
Uri.parse(link.getUrl(UrlInfo.Type.SignUp))
|
} catch (ActivityNotFoundException e) {
|
||||||
), NetworkLibraryActivity.SIGNUP_CODE);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
} catch (ActivityNotFoundException e) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -381,11 +381,56 @@ public abstract class NetworkBookActions {
|
||||||
if (mgr.isAuthorised(true)) {
|
if (mgr.isAuthorised(true)) {
|
||||||
buyDialogRunnable.run();
|
buyDialogRunnable.run();
|
||||||
} else {
|
} else {
|
||||||
Util.runAuthenticationDialog(activity, book.Link, new Runnable() {
|
final String signInKey = "signIn";
|
||||||
public void run() {
|
final String registerKey = "signUp";
|
||||||
activity.runOnUiThread(buyDialogRunnable);
|
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) {
|
} catch (ZLNetworkException e) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue