mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
code simplification: openInBrowser is now a static method in Util; sms account refilling (in progress)
This commit is contained in:
parent
3309fe02ab
commit
15b1e282a6
6 changed files with 51 additions and 33 deletions
|
@ -442,7 +442,7 @@ class NetworkBookActions extends NetworkTreeActions {
|
||||||
private static void doBuyInBrowser(Activity activity, final NetworkBookItem book) {
|
private static void doBuyInBrowser(Activity activity, final NetworkBookItem book) {
|
||||||
BookReference reference = book.reference(BookReference.Type.BUY_IN_BROWSER);
|
BookReference reference = book.reference(BookReference.Type.BUY_IN_BROWSER);
|
||||||
if (reference != null) {
|
if (reference != null) {
|
||||||
NetworkView.Instance().openInBrowser(activity, reference.URL);
|
Util.openInBrowser(activity, reference.URL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,7 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
doExpandCatalog(activity, (NetworkCatalogTree)tree);
|
doExpandCatalog(activity, (NetworkCatalogTree)tree);
|
||||||
return true;
|
return true;
|
||||||
case OPEN_IN_BROWSER_ITEM_ID:
|
case OPEN_IN_BROWSER_ITEM_ID:
|
||||||
NetworkView.Instance().openInBrowser(
|
Util.openInBrowser(
|
||||||
activity,
|
activity,
|
||||||
((NetworkCatalogTree)tree).Item.URLByType.get(NetworkCatalogItem.URL_HTML_PAGE)
|
((NetworkCatalogTree)tree).Item.URLByType.get(NetworkCatalogItem.URL_HTML_PAGE)
|
||||||
);
|
);
|
||||||
|
@ -256,7 +256,7 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
doSignOut(activity, (NetworkCatalogTree)tree);
|
doSignOut(activity, (NetworkCatalogTree)tree);
|
||||||
return true;
|
return true;
|
||||||
case REFILL_ACCOUNT_ITEM_ID:
|
case REFILL_ACCOUNT_ITEM_ID:
|
||||||
NetworkView.Instance().openInBrowser(
|
Util.openInBrowser(
|
||||||
activity,
|
activity,
|
||||||
((NetworkCatalogTree)tree).Item.Link.authenticationManager().refillAccountLink()
|
((NetworkCatalogTree)tree).Item.Link.authenticationManager().refillAccountLink()
|
||||||
);
|
);
|
||||||
|
|
|
@ -191,17 +191,6 @@ class NetworkView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Open Network URL in browser
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void openInBrowser(Context context, String url) {
|
|
||||||
if (url != null) {
|
|
||||||
url = NetworkLibrary.Instance().rewriteUrl(url, true);
|
|
||||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Notifying view's components from services
|
* Notifying view's components from services
|
||||||
|
|
|
@ -82,32 +82,52 @@ class RefillAccountActions extends NetworkTreeActions {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean runAction(NetworkBaseActivity activity, NetworkTree tree, int actionCode) {
|
public boolean runAction(NetworkBaseActivity activity, NetworkTree tree, int actionCode) {
|
||||||
|
final INetworkLink link = ((RefillAccountTree)tree).Link;
|
||||||
|
Runnable refillRunnable = null;
|
||||||
switch (actionCode) {
|
switch (actionCode) {
|
||||||
case REFILL_VIA_SMS_ITEM_ID:
|
case REFILL_VIA_SMS_ITEM_ID:
|
||||||
//doRefill(activity, (RefillAccountTree) tree);
|
refillRunnable = smsRefillRunnable(activity, link);
|
||||||
return true;
|
break;
|
||||||
case REFILL_VIA_BROWSER_ITEM_ID:
|
case REFILL_VIA_BROWSER_ITEM_ID:
|
||||||
doRefill(activity, (RefillAccountTree) tree);
|
refillRunnable = browserRefillRunnable(activity, link);
|
||||||
return true;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
if (refillRunnable == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
doRefill(activity, link, refillRunnable);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doRefill(final NetworkBaseActivity activity, final RefillAccountTree tree) {
|
private Runnable browserRefillRunnable(final NetworkBaseActivity activity, final INetworkLink link) {
|
||||||
final NetworkAuthenticationManager mgr = tree.Link.authenticationManager();
|
return new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
Util.openInBrowser(
|
||||||
|
activity,
|
||||||
|
link.authenticationManager().refillAccountLink()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Runnable smsRefillRunnable(final NetworkBaseActivity activity, final INetworkLink link) {
|
||||||
|
return new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
// TODO: implement
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doRefill(final NetworkBaseActivity activity, final INetworkLink link, final Runnable refiller) {
|
||||||
|
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||||
if (mgr.mayBeAuthorised(false)) {
|
if (mgr.mayBeAuthorised(false)) {
|
||||||
NetworkView.Instance().openInBrowser(
|
refiller.run();
|
||||||
activity,
|
|
||||||
tree.Link.authenticationManager().refillAccountLink()
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
NetworkDialog.show(activity, NetworkDialog.DIALOG_AUTHENTICATION, tree.Link, new Runnable() {
|
NetworkDialog.show(activity, NetworkDialog.DIALOG_AUTHENTICATION, link, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (mgr.mayBeAuthorised(false)) {
|
if (mgr.mayBeAuthorised(false)) {
|
||||||
NetworkView.Instance().openInBrowser(
|
refiller.run();
|
||||||
activity,
|
|
||||||
tree.Link.authenticationManager().refillAccountLink()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,10 +22,12 @@ package org.geometerplus.android.fbreader.network;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||||
import org.geometerplus.fbreader.network.INetworkLink;
|
import org.geometerplus.fbreader.network.INetworkLink;
|
||||||
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
||||||
|
|
||||||
|
@ -90,4 +92,11 @@ abstract class Util implements UserRegistrationConstants {
|
||||||
static boolean isBrowserAccountRefillingSupported(Activity activity, INetworkLink link) {
|
static boolean isBrowserAccountRefillingSupported(Activity activity, INetworkLink link) {
|
||||||
return link.getLink(INetworkLink.URL_REFILL_ACCOUNT) != null;
|
return link.getLink(INetworkLink.URL_REFILL_ACCOUNT) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void openInBrowser(Context context, String url) {
|
||||||
|
if (url != null) {
|
||||||
|
url = NetworkLibrary.Instance().rewriteUrl(url, true);
|
||||||
|
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public abstract class FormatPlugin {
|
||||||
String language = book.getLanguage();
|
String language = book.getLanguage();
|
||||||
String encoding = book.getEncoding();
|
String encoding = book.getEncoding();
|
||||||
if (encoding.length() == 0 || language.length() == 0) {
|
if (encoding.length() == 0 || language.length() == 0) {
|
||||||
PluginCollection collection = PluginCollection.instance();
|
PluginCollection collection = PluginCollection.Instance();
|
||||||
if (language.length() == 0) {
|
if (language.length() == 0) {
|
||||||
language = collection.DefaultLanguageOption.getValue();
|
language = collection.DefaultLanguageOption.getValue();
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public abstract class FormatPlugin {
|
||||||
public static void detectEncodingAndLanguage(Book book, InputStream stream) {
|
public static void detectEncodingAndLanguage(Book book, InputStream stream) {
|
||||||
String encoding = book.getEncoding();
|
String encoding = book.getEncoding();
|
||||||
if (encoding.length() == 0) {
|
if (encoding.length() == 0) {
|
||||||
encoding = EncodingDetector.detect(stream, PluginCollection.instance().DefaultLanguageOption.getValue());
|
encoding = EncodingDetector.detect(stream, PluginCollection.Instance().DefaultLanguageOption.getValue());
|
||||||
if (encoding == "unknown") {
|
if (encoding == "unknown") {
|
||||||
encoding = "windows-1252";
|
encoding = "windows-1252";
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ public abstract class FormatPlugin {
|
||||||
(encoding.equals("IBM866"))) {
|
(encoding.equals("IBM866"))) {
|
||||||
book.setLanguage("ru");
|
book.setLanguage("ru");
|
||||||
} /*else if (
|
} /*else if (
|
||||||
(PluginCollection.instance().DefaultLanguageOption.getValue() == EncodingDetector.Language.CZECH) &&
|
(PluginCollection.Instance().DefaultLanguageOption.getValue() == EncodingDetector.Language.CZECH) &&
|
||||||
((encoding == "windows-1250") ||
|
((encoding == "windows-1250") ||
|
||||||
(encoding == "ISO-8859-2") ||
|
(encoding == "ISO-8859-2") ||
|
||||||
(encoding == "IBM852"))) {
|
(encoding == "IBM852"))) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue