mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
browser topup is back; topup methods sorting
This commit is contained in:
parent
81bd86d200
commit
6199b6ad3c
8 changed files with 86 additions and 31 deletions
|
@ -145,7 +145,13 @@
|
|||
<data android:host="*" android:scheme="opds" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.NetworkBaseActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.BrowserTopupActivity" android:process=":networkLibrary" android:theme="@android:style/Theme.NoDisplay">
|
||||
<intent-filter>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<action android:name="android.fbreader.action.network.TOPUP" />
|
||||
<data android:scheme="http" android:host="data.fbreader.org" android:path="/catalogs/litres2/index.php5/browser"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<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>
|
||||
|
|
|
@ -145,7 +145,13 @@
|
|||
<data android:host="*" android:scheme="opds" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.NetworkBaseActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.BrowserTopupActivity" android:process=":networkLibrary" android:theme="@android:style/Theme.NoDisplay">
|
||||
<intent-filter>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<action android:name="android.fbreader.action.network.TOPUP" />
|
||||
<data android:scheme="http" android:host="data.fbreader.org" android:path="/catalogs/litres2/index.php5/browser"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<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>
|
||||
|
|
|
@ -103,7 +103,7 @@ public abstract class PluginApi {
|
|||
}
|
||||
}
|
||||
|
||||
public static class TopupActionInfo extends ActionInfo {
|
||||
public static class TopupActionInfo extends ActionInfo implements Comparable<TopupActionInfo> {
|
||||
public final String MenuItemName;
|
||||
public final int Weight;
|
||||
|
||||
|
@ -124,5 +124,9 @@ public abstract class PluginApi {
|
|||
parcel.writeString(MenuItemName);
|
||||
parcel.writeInt(Weight);
|
||||
}
|
||||
|
||||
public int compareTo(TopupActionInfo info) {
|
||||
return Weight - info.Weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||
import org.geometerplus.fbreader.network.INetworkLink;
|
||||
|
||||
public class BrowserTopupActivity extends Activity {
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
String url = getIntent().getData().toString();
|
||||
if (url.endsWith("/browser")) {
|
||||
url = url.substring(0, url.length() - "/browser".length());
|
||||
final INetworkLink link = NetworkLibrary.Instance().getLinkByUrl(url);
|
||||
Util.openInBrowser(this, link.authenticationManager().topupLink());
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ import java.util.*;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.*;
|
||||
import android.view.*;
|
||||
import android.widget.AdapterView;
|
||||
|
@ -42,6 +43,7 @@ import org.geometerplus.android.util.UIUtil;
|
|||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
import org.geometerplus.fbreader.network.tree.*;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
|
||||
import org.geometerplus.android.fbreader.tree.BaseActivity;
|
||||
import org.geometerplus.android.fbreader.api.PluginApi;
|
||||
|
@ -290,12 +292,21 @@ public class NetworkLibraryActivity extends BaseActivity implements NetworkView.
|
|||
break;
|
||||
case LIST_TOPUP_METHODS_CODE:
|
||||
if (intent != null) {
|
||||
NetworkView.Instance().TopupActionInfos.put(
|
||||
intent.getData().toString(),
|
||||
final String url = intent.getData().toString();
|
||||
final List<PluginApi.TopupActionInfo> actions =
|
||||
intent.<PluginApi.TopupActionInfo>getParcelableArrayListExtra(
|
||||
PluginApi.PluginInfo.KEY
|
||||
)
|
||||
);
|
||||
final INetworkLink link = NetworkLibrary.Instance().getLinkByUrl(url);
|
||||
if (link != null) {
|
||||
actions.add(new PluginApi.TopupActionInfo(
|
||||
Uri.parse(url + "/browser"),
|
||||
NetworkLibrary.resource().getResource("topupViaBrowser").getValue(),
|
||||
100
|
||||
));
|
||||
}
|
||||
Collections.sort(actions);
|
||||
NetworkView.Instance().TopupActionInfos.put(url, actions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,21 +107,6 @@ class TopupActions extends NetworkTreeActions {
|
|||
}
|
||||
}
|
||||
|
||||
private static Runnable topupRunnable(final Activity activity, final INetworkLink link, final String actionId) {
|
||||
if (Util.BROWSER_ACTION_ID.equals(actionId)) {
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
Util.openInBrowser(
|
||||
activity,
|
||||
link.authenticationManager().topupLink()
|
||||
);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void doTopup(final Activity activity, final INetworkLink link, final Runnable action) {
|
||||
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||
if (mgr.mayBeAuthorised(false)) {
|
||||
|
|
|
@ -46,7 +46,6 @@ abstract class Util implements UserRegistrationConstants {
|
|||
"android.fbreader.action.NETWORK_LIBRARY_REGISTER";
|
||||
static final String TOPUP_ACTION =
|
||||
"android.fbreader.action.network.TOPUP";
|
||||
static final String BROWSER_ACTION_ID = "browser";
|
||||
|
||||
private static boolean testService(Activity activity, String action, String url) {
|
||||
return url != null && PackageUtil.canBeStarted(activity, new Intent(action, Uri.parse(url)), true);
|
||||
|
@ -198,14 +197,6 @@ abstract class Util implements UserRegistrationConstants {
|
|||
return infos != null && infos.size() > 0;
|
||||
}
|
||||
|
||||
static boolean isTopupSupported(Activity activity, INetworkLink link, String actionId) {
|
||||
if (BROWSER_ACTION_ID.equals(actionId)) {
|
||||
return link.getUrl(UrlInfo.Type.TopUp) != null;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void runTopupDialog(Activity activity, INetworkLink link, String url) {
|
||||
try {
|
||||
final Intent intent = new Intent(TOPUP_ACTION, Uri.parse(url));
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
|
|||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
import org.geometerplus.fbreader.network.tree.*;
|
||||
import org.geometerplus.fbreader.network.opds.OPDSLinkReader;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
|
||||
public class NetworkLibrary {
|
||||
private static NetworkLibrary ourInstance;
|
||||
|
@ -124,6 +125,17 @@ public class NetworkLibrary {
|
|||
return filteredList;
|
||||
}
|
||||
|
||||
public INetworkLink getLinkByUrl(String url) {
|
||||
synchronized (myLinks) {
|
||||
for (INetworkLink link : myLinks) {
|
||||
if (url.equals(link.getUrlInfo(UrlInfo.Type.Catalog).Url)) {
|
||||
return link;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final RootTree myRootTree = new RootTree("@Root", false);
|
||||
private final RootTree myFakeRootTree = new RootTree("@FakeRoot", true);
|
||||
private SearchItemTree mySearchItemTree;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue