mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
code simplification
This commit is contained in:
parent
6ea54edf5f
commit
9d02e1bafd
5 changed files with 26 additions and 34 deletions
|
@ -22,7 +22,6 @@ package org.geometerplus.android.fbreader.network;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
@ -80,7 +79,7 @@ public abstract class Util implements UserRegistrationConstants {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Intent authorisationIntent(INetworkLink link, Uri id) {
|
public static Intent authorisationIntent(INetworkLink link, Uri id) {
|
||||||
final Intent intent = new Intent(AUTHORISATION_ACTION, id);
|
final Intent intent = new Intent(AUTHORISATION_ACTION, id);
|
||||||
intent.putExtra(CATALOG_URL, link.getUrl(UrlInfo.Type.Catalog));
|
intent.putExtra(CATALOG_URL, link.getUrl(UrlInfo.Type.Catalog));
|
||||||
intent.putExtra(SIGNIN_URL, link.getUrl(UrlInfo.Type.SignIn));
|
intent.putExtra(SIGNIN_URL, link.getUrl(UrlInfo.Type.SignIn));
|
||||||
|
@ -89,24 +88,6 @@ public abstract class Util implements UserRegistrationConstants {
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Intent registrationIntent(INetworkLink link) {
|
|
||||||
return authorisationIntent(link, Uri.parse(link.getUrl(UrlInfo.Type.Catalog) + "/register"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isRegistrationSupported(Activity activity, INetworkLink link) {
|
|
||||||
return PackageUtil.canBeStarted(activity, registrationIntent(link), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void runRegistrationDialog(Activity activity, INetworkLink link) {
|
|
||||||
try {
|
|
||||||
final Intent intent = registrationIntent(link);
|
|
||||||
if (PackageUtil.canBeStarted(activity, intent, true)) {
|
|
||||||
activity.startActivity(intent);
|
|
||||||
}
|
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void runAuthenticationDialog(Activity activity, INetworkLink link, Runnable onSuccess) {
|
public static void runAuthenticationDialog(Activity activity, INetworkLink link, Runnable onSuccess) {
|
||||||
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,14 @@
|
||||||
package org.geometerplus.android.fbreader.network.action;
|
package org.geometerplus.android.fbreader.network.action;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.INetworkLink;
|
import org.geometerplus.fbreader.network.INetworkLink;
|
||||||
import org.geometerplus.fbreader.network.NetworkTree;
|
import org.geometerplus.fbreader.network.NetworkTree;
|
||||||
import org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree;
|
|
||||||
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
||||||
|
import org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree;
|
||||||
|
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.network.Util;
|
import org.geometerplus.android.fbreader.network.Util;
|
||||||
|
|
||||||
|
@ -41,14 +44,17 @@ public class SignUpAction extends Action {
|
||||||
|
|
||||||
final INetworkLink link = tree.getLink();
|
final INetworkLink link = tree.getLink();
|
||||||
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||||
return
|
return mgr != null && !mgr.mayBeAuthorised(false);
|
||||||
mgr != null &&
|
|
||||||
!mgr.mayBeAuthorised(false) &&
|
|
||||||
Util.isRegistrationSupported(myActivity, link);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(NetworkTree tree) {
|
public void run(NetworkTree tree) {
|
||||||
Util.runRegistrationDialog(myActivity, tree.getLink());
|
final INetworkLink link = tree.getLink();
|
||||||
|
try {
|
||||||
|
myActivity.startActivity(Util.authorisationIntent(
|
||||||
|
link, Uri.parse(link.getUrl(UrlInfo.Type.Catalog) + "/signUp")
|
||||||
|
));
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ public abstract class NetworkException extends ZLNetworkException {
|
||||||
public static final String ERROR_BOOK_NOT_PURCHASED = "bookNotPurchased";
|
public static final String ERROR_BOOK_NOT_PURCHASED = "bookNotPurchased";
|
||||||
public static final String ERROR_DOWNLOAD_LIMIT_EXCEEDED = "downloadLimitExceeded";
|
public static final String ERROR_DOWNLOAD_LIMIT_EXCEEDED = "downloadLimitExceeded";
|
||||||
|
|
||||||
public static final String ERROR_EMAIL_WAS_NOT_SPECIFIED = "emailNotSpecified";
|
public static final String ERROR_EMAIL_NOT_SPECIFIED = "emailNotSpecified";
|
||||||
|
|
||||||
public static final String ERROR_NO_USER_EMAIL = "noUserEmail";
|
public static final String ERROR_NO_USER_FOR_EMAIL = "noUserForEmail";
|
||||||
|
|
||||||
public static final String ERROR_UNSUPPORTED_OPERATION = "unsupportedOperation";
|
public static final String ERROR_UNSUPPORTED_OPERATION = "unsupportedOperation";
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.geometerplus.zlibrary.core.xml.ZLStringMap;
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkAuthenticationException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkAuthenticationException;
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
|
||||||
class LitResLoginXMLReader extends LitResAuthenticationXMLReader {
|
public class LitResLoginXMLReader extends LitResAuthenticationXMLReader {
|
||||||
private static final String TAG_AUTHORIZATION_OK = "catalit-authorization-ok";
|
private static final String TAG_AUTHORIZATION_OK = "catalit-authorization-ok";
|
||||||
private static final String TAG_AUTHORIZATION_FAILED = "catalit-authorization-failed";
|
private static final String TAG_AUTHORIZATION_FAILED = "catalit-authorization-failed";
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.NetworkException;
|
import org.geometerplus.fbreader.network.NetworkException;
|
||||||
|
|
||||||
class LitResPasswordRecoveryXMLReader extends LitResAuthenticationXMLReader {
|
public class LitResPasswordRecoveryXMLReader extends LitResAuthenticationXMLReader {
|
||||||
private static final String TAG_PASSWORD_RECOVERY_OK = "catalit-pass-recover-ok";
|
private static final String TAG_PASSWORD_RECOVERY_OK = "catalit-pass-recover-ok";
|
||||||
private static final String TAG_PASSWORD_RECOVERY_FAILED = "catalit-pass-recover-failed";
|
private static final String TAG_PASSWORD_RECOVERY_FAILED = "catalit-pass-recover-failed";
|
||||||
|
|
||||||
|
@ -34,16 +34,21 @@ class LitResPasswordRecoveryXMLReader extends LitResAuthenticationXMLReader {
|
||||||
if (TAG_PASSWORD_RECOVERY_FAILED == tag) {
|
if (TAG_PASSWORD_RECOVERY_FAILED == tag) {
|
||||||
final String error = attributes.getValue("error");
|
final String error = attributes.getValue("error");
|
||||||
if ("1".equals(error)) {
|
if ("1".equals(error)) {
|
||||||
setException(ZLNetworkException.forCode(NetworkException.ERROR_NO_USER_EMAIL));
|
setException(ZLNetworkException.forCode(NetworkException.ERROR_NO_USER_FOR_EMAIL));
|
||||||
} else if ("2".equals(error)) {
|
} else if ("2".equals(error)) {
|
||||||
setException(ZLNetworkException.forCode(NetworkException.ERROR_EMAIL_WAS_NOT_SPECIFIED));
|
setException(ZLNetworkException.forCode(NetworkException.ERROR_EMAIL_NOT_SPECIFIED));
|
||||||
} else {
|
} else {
|
||||||
setException(ZLNetworkException.forCode(NetworkException.ERROR_INTERNAL));
|
final String comment = attributes.getValue("coment");
|
||||||
|
if (comment != null) {
|
||||||
|
setException(new ZLNetworkException(comment));
|
||||||
|
} else {
|
||||||
|
setException(ZLNetworkException.forCode(NetworkException.ERROR_INTERNAL, error));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (TAG_PASSWORD_RECOVERY_OK == tag) {
|
} else if (TAG_PASSWORD_RECOVERY_OK == tag) {
|
||||||
// NOP
|
// NOP
|
||||||
} else {
|
} else {
|
||||||
setException(ZLNetworkException.forCode(NetworkException.ERROR_SOMETHING_WRONG, LitResUtil.HOST_NAME));
|
setException(ZLNetworkException.forCode(ZLNetworkException.ERROR_SOMETHING_WRONG, LitResUtil.HOST_NAME));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue