mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
separate package for items
This commit is contained in:
parent
8af4ac1414
commit
aa69a4f43f
12 changed files with 221 additions and 82 deletions
|
@ -47,6 +47,8 @@ import org.geometerplus.fbreader.network.tree.NetworkAuthorTree;
|
|||
import org.geometerplus.fbreader.network.tree.NetworkSeriesTree;
|
||||
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
||||
|
||||
import org.geometerplus.android.fbreader.network.action.ActionCode;
|
||||
|
||||
class NetworkBookActions extends NetworkTreeActions {
|
||||
public static final int DOWNLOAD_BOOK_ITEM_ID = 0;
|
||||
public static final int DOWNLOAD_DEMO_ITEM_ID = 1;
|
||||
|
|
|
@ -46,6 +46,8 @@ import org.geometerplus.fbreader.network.*;
|
|||
import org.geometerplus.fbreader.network.tree.NetworkBookTree;
|
||||
import org.geometerplus.fbreader.network.urlInfo.*;
|
||||
|
||||
import org.geometerplus.android.fbreader.network.action.ActionCode;
|
||||
|
||||
public class NetworkBookInfoActivity extends Activity implements NetworkView.EventListener {
|
||||
private NetworkBookItem myBook;
|
||||
private View myMainView;
|
||||
|
|
|
@ -46,6 +46,8 @@ import org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree;
|
|||
import org.geometerplus.fbreader.network.opds.BasketItem;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
|
||||
import org.geometerplus.android.fbreader.network.action.ActionCode;
|
||||
|
||||
class NetworkCatalogActions extends NetworkTreeActions {
|
||||
@Override
|
||||
public boolean canHandleTree(NetworkTree tree) {
|
||||
|
@ -187,9 +189,6 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
|||
case ActionCode.SIGNIN:
|
||||
Util.runAuthenticationDialog(activity, item.Link, null, null);
|
||||
return true;
|
||||
case ActionCode.SIGNUP:
|
||||
Util.runRegistrationDialog(activity, item.Link);
|
||||
return true;
|
||||
case ActionCode.SIGNOUT:
|
||||
doSignOut(activity, catalogTree);
|
||||
return true;
|
||||
|
|
|
@ -50,6 +50,8 @@ import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationMan
|
|||
import org.geometerplus.android.fbreader.tree.BaseActivity;
|
||||
import org.geometerplus.android.fbreader.api.PluginApi;
|
||||
|
||||
import org.geometerplus.android.fbreader.network.action.*;
|
||||
|
||||
public class NetworkLibraryActivity extends BaseActivity implements NetworkView.EventListener {
|
||||
protected static final int BASIC_AUTHENTICATION_CODE = 1;
|
||||
protected static final int CUSTOM_AUTHENTICATION_CODE = 2;
|
||||
|
@ -291,52 +293,6 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
|||
return item;
|
||||
}
|
||||
|
||||
private static abstract class Action {
|
||||
final int Code;
|
||||
final int IconId;
|
||||
|
||||
private final String myResourceKey;
|
||||
|
||||
Action(int code, String resourceKey, int iconId) {
|
||||
Code = code;
|
||||
myResourceKey = resourceKey;
|
||||
IconId = iconId;
|
||||
}
|
||||
|
||||
abstract boolean isVisible(NetworkTree tree);
|
||||
|
||||
boolean isEnabled(NetworkTree tree) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String getLabel(NetworkTree tree) {
|
||||
return
|
||||
NetworkLibrary.resource().getResource("menu").getResource(myResourceKey).getValue();
|
||||
}
|
||||
}
|
||||
|
||||
private static class RootAction extends Action {
|
||||
RootAction(int code, String resourceKey, int iconId) {
|
||||
super(code, resourceKey, iconId);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isVisible(NetworkTree tree) {
|
||||
return tree instanceof RootTree;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CatalogAction extends Action {
|
||||
CatalogAction(int code, String resourceKey) {
|
||||
super(code, resourceKey, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isVisible(NetworkTree tree) {
|
||||
return tree instanceof NetworkCatalogTree;
|
||||
}
|
||||
}
|
||||
|
||||
private MenuItem addMenuItem(Menu menu, int index, String resourceKey, int iconId) {
|
||||
final String label = NetworkLibrary.resource().getResource("menu").getResource(resourceKey).getValue();
|
||||
return menu.add(0, index, Menu.NONE, label).setIcon(iconId);
|
||||
|
@ -359,16 +315,24 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
|||
myMenuActions.clear();
|
||||
myMenuActions.add(new RootAction(ActionCode.SEARCH, "networkSearch", R.drawable.ic_menu_search) {
|
||||
@Override
|
||||
boolean isEnabled(NetworkTree tree) {
|
||||
public boolean isEnabled(NetworkTree tree) {
|
||||
return !searchIsInProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(NetworkTree tree) {
|
||||
onSearchRequested();
|
||||
}
|
||||
});
|
||||
myMenuActions.add(new RootAction(ActionCode.CUSTOM_CATALOG_ADD, "addCustomCatalog", R.drawable.ic_menu_add) {
|
||||
});
|
||||
myMenuActions.add(new RootAction(ActionCode.REFRESH, "refreshCatalogsList", R.drawable.ic_menu_refresh) {
|
||||
});
|
||||
myMenuActions.add(new RootAction(ActionCode.LANGUAGE_FILTER, "languages", R.drawable.ic_menu_languages) {
|
||||
});
|
||||
myMenuActions.add(new RootAction(ActionCode.CUSTOM_CATALOG_ADD, "addCustomCatalog", R.drawable.ic_menu_add));
|
||||
myMenuActions.add(new RootAction(ActionCode.REFRESH, "refreshCatalogsList", R.drawable.ic_menu_refresh));
|
||||
myMenuActions.add(new RootAction(ActionCode.LANGUAGE_FILTER, "languages", R.drawable.ic_menu_languages));
|
||||
myMenuActions.add(new CatalogAction(ActionCode.RELOAD_CATALOG, "reload") {
|
||||
@Override
|
||||
boolean isVisible(NetworkTree tree) {
|
||||
public boolean isVisible(NetworkTree tree) {
|
||||
if (!super.isVisible(tree)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -383,7 +347,7 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
|||
});
|
||||
myMenuActions.add(new CatalogAction(ActionCode.SIGNIN, "signIn") {
|
||||
@Override
|
||||
boolean isVisible(NetworkTree tree) {
|
||||
public boolean isVisible(NetworkTree tree) {
|
||||
if (!super.isVisible(tree)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -393,24 +357,10 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
|||
return mgr != null && !mgr.mayBeAuthorised(false);
|
||||
}
|
||||
});
|
||||
myMenuActions.add(new CatalogAction(ActionCode.SIGNUP, "signUp") {
|
||||
@Override
|
||||
boolean isVisible(NetworkTree tree) {
|
||||
if (!super.isVisible(tree)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
||||
final NetworkAuthenticationManager mgr = item.Link.authenticationManager();
|
||||
return
|
||||
mgr != null &&
|
||||
!mgr.mayBeAuthorised(false) &&
|
||||
Util.isRegistrationSupported(NetworkLibraryActivity.this, item.Link);
|
||||
}
|
||||
});
|
||||
myMenuActions.add(new SignUpAction(this));
|
||||
myMenuActions.add(new CatalogAction(ActionCode.SIGNOUT, "signOut") {
|
||||
@Override
|
||||
boolean isVisible(NetworkTree tree) {
|
||||
public boolean isVisible(NetworkTree tree) {
|
||||
if (!super.isVisible(tree)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -421,7 +371,7 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
|||
}
|
||||
|
||||
@Override
|
||||
String getLabel(NetworkTree tree) {
|
||||
public String getLabel(NetworkTree tree) {
|
||||
final NetworkAuthenticationManager mgr =
|
||||
(((NetworkCatalogTree)tree).Item).Link.authenticationManager();
|
||||
final String userName =
|
||||
|
@ -431,7 +381,7 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
|||
});
|
||||
myMenuActions.add(new CatalogAction(ActionCode.TOPUP, "topup") {
|
||||
@Override
|
||||
boolean isVisible(NetworkTree tree) {
|
||||
public boolean isVisible(NetworkTree tree) {
|
||||
if (!super.isVisible(tree)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -485,10 +435,16 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
|||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (getCurrentTree() instanceof RootTree) {
|
||||
final NetworkTree tree = (NetworkTree)getCurrentTree();
|
||||
for (Action a : myMenuActions) {
|
||||
if (a.Code == item.getItemId()) {
|
||||
a.run(tree);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tree instanceof RootTree) {
|
||||
switch (item.getItemId()) {
|
||||
case ActionCode.SEARCH:
|
||||
return onSearchRequested();
|
||||
case ActionCode.CUSTOM_CATALOG_ADD:
|
||||
AddCustomCatalogItemActions.addCustomCatalog(this);
|
||||
return true;
|
||||
|
@ -502,7 +458,6 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
|||
return true;
|
||||
}
|
||||
} else {
|
||||
final NetworkTree tree = (NetworkTree)getCurrentTree();
|
||||
final NetworkTreeActions actions = NetworkView.Instance().getActions(tree);
|
||||
if (actions != null) {
|
||||
return actions.runAction(this, tree, item.getItemId());
|
||||
|
|
|
@ -27,6 +27,8 @@ import android.view.MenuItem;
|
|||
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||
import org.geometerplus.fbreader.network.NetworkTree;
|
||||
|
||||
import org.geometerplus.android.fbreader.network.action.ActionCode;
|
||||
|
||||
abstract class NetworkTreeActions {
|
||||
// special values to return from getDefaultActionCode(NetworkTree)
|
||||
protected final String getTitleValue(String key) {
|
||||
|
|
|
@ -24,6 +24,8 @@ import android.view.ContextMenu;
|
|||
import org.geometerplus.fbreader.network.NetworkTree;
|
||||
import org.geometerplus.fbreader.network.tree.SearchItemTree;
|
||||
|
||||
import org.geometerplus.android.fbreader.network.action.ActionCode;
|
||||
|
||||
class SearchItemActions extends NetworkTreeActions {
|
||||
private static final int RUN_SEARCH_ITEM_ID = 0;
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
|||
import org.geometerplus.android.util.UIUtil;
|
||||
import org.geometerplus.android.util.PackageUtil;
|
||||
|
||||
abstract class Util implements UserRegistrationConstants {
|
||||
public abstract class Util implements UserRegistrationConstants {
|
||||
private static final String REGISTRATION_ACTION =
|
||||
"android.fbreader.action.NETWORK_LIBRARY_REGISTER";
|
||||
|
||||
|
@ -47,7 +47,7 @@ abstract class Util implements UserRegistrationConstants {
|
|||
return url != null && PackageUtil.canBeStarted(activity, new Intent(action, Uri.parse(url)), true);
|
||||
}
|
||||
|
||||
static boolean isRegistrationSupported(Activity activity, INetworkLink link) {
|
||||
public static boolean isRegistrationSupported(Activity activity, INetworkLink link) {
|
||||
return testService(
|
||||
activity,
|
||||
REGISTRATION_ACTION,
|
||||
|
@ -55,7 +55,7 @@ abstract class Util implements UserRegistrationConstants {
|
|||
);
|
||||
}
|
||||
|
||||
static void runRegistrationDialog(Activity activity, INetworkLink link) {
|
||||
public static void runRegistrationDialog(Activity activity, INetworkLink link) {
|
||||
try {
|
||||
final Intent intent = new Intent(
|
||||
REGISTRATION_ACTION,
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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 java.util.*;
|
||||
|
||||
import org.geometerplus.fbreader.network.NetworkTree;
|
||||
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||
|
||||
public abstract class Action {
|
||||
public final int Code;
|
||||
public final int IconId;
|
||||
|
||||
private final String myResourceKey;
|
||||
|
||||
protected Action(int code, String resourceKey, int iconId) {
|
||||
Code = code;
|
||||
myResourceKey = resourceKey;
|
||||
IconId = iconId;
|
||||
}
|
||||
|
||||
public abstract boolean isVisible(NetworkTree tree);
|
||||
|
||||
public boolean isEnabled(NetworkTree tree) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: change to abstract
|
||||
public void run(NetworkTree tree) {
|
||||
}
|
||||
|
||||
public String getLabel(NetworkTree tree) {
|
||||
return
|
||||
NetworkLibrary.resource().getResource("menu").getResource(myResourceKey).getValue();
|
||||
}
|
||||
}
|
|
@ -17,9 +17,9 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.android.fbreader.network;
|
||||
package org.geometerplus.android.fbreader.network.action;
|
||||
|
||||
interface ActionCode {
|
||||
public interface ActionCode {
|
||||
int TREE_SHOW_CONTEXT_MENU = -2;
|
||||
int TREE_NO_ACTION = -1;
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 org.geometerplus.fbreader.network.NetworkTree;
|
||||
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
||||
|
||||
public class CatalogAction extends Action {
|
||||
protected CatalogAction(int code, String resourceKey) {
|
||||
super(code, resourceKey, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(NetworkTree tree) {
|
||||
return tree instanceof NetworkCatalogTree;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 org.geometerplus.fbreader.network.NetworkTree;
|
||||
import org.geometerplus.fbreader.network.tree.RootTree;
|
||||
|
||||
public class RootAction extends Action {
|
||||
protected RootAction(int code, String resourceKey, int iconId) {
|
||||
super(code, resourceKey, iconId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(NetworkTree tree) {
|
||||
return tree instanceof RootTree;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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 org.geometerplus.fbreader.network.NetworkTree;
|
||||
import org.geometerplus.fbreader.network.NetworkCatalogItem;
|
||||
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
||||
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
||||
|
||||
import org.geometerplus.android.fbreader.network.NetworkLibraryActivity;
|
||||
import org.geometerplus.android.fbreader.network.Util;
|
||||
|
||||
public class SignUpAction extends CatalogAction {
|
||||
private final NetworkLibraryActivity myActivity;
|
||||
|
||||
public SignUpAction(NetworkLibraryActivity activity) {
|
||||
super(ActionCode.SIGNUP, "signUp");
|
||||
myActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(NetworkTree tree) {
|
||||
if (!super.isVisible(tree)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final NetworkCatalogItem item = ((NetworkCatalogTree)tree).Item;
|
||||
final NetworkAuthenticationManager mgr = item.Link.authenticationManager();
|
||||
return
|
||||
mgr != null &&
|
||||
!mgr.mayBeAuthorised(false) &&
|
||||
Util.isRegistrationSupported(myActivity, item.Link);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(NetworkTree tree) {
|
||||
Util.runRegistrationDialog(myActivity, (((NetworkCatalogTree)tree).Item).Link);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue