mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
new mechanism for notification about registration
This commit is contained in:
parent
1b96f763d2
commit
36c46fab34
15 changed files with 99 additions and 74 deletions
|
@ -161,7 +161,6 @@
|
|||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.AccountMenuActivity" android:process=":networkLibrary" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden"/>
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.TopupMenuActivity" android:process=":networkLibrary" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden"/>
|
||||
<service android:name="org.geometerplus.android.fbreader.network.ItemsLoadingService" android:process=":networkLibrary" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.NetworkBookInfoActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
@ -169,7 +168,11 @@
|
|||
<data android:host="*" android:scheme="litres-book" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<receiver android:name="org.geometerplus.android.fbreader.network.BookDownloaderCallback" android:process=":networkLibrary" />
|
||||
<service android:name="org.geometerplus.android.fbreader.network.LibraryInitializationService" android:process=":networkLibrary" />
|
||||
<receiver android:name="org.geometerplus.android.fbreader.network.ListenerCallback" android:process=":networkLibrary">
|
||||
<intent-filter>
|
||||
<action android:name="android.fbreader.action.network.SIGNIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -161,7 +161,6 @@
|
|||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.AccountMenuActivity" android:process=":networkLibrary" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden"/>
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.TopupMenuActivity" android:process=":networkLibrary" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden"/>
|
||||
<service android:name="org.geometerplus.android.fbreader.network.ItemsLoadingService" android:process=":networkLibrary" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.NetworkBookInfoActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
@ -169,7 +168,11 @@
|
|||
<data android:host="*" android:scheme="litres-book" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<receiver android:name="org.geometerplus.android.fbreader.network.BookDownloaderCallback" android:process=":networkLibrary" />
|
||||
<service android:name="org.geometerplus.android.fbreader.network.LibraryInitializationService" android:process=":networkLibrary" />
|
||||
<receiver android:name="org.geometerplus.android.fbreader.network.ListenerCallback" android:process=":networkLibrary">
|
||||
<intent-filter>
|
||||
<action android:name="android.fbreader.action.network.SIGNIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
always sign in after registration
|
||||
auto-sign-in
|
||||
resources synchronization
|
||||
honeycomb
|
||||
|
|
|
@ -138,6 +138,7 @@
|
|||
<node name="notAuthorized" value="Authorization required" />
|
||||
<node name="noAccountInformation" value="Cannot load account state" />
|
||||
<node name="unsufficientFunds" value="This purchase costs %0 and you have only %1" />
|
||||
<node name="zeroFunds" value="This purchase costs %0" />
|
||||
</node>
|
||||
<node name="networkBookView">
|
||||
<node name="bookInfo" value="Book Info" />
|
||||
|
|
|
@ -138,6 +138,7 @@
|
|||
<node name="notAuthorized" value="Требуется авторизация" />
|
||||
<node name="noAccountInformation" value="Не удалось проверить состояние счета" />
|
||||
<node name="unsufficientFunds" value="Для покупки требуется %0, а на счете только %1" />
|
||||
<node name="zeroFunds" value="Для покупки требуется %0" />
|
||||
</node>
|
||||
<node name="networkBookView">
|
||||
<node name="bookInfo" value="Информация о книге" />
|
||||
|
|
|
@ -241,7 +241,7 @@ public class BookDownloaderService extends Service {
|
|||
|
||||
private void sendDownloaderCallback() {
|
||||
sendBroadcast(
|
||||
new Intent(getApplicationContext(), BookDownloaderCallback.class)
|
||||
new Intent(getApplicationContext(), ListenerCallback.class)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationMan
|
|||
|
||||
import org.geometerplus.android.fbreader.network.*;
|
||||
|
||||
public class BuyBooksActivity extends Activity {
|
||||
public class BuyBooksActivity extends Activity implements NetworkLibrary.ChangeListener {
|
||||
public static void run(Activity activity, NetworkBookTree tree) {
|
||||
run(activity, Collections.singletonList(tree));
|
||||
}
|
||||
|
@ -62,30 +62,6 @@ public class BuyBooksActivity extends Activity {
|
|||
}
|
||||
intent.putExtra(NetworkLibraryActivity.TREE_KEY_KEY, keys);
|
||||
activity.startActivity(intent);
|
||||
|
||||
/*
|
||||
final INetworkLink link = trees.get(0).getLink();
|
||||
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||
if (mgr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (mgr.isAuthorised(true)) {
|
||||
final Intent intent = new Intent(activity, BuyBooksActivity.class);
|
||||
final ArrayList<NetworkTree.Key> keys =
|
||||
new ArrayList<NetworkTree.Key>(trees.size());
|
||||
for (NetworkBookTree t : trees) {
|
||||
keys.add(t.getUniqueKey());
|
||||
}
|
||||
intent.putExtra(NetworkLibraryActivity.TREE_KEY_KEY, keys);
|
||||
activity.startActivity(intent);
|
||||
} else {
|
||||
AccountMenuActivity.runMenu(activity, link);
|
||||
}
|
||||
} catch (ZLNetworkException e) {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private NetworkLibrary myLibrary;
|
||||
|
@ -195,11 +171,18 @@ public class BuyBooksActivity extends Activity {
|
|||
}
|
||||
});
|
||||
} else if (myCost.compareTo(myAccount) > 0) {
|
||||
textArea.setText(
|
||||
resource.getResource("unsufficientFunds").getValue()
|
||||
.replace("%0", myCost.toString())
|
||||
.replace("%1", myAccount.toString())
|
||||
);
|
||||
if (Money.ZERO.equals(myAccount)) {
|
||||
textArea.setText(
|
||||
resource.getResource("zeroFunds").getValue()
|
||||
.replace("%0", myCost.toString())
|
||||
);
|
||||
} else {
|
||||
textArea.setText(
|
||||
resource.getResource("unsufficientFunds").getValue()
|
||||
.replace("%0", myCost.toString())
|
||||
.replace("%1", myAccount.toString())
|
||||
);
|
||||
}
|
||||
okButton.setText(buttonResource.getResource("pay").getValue());
|
||||
cancelButton.setText(buttonResource.getResource("refresh").getValue());
|
||||
okButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -244,20 +227,22 @@ public class BuyBooksActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
NetworkLibrary.Instance().addChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
NetworkLibrary.Instance().removeChangeListener(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
final NetworkAuthenticationManager mgr = myLink.authenticationManager();
|
||||
try {
|
||||
if (mgr.isAuthorised(true)) {
|
||||
refreshAccountInformation();
|
||||
} else {
|
||||
setupUI(false);
|
||||
}
|
||||
} catch (ZLNetworkException e) {
|
||||
setupUI(false);
|
||||
}
|
||||
updateAuthorizationState();
|
||||
}
|
||||
|
||||
private Money calculateCost() {
|
||||
|
@ -354,4 +339,26 @@ public class BuyBooksActivity extends Activity {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
// method from NetworkLibrary.ChangeListener
|
||||
public void onLibraryChanged(final NetworkLibrary.ChangeListener.Code code, final Object[] params) {
|
||||
switch (code) {
|
||||
case SignedIn:
|
||||
updateAuthorizationState();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAuthorizationState() {
|
||||
final NetworkAuthenticationManager mgr = myLink.authenticationManager();
|
||||
try {
|
||||
if (mgr.isAuthorised(true)) {
|
||||
refreshAccountInformation();
|
||||
} else {
|
||||
setupUI(false);
|
||||
}
|
||||
} catch (ZLNetworkException e) {
|
||||
setupUI(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,23 @@ import android.content.BroadcastReceiver;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.geometerplus.fbreader.network.INetworkLink;
|
||||
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||
|
||||
public class BookDownloaderCallback extends BroadcastReceiver {
|
||||
public class ListenerCallback extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||
|
||||
if ("android.fbreader.action.network.SIGNIN".equals(intent.getAction())) {
|
||||
final String url = intent.getStringExtra(UserRegistrationConstants.CATALOG_URL);
|
||||
final INetworkLink link = library.getLinkByUrl(url);
|
||||
if (link != null) {
|
||||
Util.processSignup(link, android.app.Activity.RESULT_OK, intent);
|
||||
}
|
||||
library.fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SignedIn);
|
||||
} else {
|
||||
library.fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -427,16 +427,4 @@ public class NetworkBookInfoActivity extends Activity implements NetworkLibrary.
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case NetworkLibraryActivity.SIGNUP_CODE:
|
||||
Util.processSignup(myBook.Link, resultCode, data);
|
||||
break;
|
||||
case NetworkLibraryActivity.AUTO_SIGNIN_CODE:
|
||||
Util.processAutoSignIn(this, myBook.Link, resultCode, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,6 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
|||
static final String OPEN_CATALOG_ACTION = "android.fbreader.action.OPEN_NETWORK_CATALOG";
|
||||
|
||||
protected static final int BASIC_AUTHENTICATION_CODE = 1;
|
||||
protected static final int SIGNUP_CODE = 2;
|
||||
protected static final int AUTO_SIGNIN_CODE = 3;
|
||||
|
||||
BookDownloaderServiceConnection Connection;
|
||||
|
||||
|
@ -287,12 +285,6 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
|||
case BASIC_AUTHENTICATION_CODE:
|
||||
myCredentialsCreator.onDataReceived(resultCode, intent);
|
||||
break;
|
||||
case SIGNUP_CODE:
|
||||
Util.processSignup(((NetworkTree)getCurrentTree()).getLink(), resultCode, intent);
|
||||
break;
|
||||
case AUTO_SIGNIN_CODE:
|
||||
Util.processAutoSignIn(this, ((NetworkTree)getCurrentTree()).getLink(), resultCode, intent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.geometerplus.android.fbreader.network;
|
||||
|
||||
public interface UserRegistrationConstants {
|
||||
String CATALOG_URL = "catalogUrl";
|
||||
String SIGNUP_URL = "signupUrl";
|
||||
|
||||
String USER_REGISTRATION_USERNAME = "userName";
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.geometerplus.android.fbreader.network;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
|
@ -76,13 +78,18 @@ public abstract class Util implements UserRegistrationConstants {
|
|||
|
||||
public static void runRegistrationDialog(Activity activity, INetworkLink link) {
|
||||
try {
|
||||
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||
final Intent intent = new Intent(
|
||||
AUTHORIZATION_ACTION,
|
||||
Uri.parse(link.getUrl(UrlInfo.Type.Catalog) + "/register")
|
||||
);
|
||||
intent.putExtra(UserRegistrationConstants.SIGNUP_URL, link.getUrl(UrlInfo.Type.SignUp));
|
||||
if (mgr != null) {
|
||||
for (Map.Entry<String,String> entry : mgr.getAccountData().entrySet()) {
|
||||
intent.putExtra(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
if (PackageUtil.canBeStarted(activity, intent, true)) {
|
||||
activity.startActivityForResult(intent, NetworkLibraryActivity.SIGNUP_CODE);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
} catch (ActivityNotFoundException e) {
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ public class NetworkLibrary {
|
|||
ItemRemoved,
|
||||
StatusChanged,
|
||||
*/
|
||||
SignedIn,
|
||||
Found,
|
||||
NotFound,
|
||||
EmptyCatalog,
|
||||
|
@ -147,6 +148,9 @@ public class NetworkLibrary {
|
|||
}
|
||||
|
||||
public INetworkLink getLinkByUrl(String url) {
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
synchronized (myLinks) {
|
||||
for (INetworkLink link : myLinks) {
|
||||
if (url.equals(link.getUrlInfo(UrlInfo.Type.Catalog).Url)) {
|
||||
|
|
|
@ -112,7 +112,10 @@ public abstract class NetworkAuthenticationManager {
|
|||
* sign up
|
||||
*/
|
||||
public Map<String,String> getAccountData() {
|
||||
return Collections.singletonMap("signupUrl", Link.getUrl(UrlInfo.Type.SignUp));
|
||||
final Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("catalogUrl", Link.getUrl(UrlInfo.Type.Catalog));
|
||||
map.put("signupUrl", Link.getUrl(UrlInfo.Type.SignUp));
|
||||
return map;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -247,7 +247,9 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
return null;
|
||||
}
|
||||
url = ZLNetworkUtil.appendParameter(url, "sid", sid);
|
||||
url = ZLNetworkUtil.appendParameter(url, "summ", String.valueOf(sum.Amount));
|
||||
if (sum != null) {
|
||||
url = ZLNetworkUtil.appendParameter(url, "summ", String.valueOf(sum.Amount));
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue