1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 18:29:23 +02:00

purchasing -- authorization intercommunication

This commit is contained in:
Nikolay Pultsin 2011-10-02 17:49:19 +01:00
parent 726fb957a5
commit f2a643d616
6 changed files with 71 additions and 22 deletions

View file

@ -1,6 +1,6 @@
buy book after registration
buy book after auto-sign-in
auto-sign-in
resources synchronization
honeycomb
do we cache cover images?
states:

View file

@ -91,7 +91,7 @@
<node name="topup" value="Top up account (currently: %s)"/>
<node name="topupTitle" value="Top up account"/>
<node name="topupViaBrowser" value="Open page in browser"/>
<node name="accountMenuTitle" value="Select action"/>
<node name="authorizationMenuTitle" value="Select action"/>
<node name="topupSummary" value="Currently: %s"/>
<node name="basket" value="Basket"/>
<node name="basketSummaryEmpty" value="No books"/>
@ -135,6 +135,7 @@
<node name="confirm" value="Are you sure you want to buy &#10;&#8220;%s&#8221;?" />
<node name="confirmSeveralBooks" value="Are you sure you want to buy %s books?" />
<node name="alreadyBought" value="Book is already bought" />
<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>
@ -254,6 +255,7 @@
<node name="topup" value="Top up"/>
<node name="pay" value="Pay"/>
<node name="refresh" value="Refresh"/>
<node name="authorize" value="Authorize"/>
</node>
<node name="plugin">
<node name="installTitle" value="Install plugin"/>

View file

@ -91,7 +91,7 @@
<node name="topup" value="Пополнение счёта (баланс: %s)" />
<node name="topupTitle" value="Оплата"/>
<node name="topupViaBrowser" value="В окне браузера"/>
<node name="accountMenuTitle" value="Выберите действие"/>
<node name="authorizationMenuTitle" value="Выберите действие"/>
<node name="topupSummary" value="Текущий счёт: %s"/>
<node name="basket" value="Корзина"/>
<node name="basketSummaryEmpty" value="Пустая корзина"/>
@ -135,6 +135,7 @@
<node name="confirm" value="Вы уверены, что хотите приобрести книгу&#10;«%s»?" />
<node name="confirmSeveralBooks" value="Вы уверены, что хотите приобрести %s книги?" />
<node name="alreadyBought" value="Книга уже куплена" />
<node name="notAuthorized" value="Требуется авторизация" />
<node name="noAccountInformation" value="Не удалось проверить состояние счета" />
<node name="unsufficientFunds" value="Для покупки требуется %0, а на счете только %1" />
</node>
@ -254,6 +255,7 @@
<node name="topup" value="Пополнить счёт"/>
<node name="pay" value="Заплатить"/>
<node name="refresh" value="Обновить"/>
<node name="authorize" value="Авторизоваться"/>
</node>
<node name="plugin">
<node name="installTitle" value="Установка дополнения"/>

View file

@ -48,7 +48,7 @@ public class AccountMenuActivity extends MenuActivity {
@Override
protected void init() {
setTitle(NetworkLibrary.resource().getResource("accountMenuTitle").getValue());
setTitle(NetworkLibrary.resource().getResource("authorizationMenuTitle").getValue());
final String url = getIntent().getData().toString();
myLink = NetworkLibrary.Instance().getLinkByUrl(url);
@ -63,7 +63,7 @@ public class AccountMenuActivity extends MenuActivity {
@Override
protected String getAction() {
return "android.fbreader.action.network.ACCOUNT";
return Util.AUTHORIZATION_ACTION;
}
@Override

View file

@ -54,6 +54,16 @@ public class BuyBooksActivity extends Activity {
return;
}
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);
/*
final INetworkLink link = trees.get(0).getLink();
final NetworkAuthenticationManager mgr = link.authenticationManager();
if (mgr == null) {
@ -75,9 +85,11 @@ public class BuyBooksActivity extends Activity {
}
} catch (ZLNetworkException e) {
}
*/
}
private NetworkLibrary myLibrary;
// we assume all the books are from the same catalog
private INetworkLink myLink;
private List<NetworkBookItem> myBooks;
private Money myCost;
@ -87,7 +99,6 @@ public class BuyBooksActivity extends Activity {
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
setContentView(R.layout.buy_book);
myLibrary = NetworkLibrary.Instance();
@ -109,6 +120,23 @@ public class BuyBooksActivity extends Activity {
return;
}
}
myLink = myBooks.get(0).Link;
final NetworkAuthenticationManager mgr = myLink.authenticationManager();
if (mgr == null) {
finish();
return;
}
try {
if (!mgr.isAuthorised(true)) {
AccountMenuActivity.runMenu(this, myLink);
}
} catch (ZLNetworkException e) {
}
setContentView(R.layout.buy_book);
myCost = calculateCost();
if (myCost == null) {
// TODO: error message
@ -116,19 +144,12 @@ public class BuyBooksActivity extends Activity {
return;
}
// we assume all the books are from the same catalog
myLink = myBooks.get(0).Link;
final NetworkAuthenticationManager mgr = myLink.authenticationManager();
if (mgr == null) {
finish();
return;
}
myAccount = mgr.currentAccount();
setupUI();
setupUI(true);
}
private void setupUI() {
private void setupUI(boolean authorized) {
final ZLResource dialogResource = ZLResource.resource("dialog");
final ZLResource buttonResource = dialogResource.getResource("button");
@ -145,7 +166,21 @@ public class BuyBooksActivity extends Activity {
setTitle(resource.getResource("title").getValue());
}
if (myAccount == null) {
if (!authorized) {
textArea.setText(resource.getResource("notAuthorized").getValue());
okButton.setText(buttonResource.getResource("authorize").getValue());
cancelButton.setText(buttonResource.getResource("cancel").getValue());
okButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AccountMenuActivity.runMenu(BuyBooksActivity.this, myLink);
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
} else if (myAccount == null) {
textArea.setText(resource.getResource("noAccountInformation").getValue());
okButton.setText(buttonResource.getResource("refresh").getValue());
cancelButton.setText(buttonResource.getResource("cancel").getValue());
@ -212,7 +247,17 @@ public class BuyBooksActivity extends Activity {
@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);
}
}
private Money calculateCost() {
@ -255,7 +300,7 @@ public class BuyBooksActivity extends Activity {
if (updated) {
runOnUiThread(new Runnable() {
public void run() {
setupUI();
setupUI(true);
}
});
}

View file

@ -36,7 +36,7 @@ import org.geometerplus.android.util.UIUtil;
import org.geometerplus.android.util.PackageUtil;
public abstract class Util implements UserRegistrationConstants {
static final String ACCOUNT_ACTION = "android.fbreader.action.network.ACCOUNT";
static final String AUTHORIZATION_ACTION = "android.fbreader.action.network.AUTHORIZATION";
public static Intent intentByLink(Intent intent, INetworkLink link) {
if (link != null) {
@ -69,7 +69,7 @@ public abstract class Util implements UserRegistrationConstants {
public static boolean isRegistrationSupported(Activity activity, INetworkLink link) {
return testService(
activity,
ACCOUNT_ACTION,
AUTHORIZATION_ACTION,
link.getUrl(UrlInfo.Type.Catalog) + "/register"
);
}
@ -77,7 +77,7 @@ public abstract class Util implements UserRegistrationConstants {
public static void runRegistrationDialog(Activity activity, INetworkLink link) {
try {
final Intent intent = new Intent(
ACCOUNT_ACTION,
AUTHORIZATION_ACTION,
Uri.parse(link.getUrl(UrlInfo.Type.Catalog) + "/register")
);
intent.putExtra(UserRegistrationConstants.SIGNUP_URL, link.getUrl(UrlInfo.Type.SignUp));