mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
refactoring: catalog actions have been moved to action package
This commit is contained in:
parent
0c11e03a8b
commit
74ccd3850d
19 changed files with 408 additions and 249 deletions
|
@ -49,10 +49,8 @@ public class AddCustomCatalogActivity extends Activity {
|
||||||
private static final String ADD_CATALOG_ID_KEY = "id";
|
private static final String ADD_CATALOG_ID_KEY = "id";
|
||||||
private static final String ADD_CATALOG_URLS_MAP_KEY = "urls";
|
private static final String ADD_CATALOG_URLS_MAP_KEY = "urls";
|
||||||
|
|
||||||
static void addLinkToIntent(Intent intent, ICustomNetworkLink link) {
|
public static void addLinkToIntent(Intent intent, ICustomNetworkLink link) {
|
||||||
final String textUrl = link.getUrl(UrlInfo.Type.Catalog);
|
Util.intentByLink(intent, link)
|
||||||
intent.setData(Uri.parse(textUrl));
|
|
||||||
intent
|
|
||||||
.putExtra(ADD_CATALOG_TITLE_KEY, link.getTitle())
|
.putExtra(ADD_CATALOG_TITLE_KEY, link.getTitle())
|
||||||
.putExtra(ADD_CATALOG_SUMMARY_KEY, link.getSummary())
|
.putExtra(ADD_CATALOG_SUMMARY_KEY, link.getSummary())
|
||||||
.putExtra(ADD_CATALOG_ID_KEY, link.getId())
|
.putExtra(ADD_CATALOG_ID_KEY, link.getId())
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.geometerplus.android.fbreader.network;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -34,6 +35,8 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkManager;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkManager;
|
||||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.network.INetworkLink;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.ui.android.R;
|
import org.geometerplus.zlibrary.ui.android.R;
|
||||||
|
|
||||||
public class AuthenticationActivity extends Activity {
|
public class AuthenticationActivity extends Activity {
|
||||||
|
@ -101,15 +104,22 @@ public class AuthenticationActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZLResource myResource;
|
private ZLResource myResource;
|
||||||
|
private INetworkLink myLink;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
|
Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
|
||||||
setResult(RESULT_CANCELED);
|
|
||||||
setContentView(R.layout.authentication);
|
setContentView(R.layout.authentication);
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
|
myLink = Util.linkByIntent(intent);
|
||||||
|
if (myLink == null) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setResult(RESULT_CANCELED, Util.intentByLink(new Intent(), myLink));
|
||||||
|
|
||||||
final String host = intent.getStringExtra(HOST_KEY);
|
final String host = intent.getStringExtra(HOST_KEY);
|
||||||
final String area = intent.getStringExtra(AREA_KEY);
|
final String area = intent.getStringExtra(AREA_KEY);
|
||||||
final String username = intent.getStringExtra(USERNAME_KEY);
|
final String username = intent.getStringExtra(USERNAME_KEY);
|
||||||
|
@ -155,7 +165,7 @@ public class AuthenticationActivity extends Activity {
|
||||||
signupView.setText(myResource.getResource("register").getValue());
|
signupView.setText(myResource.getResource("register").getValue());
|
||||||
signupView.setOnClickListener(new View.OnClickListener() {
|
signupView.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
setResult(RESULT_SIGNUP);
|
setResult(RESULT_SIGNUP, Util.intentByLink(new Intent(), myLink));
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -169,7 +179,7 @@ public class AuthenticationActivity extends Activity {
|
||||||
okButton.setText(buttonResource.getResource("ok").getValue());
|
okButton.setText(buttonResource.getResource("ok").getValue());
|
||||||
okButton.setOnClickListener(new Button.OnClickListener() {
|
okButton.setOnClickListener(new Button.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final Intent data = new Intent();
|
final Intent data = Util.intentByLink(new Intent(), myLink);
|
||||||
data.putExtra(
|
data.putExtra(
|
||||||
USERNAME_KEY,
|
USERNAME_KEY,
|
||||||
usernameView.getText().toString()
|
usernameView.getText().toString()
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.geometerplus.fbreader.network.NetworkTree;
|
||||||
public class ItemsLoadingService extends Service {
|
public class ItemsLoadingService extends Service {
|
||||||
private static final String KEY = "ItemsLoadingRunnable";
|
private static final String KEY = "ItemsLoadingRunnable";
|
||||||
|
|
||||||
static void start(Context context, NetworkTree tree, ItemsLoader runnable) {
|
public static void start(Context context, NetworkTree tree, ItemsLoader runnable) {
|
||||||
boolean doDownload = false;
|
boolean doDownload = false;
|
||||||
synchronized (tree) {
|
synchronized (tree) {
|
||||||
if (tree.getUserData(KEY) == null) {
|
if (tree.getUserData(KEY) == null) {
|
||||||
|
|
|
@ -66,7 +66,6 @@ class NetworkBookActions extends NetworkTreeActions {
|
||||||
book.reference(UrlInfo.Type.Book) == null;
|
book.reference(UrlInfo.Type.Book) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canHandleTree(NetworkTree tree) {
|
public boolean canHandleTree(NetworkTree tree) {
|
||||||
return tree instanceof NetworkBookTree
|
return tree instanceof NetworkBookTree
|
||||||
|| tree instanceof NetworkAuthorTree
|
|| tree instanceof NetworkAuthorTree
|
||||||
|
|
|
@ -390,7 +390,7 @@ public class NetworkBookInfoActivity extends Activity implements NetworkView.Eve
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case NetworkLibraryActivity.CUSTOM_AUTHENTICATION_CODE:
|
case NetworkLibraryActivity.CUSTOM_AUTHENTICATION_CODE:
|
||||||
Util.processCustomAuthentication(this, myBook.Link, resultCode, data);
|
Util.processCustomAuthentication(this, resultCode, data);
|
||||||
break;
|
break;
|
||||||
case NetworkLibraryActivity.SIGNUP_CODE:
|
case NetworkLibraryActivity.SIGNUP_CODE:
|
||||||
Util.processSignup(myBook.Link, resultCode, data);
|
Util.processSignup(myBook.Link, resultCode, data);
|
||||||
|
|
|
@ -22,18 +22,8 @@ package org.geometerplus.android.fbreader.network;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.ContextMenu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
|
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
|
||||||
|
|
||||||
import org.geometerplus.android.util.UIUtil;
|
import org.geometerplus.android.util.UIUtil;
|
||||||
import org.geometerplus.android.util.PackageUtil;
|
import org.geometerplus.android.util.PackageUtil;
|
||||||
|
@ -42,173 +32,19 @@ import org.geometerplus.fbreader.network.*;
|
||||||
import org.geometerplus.fbreader.network.authentication.*;
|
import org.geometerplus.fbreader.network.authentication.*;
|
||||||
import org.geometerplus.fbreader.network.tree.NetworkTreeFactory;
|
import org.geometerplus.fbreader.network.tree.NetworkTreeFactory;
|
||||||
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
||||||
import org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree;
|
|
||||||
import org.geometerplus.fbreader.network.opds.BasketItem;
|
import org.geometerplus.fbreader.network.opds.BasketItem;
|
||||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.network.action.ActionCode;
|
import org.geometerplus.android.fbreader.network.action.ActionCode;
|
||||||
|
|
||||||
public class NetworkCatalogActions extends NetworkTreeActions {
|
public class NetworkCatalogActions {
|
||||||
@Override
|
|
||||||
public boolean canHandleTree(NetworkTree tree) {
|
|
||||||
return tree instanceof NetworkCatalogTree;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void buildContextMenu(NetworkLibraryActivity activity, ContextMenu menu, NetworkTree tree) {
|
|
||||||
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
|
||||||
final NetworkURLCatalogItem urlItem =
|
|
||||||
item instanceof NetworkURLCatalogItem ? (NetworkURLCatalogItem)item : null;
|
|
||||||
menu.setHeaderTitle(tree.getName());
|
|
||||||
|
|
||||||
boolean hasItems = false;
|
|
||||||
|
|
||||||
final String catalogUrl =
|
|
||||||
urlItem != null ? urlItem.getUrl(UrlInfo.Type.Catalog) : null;
|
|
||||||
if (catalogUrl != null &&
|
|
||||||
(!(item instanceof BasketItem) || item.Link.basket().bookIds().size() > 0)) {
|
|
||||||
addMenuItem(menu, ActionCode.OPEN_CATALOG, "openCatalog");
|
|
||||||
hasItems = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tree instanceof NetworkCatalogRootTree) {
|
|
||||||
if (item.getVisibility() == ZLBoolean3.B3_TRUE) {
|
|
||||||
final NetworkAuthenticationManager mgr = item.Link.authenticationManager();
|
|
||||||
if (mgr != null) {
|
|
||||||
if (mgr.mayBeAuthorised(false)) {
|
|
||||||
addMenuItem(menu, ActionCode.SIGNOUT, "signOut", mgr.currentUserName());
|
|
||||||
if (TopupMenuActivity.isTopupSupported(item.Link)) {
|
|
||||||
final String account = mgr.currentAccount();
|
|
||||||
if (account != null) {
|
|
||||||
addMenuItem(menu, ActionCode.TOPUP, "topup", account);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
addMenuItem(menu, ActionCode.SIGNIN, "signIn");
|
|
||||||
//if (mgr.passwordRecoverySupported()) {
|
|
||||||
// registerAction(new PasswordRecoveryAction(mgr), true);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
INetworkLink link = item.Link;
|
|
||||||
if (link instanceof ICustomNetworkLink) {
|
|
||||||
addMenuItem(menu, ActionCode.CUSTOM_CATALOG_EDIT, "editCustomCatalog");
|
|
||||||
addMenuItem(menu, ActionCode.CUSTOM_CATALOG_REMOVE, "removeCustomCatalog");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (urlItem != null && urlItem.getUrl(UrlInfo.Type.HtmlPage) != null) {
|
|
||||||
addMenuItem(menu, ActionCode.OPEN_IN_BROWSER, "openInBrowser");
|
|
||||||
hasItems = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.getVisibility() == ZLBoolean3.B3_UNDEFINED &&
|
|
||||||
!hasItems && item.Link.authenticationManager() != null) {
|
|
||||||
addMenuItem(menu, ActionCode.SIGNIN, "signIn");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getDefaultActionCode(NetworkLibraryActivity activity, NetworkTree tree) {
|
|
||||||
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
|
||||||
if (!(item instanceof NetworkURLCatalogItem)) {
|
|
||||||
return ActionCode.OPEN_CATALOG;
|
|
||||||
}
|
|
||||||
final NetworkURLCatalogItem urlItem = (NetworkURLCatalogItem)item;
|
|
||||||
if (urlItem.getUrl(UrlInfo.Type.Catalog) != null) {
|
|
||||||
return ActionCode.OPEN_CATALOG;
|
|
||||||
}
|
|
||||||
if (urlItem.getUrl(UrlInfo.Type.HtmlPage) != null) {
|
|
||||||
return ActionCode.OPEN_IN_BROWSER;
|
|
||||||
}
|
|
||||||
if (urlItem.getVisibility() == ZLBoolean3.B3_UNDEFINED &&
|
|
||||||
urlItem.Link.authenticationManager() != null) {
|
|
||||||
return ActionCode.SIGNIN;
|
|
||||||
}
|
|
||||||
return ActionCode.TREE_NO_ACTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean consumeByVisibility(final NetworkLibraryActivity activity, final NetworkTree tree, final int actionCode) {
|
|
||||||
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
|
||||||
switch (item.getVisibility()) {
|
|
||||||
case B3_TRUE:
|
|
||||||
return false;
|
|
||||||
case B3_UNDEFINED:
|
|
||||||
Util.runAuthenticationDialog(activity, item.Link, null, new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if (item.getVisibility() != ZLBoolean3.B3_TRUE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (actionCode != ActionCode.SIGNIN) {
|
|
||||||
runAction(activity, tree, actionCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean runAction(final NetworkLibraryActivity activity, NetworkTree tree, int actionCode) {
|
public boolean runAction(final NetworkLibraryActivity activity, NetworkTree tree, int actionCode) {
|
||||||
final NetworkCatalogTree catalogTree = (NetworkCatalogTree)tree;
|
final NetworkCatalogTree catalogTree = (NetworkCatalogTree)tree;
|
||||||
if (consumeByVisibility(activity, catalogTree, actionCode)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final NetworkCatalogItem item = catalogTree.Item;
|
final NetworkCatalogItem item = catalogTree.Item;
|
||||||
switch (actionCode) {
|
switch (actionCode) {
|
||||||
case ActionCode.OPEN_CATALOG:
|
|
||||||
if (item instanceof BasketItem && item.Link.basket().bookIds().size() == 0) {
|
|
||||||
UIUtil.showErrorMessage(activity, "emptyBasket");
|
|
||||||
} else {
|
|
||||||
doExpandCatalog(activity, catalogTree);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case ActionCode.OPEN_IN_BROWSER:
|
|
||||||
if (item instanceof NetworkURLCatalogItem) {
|
|
||||||
final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button");
|
|
||||||
final String message = NetworkLibrary.resource().getResource("confirmQuestions").getResource("openInBrowser").getValue();
|
|
||||||
new AlertDialog.Builder(activity)
|
|
||||||
.setTitle(catalogTree.getName())
|
|
||||||
.setMessage(message)
|
|
||||||
.setIcon(0)
|
|
||||||
.setPositiveButton(buttonResource.getResource("yes").getValue(), new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
Util.openInBrowser(activity, item.getUrl(UrlInfo.Type.HtmlPage));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(buttonResource.getResource("no").getValue(), null)
|
|
||||||
.create().show();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case ActionCode.RELOAD_CATALOG:
|
|
||||||
doReloadCatalog(activity, catalogTree);
|
|
||||||
return true;
|
|
||||||
case ActionCode.SIGNIN:
|
case ActionCode.SIGNIN:
|
||||||
Util.runAuthenticationDialog(activity, item.Link, null, null);
|
Util.runAuthenticationDialog(activity, item.Link, null, null);
|
||||||
return true;
|
return true;
|
||||||
case ActionCode.SIGNOUT:
|
|
||||||
doSignOut(activity, catalogTree);
|
|
||||||
return true;
|
|
||||||
case ActionCode.TOPUP:
|
|
||||||
// TODO: replace 112 with required amount
|
|
||||||
TopupMenuActivity.runMenu(activity, item.Link, "112");
|
|
||||||
return true;
|
|
||||||
case ActionCode.CUSTOM_CATALOG_EDIT:
|
|
||||||
{
|
|
||||||
final Intent intent = new Intent(activity, AddCustomCatalogActivity.class);
|
|
||||||
AddCustomCatalogActivity.addLinkToIntent(
|
|
||||||
intent,
|
|
||||||
(ICustomNetworkLink)item.Link
|
|
||||||
);
|
|
||||||
activity.startActivity(intent);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case ActionCode.CUSTOM_CATALOG_REMOVE:
|
|
||||||
removeCustomLink((ICustomNetworkLink)item.Link);
|
|
||||||
return true;
|
|
||||||
case ActionCode.BASKET_CLEAR:
|
case ActionCode.BASKET_CLEAR:
|
||||||
item.Link.basket().clear();
|
item.Link.basket().clear();
|
||||||
return true;
|
return true;
|
||||||
|
@ -218,7 +54,7 @@ public class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class CatalogExpander extends ItemsLoader {
|
public static class CatalogExpander extends ItemsLoader {
|
||||||
private final NetworkCatalogTree myTree;
|
private final NetworkCatalogTree myTree;
|
||||||
private final boolean myCheckAuthentication;
|
private final boolean myCheckAuthentication;
|
||||||
private final boolean myResumeNotLoad;
|
private final boolean myResumeNotLoad;
|
||||||
|
@ -347,7 +183,7 @@ public class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void clearTree(Activity activity, final NetworkCatalogTree tree) {
|
public static void clearTree(Activity activity, final NetworkCatalogTree tree) {
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
tree.ChildrenItems.clear();
|
tree.ChildrenItems.clear();
|
||||||
|
@ -357,18 +193,6 @@ public class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doReloadCatalog(Activity activity, final NetworkCatalogTree tree) {
|
|
||||||
if (ItemsLoadingService.getRunnable(tree) != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
clearTree(activity, tree);
|
|
||||||
ItemsLoadingService.start(
|
|
||||||
activity,
|
|
||||||
tree,
|
|
||||||
new CatalogExpander(activity, tree, false, false)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void doSignOut(final Activity activity, NetworkCatalogTree tree) {
|
public static void doSignOut(final Activity activity, NetworkCatalogTree tree) {
|
||||||
final NetworkAuthenticationManager mgr = tree.Item.Link.authenticationManager();
|
final NetworkAuthenticationManager mgr = tree.Item.Link.authenticationManager();
|
||||||
final Runnable runnable = new Runnable() {
|
final Runnable runnable = new Runnable() {
|
||||||
|
@ -388,11 +212,4 @@ public class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
};
|
};
|
||||||
UIUtil.wait("signOut", runnable, activity);
|
UIUtil.wait("signOut", runnable, activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeCustomLink(ICustomNetworkLink link) {
|
|
||||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
|
||||||
library.removeCustomLink(link);
|
|
||||||
library.synchronize();
|
|
||||||
NetworkView.Instance().fireModelChangedAsync();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.geometerplus.zlibrary.core.network.ZLNetworkManager;
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
import org.geometerplus.zlibrary.core.language.ZLLanguageUtil;
|
import org.geometerplus.zlibrary.core.language.ZLLanguageUtil;
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.ui.android.network.SQLiteCookieDatabase;
|
import org.geometerplus.zlibrary.ui.android.network.SQLiteCookieDatabase;
|
||||||
import org.geometerplus.zlibrary.ui.android.R;
|
import org.geometerplus.zlibrary.ui.android.R;
|
||||||
|
@ -214,8 +215,13 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
||||||
|
|
||||||
private void fillContextMenuList() {
|
private void fillContextMenuList() {
|
||||||
myContextMenuActions.add(new OpenCatalogAction(this));
|
myContextMenuActions.add(new OpenCatalogAction(this));
|
||||||
|
myContextMenuActions.add(new OpenInBrowserAction(this));
|
||||||
myContextMenuActions.add(new AddCustomCatalogAction(this));
|
myContextMenuActions.add(new AddCustomCatalogAction(this));
|
||||||
|
myContextMenuActions.add(new SignOutAction(this));
|
||||||
myContextMenuActions.add(new TopupAction(this));
|
myContextMenuActions.add(new TopupAction(this));
|
||||||
|
myContextMenuActions.add(new SignInAction(this));
|
||||||
|
myContextMenuActions.add(new EditCustomCatalogAction(this));
|
||||||
|
myContextMenuActions.add(new RemoveCustomCatalogAction(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -234,10 +240,12 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
/*
|
||||||
final NetworkTreeActions actions = NetworkView.Instance().getActions(tree);
|
final NetworkTreeActions actions = NetworkView.Instance().getActions(tree);
|
||||||
if (actions != null) {
|
if (actions != null) {
|
||||||
actions.buildContextMenu(this, menu, tree);
|
actions.buildContextMenu(this, menu, tree);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
} else if (count > 1) {
|
} else if (count > 1) {
|
||||||
menu.setHeaderTitle(tree.getName());
|
menu.setHeaderTitle(tree.getName());
|
||||||
for (Action a : myContextMenuActions) {
|
for (Action a : myContextMenuActions) {
|
||||||
|
@ -249,15 +257,48 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void runAction(final Action action, final NetworkTree tree) {
|
||||||
|
if (tree instanceof NetworkCatalogTree) {
|
||||||
|
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
||||||
|
switch (item.getVisibility()) {
|
||||||
|
case B3_TRUE:
|
||||||
|
action.run(tree);
|
||||||
|
break;
|
||||||
|
case B3_UNDEFINED:
|
||||||
|
Util.runAuthenticationDialog(this, item.Link, null, new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (item.getVisibility() != ZLBoolean3.B3_TRUE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (action.Code != ActionCode.SIGNIN) {
|
||||||
|
action.run(tree);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
action.run(tree);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
final int position = ((AdapterView.AdapterContextMenuInfo)item.getMenuInfo()).position;
|
final int position = ((AdapterView.AdapterContextMenuInfo)item.getMenuInfo()).position;
|
||||||
final NetworkTree tree = (NetworkTree)getListAdapter().getItem(position);
|
final NetworkTree tree = (NetworkTree)getListAdapter().getItem(position);
|
||||||
if (tree != null) {
|
if (tree != null) {
|
||||||
|
for (Action a : myContextMenuActions) {
|
||||||
|
if (a.Code == item.getItemId()) {
|
||||||
|
runAction(a, tree);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
final NetworkTreeActions actions = NetworkView.Instance().getActions(tree);
|
final NetworkTreeActions actions = NetworkView.Instance().getActions(tree);
|
||||||
if (actions != null && actions.runAction(this, tree, item.getItemId())) {
|
if (actions != null && actions.runAction(this, tree, item.getItemId())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
return super.onContextItemSelected(item);
|
return super.onContextItemSelected(item);
|
||||||
}
|
}
|
||||||
|
@ -270,14 +311,13 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
||||||
|
|
||||||
final NetworkTree tree = (NetworkTree)getListAdapter().getItem(position);
|
final NetworkTree tree = (NetworkTree)getListAdapter().getItem(position);
|
||||||
Action defaultAction = null;
|
Action defaultAction = null;
|
||||||
int count = 0;
|
|
||||||
for (Action a : myContextMenuActions) {
|
for (Action a : myContextMenuActions) {
|
||||||
if (a.isVisible(tree) && a.isEnabled(tree)) {
|
if (a.isVisible(tree) && a.isEnabled(tree)) {
|
||||||
defaultAction = a;
|
runAction(a, tree);
|
||||||
++count;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count == 0) {
|
/*
|
||||||
final NetworkView networkView = NetworkView.Instance();
|
final NetworkView networkView = NetworkView.Instance();
|
||||||
final NetworkTreeActions actions = networkView.getActions(tree);
|
final NetworkTreeActions actions = networkView.getActions(tree);
|
||||||
if (actions == null) {
|
if (actions == null) {
|
||||||
|
@ -292,11 +332,7 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
actions.runAction(this, tree, actionCode);
|
actions.runAction(this, tree, actionCode);
|
||||||
} else if (count == 1) {
|
*/
|
||||||
defaultAction.run(tree);
|
|
||||||
} else {
|
|
||||||
// TODO: select "default" action
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final AuthenticationActivity.CredentialsCreator myCredentialsCreator =
|
private final AuthenticationActivity.CredentialsCreator myCredentialsCreator =
|
||||||
|
@ -309,9 +345,7 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
||||||
myCredentialsCreator.onDataReceived(resultCode, intent);
|
myCredentialsCreator.onDataReceived(resultCode, intent);
|
||||||
break;
|
break;
|
||||||
case CUSTOM_AUTHENTICATION_CODE:
|
case CUSTOM_AUTHENTICATION_CODE:
|
||||||
Util.processCustomAuthentication(
|
Util.processCustomAuthentication(this, resultCode, intent);
|
||||||
this, ((NetworkCatalogTree)getCurrentTree()).Item.Link, resultCode, intent
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
case SIGNUP_CODE:
|
case SIGNUP_CODE:
|
||||||
Util.processSignup(((NetworkCatalogTree)getCurrentTree()).Item.Link, resultCode, intent);
|
Util.processSignup(((NetworkCatalogTree)getCurrentTree()).Item.Link, resultCode, intent);
|
||||||
|
|
|
@ -61,8 +61,6 @@ abstract class NetworkTreeActions {
|
||||||
return addMenuItemWithText(menu, id, getTitleValue(key, arg));
|
return addMenuItemWithText(menu, id, getTitleValue(key, arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean canHandleTree(NetworkTree tree);
|
|
||||||
|
|
||||||
public abstract int getDefaultActionCode(NetworkLibraryActivity activity, NetworkTree tree);
|
public abstract int getDefaultActionCode(NetworkLibraryActivity activity, NetworkTree tree);
|
||||||
|
|
||||||
public abstract boolean runAction(NetworkLibraryActivity activity, NetworkTree tree, int actionCode);
|
public abstract boolean runAction(NetworkLibraryActivity activity, NetworkTree tree, int actionCode);
|
||||||
|
|
|
@ -43,7 +43,6 @@ public class NetworkView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private volatile boolean myInitialized;
|
private volatile boolean myInitialized;
|
||||||
private final ArrayList<NetworkTreeActions> myActions = new ArrayList<NetworkTreeActions>();
|
|
||||||
|
|
||||||
private NetworkView() {
|
private NetworkView() {
|
||||||
}
|
}
|
||||||
|
@ -59,11 +58,6 @@ public class NetworkView {
|
||||||
library.initialize();
|
library.initialize();
|
||||||
library.synchronize();
|
library.synchronize();
|
||||||
|
|
||||||
myActions.add(new NetworkBookActions());
|
|
||||||
myActions.add(new NetworkCatalogActions());
|
|
||||||
myActions.add(new SearchItemActions());
|
|
||||||
myActions.trimToSize();
|
|
||||||
|
|
||||||
myInitialized = true;
|
myInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,19 +74,6 @@ public class NetworkView {
|
||||||
fireModelChanged();
|
fireModelChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* NetworkItem's actions
|
|
||||||
*/
|
|
||||||
|
|
||||||
public NetworkTreeActions getActions(NetworkTree tree) {
|
|
||||||
for (NetworkTreeActions actions : myActions) {
|
|
||||||
if (actions.canHandleTree(tree)) {
|
|
||||||
return actions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Code for loading network items (running items-loading service and managing items-loading runnables).
|
* Code for loading network items (running items-loading service and managing items-loading runnables).
|
||||||
*/
|
*/
|
||||||
|
@ -147,7 +128,7 @@ public class NetworkView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final void fireModelChangedAsync() {
|
public final void fireModelChangedAsync() {
|
||||||
synchronized (myEventListeners) {
|
synchronized (myEventListeners) {
|
||||||
if (myEventHandler != null) {
|
if (myEventHandler != null) {
|
||||||
myEventHandler.sendEmptyMessage(0);
|
myEventHandler.sendEmptyMessage(0);
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.geometerplus.android.fbreader.network.action.ActionCode;
|
||||||
class SearchItemActions extends NetworkTreeActions {
|
class SearchItemActions extends NetworkTreeActions {
|
||||||
private static final int RUN_SEARCH_ITEM_ID = 0;
|
private static final int RUN_SEARCH_ITEM_ID = 0;
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canHandleTree(NetworkTree tree) {
|
public boolean canHandleTree(NetworkTree tree) {
|
||||||
return tree instanceof SearchItemTree;
|
return tree instanceof SearchItemTree;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,13 +45,12 @@ public class TopupMenuActivity extends ListActivity implements AdapterView.OnIte
|
||||||
|
|
||||||
public static boolean isTopupSupported(INetworkLink link) {
|
public static boolean isTopupSupported(INetworkLink link) {
|
||||||
// TODO: more correct check
|
// TODO: more correct check
|
||||||
return link.authenticationManager().topupLink() != null;
|
return link.getUrlInfo(UrlInfo.Type.TopUp) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runMenu(Context context, INetworkLink link, String amount) {
|
public static void runMenu(Context context, INetworkLink link, String amount) {
|
||||||
context.startActivity(
|
context.startActivity(
|
||||||
new Intent(context, TopupMenuActivity.class)
|
Util.intentByLink(new Intent(context, TopupMenuActivity.class), link)
|
||||||
.setData(Uri.parse(link.getUrlInfo(UrlInfo.Type.Catalog).Url))
|
|
||||||
.putExtra(AMOUNT_KEY, amount)
|
.putExtra(AMOUNT_KEY, amount)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +68,7 @@ public class TopupMenuActivity extends ListActivity implements AdapterView.OnIte
|
||||||
myAmount = getIntent().getStringExtra(AMOUNT_KEY);
|
myAmount = getIntent().getStringExtra(AMOUNT_KEY);
|
||||||
|
|
||||||
myInfos = new ArrayList<PluginApi.TopupActionInfo>();
|
myInfos = new ArrayList<PluginApi.TopupActionInfo>();
|
||||||
if (myLink.authenticationManager().topupLink() != null) {
|
if (myLink.getUrlInfo(UrlInfo.Type.TopUp) != null) {
|
||||||
myInfos.add(new PluginApi.TopupActionInfo(
|
myInfos.add(new PluginApi.TopupActionInfo(
|
||||||
Uri.parse(url + "/browser"),
|
Uri.parse(url + "/browser"),
|
||||||
NetworkLibrary.resource().getResource("topupViaBrowser").getValue(),
|
NetworkLibrary.resource().getResource("topupViaBrowser").getValue(),
|
||||||
|
@ -128,7 +127,9 @@ public class TopupMenuActivity extends ListActivity implements AdapterView.OnIte
|
||||||
final NetworkAuthenticationManager mgr = myLink.authenticationManager();
|
final NetworkAuthenticationManager mgr = myLink.authenticationManager();
|
||||||
if (info.getId().toString().endsWith("/browser")) {
|
if (info.getId().toString().endsWith("/browser")) {
|
||||||
// TODO: put amount
|
// TODO: put amount
|
||||||
Util.openInBrowser(TopupMenuActivity.this, mgr.topupLink());
|
if (mgr != null) {
|
||||||
|
Util.openInBrowser(TopupMenuActivity.this, mgr.topupLink());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
final Intent intent = new Intent(TOPUP_ACTION, info.getId());
|
final Intent intent = new Intent(TOPUP_ACTION, info.getId());
|
||||||
if (mgr != null) {
|
if (mgr != null) {
|
||||||
|
|
|
@ -43,6 +43,14 @@ 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";
|
||||||
|
|
||||||
|
static INetworkLink linkByIntent(Intent intent) {
|
||||||
|
return NetworkLibrary.Instance().getLinkByUrl(intent.getData().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
static Intent intentByLink(Intent intent, INetworkLink link) {
|
||||||
|
return intent.setData(Uri.parse(link.getUrl(UrlInfo.Type.Catalog)));
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean testService(Activity activity, String action, String url) {
|
private static boolean testService(Activity activity, String action, String url) {
|
||||||
return url != null && PackageUtil.canBeStarted(activity, new Intent(action, Uri.parse(url)), true);
|
return url != null && PackageUtil.canBeStarted(activity, new Intent(action, Uri.parse(url)), true);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +85,7 @@ public abstract class Util implements UserRegistrationConstants {
|
||||||
public static void runAuthenticationDialog(Activity activity, INetworkLink link, String error, Runnable onSuccess) {
|
public static void runAuthenticationDialog(Activity activity, INetworkLink link, String error, Runnable onSuccess) {
|
||||||
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||||
|
|
||||||
final Intent intent = new Intent(activity, AuthenticationActivity.class);
|
final Intent intent = intentByLink(new Intent(activity, AuthenticationActivity.class), link);
|
||||||
intent.putExtra(AuthenticationActivity.USERNAME_KEY, mgr.UserNameOption.getValue());
|
intent.putExtra(AuthenticationActivity.USERNAME_KEY, mgr.UserNameOption.getValue());
|
||||||
if (isRegistrationSupported(activity, link)) {
|
if (isRegistrationSupported(activity, link)) {
|
||||||
intent.putExtra(AuthenticationActivity.SHOW_SIGNUP_LINK_KEY, true);
|
intent.putExtra(AuthenticationActivity.SHOW_SIGNUP_LINK_KEY, true);
|
||||||
|
@ -90,9 +98,15 @@ public abstract class Util implements UserRegistrationConstants {
|
||||||
activity.startActivityForResult(intent, NetworkLibraryActivity.CUSTOM_AUTHENTICATION_CODE);
|
activity.startActivityForResult(intent, NetworkLibraryActivity.CUSTOM_AUTHENTICATION_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void processCustomAuthentication(final Activity activity, final INetworkLink link, int resultCode, Intent data) {
|
static void processCustomAuthentication(final Activity activity, int resultCode, Intent data) {
|
||||||
|
final INetworkLink link = linkByIntent(data);
|
||||||
|
if (link == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final Runnable onSuccess = ourAfterRegisrationMap.get(activity);
|
final Runnable onSuccess = ourAfterRegisrationMap.get(activity);
|
||||||
ourAfterRegisrationMap.remove(activity);
|
ourAfterRegisrationMap.remove(activity);
|
||||||
|
|
||||||
switch (resultCode) {
|
switch (resultCode) {
|
||||||
case AuthenticationActivity.RESULT_CANCELED:
|
case AuthenticationActivity.RESULT_CANCELED:
|
||||||
UIUtil.wait(
|
UIUtil.wait(
|
||||||
|
@ -187,7 +201,7 @@ public abstract class Util implements UserRegistrationConstants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void openInBrowser(Context context, String url) {
|
public static void openInBrowser(Context context, String url) {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
url = NetworkLibrary.Instance().rewriteUrl(url, true);
|
url = NetworkLibrary.Instance().rewriteUrl(url, true);
|
||||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010-2011 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.network.action;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.network.NetworkTree;
|
||||||
|
import org.geometerplus.fbreader.network.ICustomNetworkLink;
|
||||||
|
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
||||||
|
|
||||||
|
import org.geometerplus.android.fbreader.network.AddCustomCatalogActivity;
|
||||||
|
|
||||||
|
public class EditCustomCatalogAction extends CatalogAction {
|
||||||
|
public EditCustomCatalogAction(Activity activity) {
|
||||||
|
super(activity, ActionCode.CUSTOM_CATALOG_EDIT, "editCustomCatalog");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(NetworkTree tree) {
|
||||||
|
return
|
||||||
|
super.isVisible(tree) &&
|
||||||
|
((NetworkCatalogTree)tree).Item.Link instanceof ICustomNetworkLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(NetworkTree tree) {
|
||||||
|
final Intent intent = new Intent(myActivity, AddCustomCatalogActivity.class);
|
||||||
|
AddCustomCatalogActivity.addLinkToIntent(
|
||||||
|
intent,
|
||||||
|
(ICustomNetworkLink)((NetworkCatalogTree)tree).Item.Link
|
||||||
|
);
|
||||||
|
myActivity.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010-2011 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.network.action;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.network.NetworkTree;
|
||||||
|
import org.geometerplus.fbreader.network.NetworkCatalogItem;
|
||||||
|
import org.geometerplus.fbreader.network.NetworkURLCatalogItem;
|
||||||
|
import org.geometerplus.fbreader.network.opds.BasketItem;
|
||||||
|
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
||||||
|
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||||
|
|
||||||
|
import org.geometerplus.android.fbreader.network.NetworkCatalogActions;
|
||||||
|
|
||||||
|
import org.geometerplus.android.util.UIUtil;
|
||||||
|
|
||||||
|
public class OpenCatalogAction extends CatalogAction {
|
||||||
|
public OpenCatalogAction(Activity activity) {
|
||||||
|
super(activity, ActionCode.OPEN_CATALOG, "openCatalog");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(NetworkTree tree) {
|
||||||
|
if (!super.isVisible(tree)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
||||||
|
if (!(item instanceof NetworkURLCatalogItem)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
final String catalogUrl = ((NetworkURLCatalogItem)item).getUrl(UrlInfo.Type.Catalog);
|
||||||
|
|
||||||
|
return
|
||||||
|
catalogUrl != null &&
|
||||||
|
(!(item instanceof BasketItem) || item.Link.basket().bookIds().size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(NetworkTree tree) {
|
||||||
|
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
||||||
|
if (item instanceof BasketItem && item.Link.basket().bookIds().size() == 0) {
|
||||||
|
UIUtil.showErrorMessage(myActivity, "emptyBasket");
|
||||||
|
} else {
|
||||||
|
NetworkCatalogActions.doExpandCatalog(myActivity, (NetworkCatalogTree)tree);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010-2011 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.network.action;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.network.*;
|
||||||
|
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
||||||
|
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||||
|
|
||||||
|
import org.geometerplus.android.fbreader.network.Util;
|
||||||
|
|
||||||
|
public class OpenInBrowserAction extends CatalogAction {
|
||||||
|
public OpenInBrowserAction(Activity activity) {
|
||||||
|
super(activity, ActionCode.OPEN_IN_BROWSER, "openInBrowser");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(NetworkTree tree) {
|
||||||
|
if (!super.isVisible(tree)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
||||||
|
if (!(item instanceof NetworkURLCatalogItem)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((NetworkURLCatalogItem)item).getUrl(UrlInfo.Type.HtmlPage) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(NetworkTree tree) {
|
||||||
|
final String url =
|
||||||
|
((NetworkURLCatalogItem)((NetworkCatalogTree)tree).Item).getUrl(UrlInfo.Type.HtmlPage);
|
||||||
|
|
||||||
|
final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button");
|
||||||
|
final String message = NetworkLibrary.resource().getResource("confirmQuestions").getResource("openInBrowser").getValue();
|
||||||
|
new AlertDialog.Builder(myActivity)
|
||||||
|
.setTitle(tree.getName())
|
||||||
|
.setMessage(message)
|
||||||
|
.setIcon(0)
|
||||||
|
.setPositiveButton(buttonResource.getResource("yes").getValue(), new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
Util.openInBrowser(myActivity, url);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(buttonResource.getResource("no").getValue(), null)
|
||||||
|
.create().show();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010-2011 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.network.action;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.network.NetworkTree;
|
||||||
|
import org.geometerplus.fbreader.network.NetworkCatalogItem;
|
||||||
|
import org.geometerplus.fbreader.network.NetworkURLCatalogItem;
|
||||||
|
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
||||||
|
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||||
|
|
||||||
|
import org.geometerplus.android.fbreader.network.NetworkCatalogActions;
|
||||||
|
import org.geometerplus.android.fbreader.network.ItemsLoadingService;
|
||||||
|
|
||||||
|
public class ReloadCatalogAction extends CatalogAction {
|
||||||
|
public ReloadCatalogAction(Activity activity) {
|
||||||
|
super(activity, ActionCode.RELOAD_CATALOG, "reload");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(NetworkTree tree) {
|
||||||
|
if (!super.isVisible(tree)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
||||||
|
if (!(item instanceof NetworkURLCatalogItem)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return
|
||||||
|
((NetworkURLCatalogItem)item).getUrl(UrlInfo.Type.Catalog) != null &&
|
||||||
|
ItemsLoadingService.getRunnable(tree) == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(NetworkTree tree) {
|
||||||
|
if (ItemsLoadingService.getRunnable(tree) != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NetworkCatalogActions.clearTree(myActivity, (NetworkCatalogTree)tree);
|
||||||
|
ItemsLoadingService.start(
|
||||||
|
myActivity,
|
||||||
|
tree,
|
||||||
|
new NetworkCatalogActions.CatalogExpander(myActivity, (NetworkCatalogTree)tree, false, false)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010-2011 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.network.action;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||||
|
import org.geometerplus.fbreader.network.NetworkTree;
|
||||||
|
import org.geometerplus.fbreader.network.ICustomNetworkLink;
|
||||||
|
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
||||||
|
|
||||||
|
import org.geometerplus.android.fbreader.network.NetworkView;
|
||||||
|
|
||||||
|
public class RemoveCustomCatalogAction extends CatalogAction {
|
||||||
|
public RemoveCustomCatalogAction(Activity activity) {
|
||||||
|
super(activity, ActionCode.CUSTOM_CATALOG_REMOVE, "removeCustomCatalog");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(NetworkTree tree) {
|
||||||
|
return
|
||||||
|
super.isVisible(tree) &&
|
||||||
|
((NetworkCatalogTree)tree).Item.Link instanceof ICustomNetworkLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(NetworkTree tree) {
|
||||||
|
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||||
|
library.removeCustomLink((ICustomNetworkLink)((NetworkCatalogTree)tree).Item.Link);
|
||||||
|
library.synchronize();
|
||||||
|
NetworkView.Instance().fireModelChangedAsync();
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,36 +23,36 @@ import android.app.Activity;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.NetworkTree;
|
import org.geometerplus.fbreader.network.NetworkTree;
|
||||||
import org.geometerplus.fbreader.network.NetworkCatalogItem;
|
import org.geometerplus.fbreader.network.NetworkCatalogItem;
|
||||||
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
import org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree;
|
||||||
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.network.NetworkCatalogActions;
|
import org.geometerplus.android.fbreader.network.NetworkCatalogActions;
|
||||||
|
|
||||||
public class SignOutAction extends CatalogAction {
|
public class SignOutAction extends Action {
|
||||||
public SignOutAction(Activity activity) {
|
public SignOutAction(Activity activity) {
|
||||||
super(activity, ActionCode.SIGNOUT, "signOut");
|
super(activity, ActionCode.SIGNOUT, "signOut", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisible(NetworkTree tree) {
|
public boolean isVisible(NetworkTree tree) {
|
||||||
if (!super.isVisible(tree)) {
|
if (!(tree instanceof NetworkCatalogRootTree)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
final NetworkCatalogItem item = ((NetworkCatalogRootTree)tree).Item;
|
||||||
final NetworkAuthenticationManager mgr = item.Link.authenticationManager();
|
final NetworkAuthenticationManager mgr = item.Link.authenticationManager();
|
||||||
return mgr != null && mgr.mayBeAuthorised(false);
|
return mgr != null && mgr.mayBeAuthorised(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(NetworkTree tree) {
|
public void run(NetworkTree tree) {
|
||||||
NetworkCatalogActions.doSignOut(myActivity, (NetworkCatalogTree)tree);
|
NetworkCatalogActions.doSignOut(myActivity, (NetworkCatalogRootTree)tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOptionsLabel(NetworkTree tree) {
|
public String getOptionsLabel(NetworkTree tree) {
|
||||||
final NetworkAuthenticationManager mgr =
|
final NetworkAuthenticationManager mgr =
|
||||||
(((NetworkCatalogTree)tree).Item).Link.authenticationManager();
|
(((NetworkCatalogRootTree)tree).Item).Link.authenticationManager();
|
||||||
final String userName =
|
final String userName =
|
||||||
mgr != null && mgr.mayBeAuthorised(false) ? mgr.currentUserName() : "";
|
mgr != null && mgr.mayBeAuthorised(false) ? mgr.currentUserName() : "";
|
||||||
return super.getOptionsLabel(tree).replace("%s", userName);
|
return super.getOptionsLabel(tree).replace("%s", userName);
|
||||||
|
@ -61,7 +61,7 @@ public class SignOutAction extends CatalogAction {
|
||||||
@Override
|
@Override
|
||||||
public String getContextLabel(NetworkTree tree) {
|
public String getContextLabel(NetworkTree tree) {
|
||||||
final NetworkAuthenticationManager mgr =
|
final NetworkAuthenticationManager mgr =
|
||||||
(((NetworkCatalogTree)tree).Item).Link.authenticationManager();
|
(((NetworkCatalogRootTree)tree).Item).Link.authenticationManager();
|
||||||
final String userName =
|
final String userName =
|
||||||
mgr != null && mgr.mayBeAuthorised(false) ? mgr.currentUserName() : "";
|
mgr != null && mgr.mayBeAuthorised(false) ? mgr.currentUserName() : "";
|
||||||
return super.getContextLabel(tree).replace("%s", userName);
|
return super.getContextLabel(tree).replace("%s", userName);
|
||||||
|
|
|
@ -60,9 +60,13 @@ public abstract class BaseActivity extends ListActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(final Intent intent) {
|
||||||
if (OPEN_TREE_ACTION.equals(intent.getAction())) {
|
if (OPEN_TREE_ACTION.equals(intent.getAction())) {
|
||||||
init(intent);
|
runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
init(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue