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

better network library initialization error processing

This commit is contained in:
Nikolay Pultsin 2014-11-04 01:00:06 +00:00
parent 645d2b1ccf
commit cdbd9b22c7
4 changed files with 21 additions and 6 deletions

View file

@ -23,7 +23,7 @@ import android.content.Intent;
import android.content.ActivityNotFoundException;
import android.net.Uri;
import org.geometerplus.zlibrary.core.network.QuietNetworkContext;
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
import org.geometerplus.zlibrary.text.view.*;
import org.geometerplus.fbreader.fbreader.FBReaderApp;
@ -31,7 +31,9 @@ import org.geometerplus.fbreader.bookmodel.FBHyperlinkType;
import org.geometerplus.fbreader.network.NetworkLibrary;
import org.geometerplus.android.fbreader.network.*;
import org.geometerplus.android.fbreader.network.auth.ActivityNetworkContext;
import org.geometerplus.android.fbreader.image.ImageViewActivity;
import org.geometerplus.android.util.UIUtil;
class ProcessHyperlinkAction extends FBAndroidAction {
ProcessHyperlinkAction(FBReader baseActivity, FBReaderApp fbreader) {
@ -103,7 +105,13 @@ class ProcessHyperlinkAction extends FBAndroidAction {
new Thread(new Runnable() {
public void run() {
if (!url.startsWith("fbreader-action:")) {
nLibrary.initialize(new QuietNetworkContext());
try {
nLibrary.initialize(new ActivityNetworkContext(BaseActivity));
} catch (ZLNetworkException e) {
e.printStackTrace();
UIUtil.showMessageText(BaseActivity, e.getMessage());
return;
}
}
intent.setData(Util.rewriteUri(Uri.parse(nLibrary.rewriteUrl(url, externalUrl))));
BaseActivity.runOnUiThread(new Runnable() {

View file

@ -124,7 +124,10 @@ public class NetworkBookInfoActivity extends Activity implements NetworkLibrary.
if (SQLiteNetworkDatabase.Instance() == null) {
new SQLiteNetworkDatabase(getApplication());
}
try {
library.initialize(myNetworkContext);
} catch (ZLNetworkException e) {
}
}
if (myBook == null) {

View file

@ -27,6 +27,7 @@ import android.content.Intent;
import android.net.Uri;
import org.geometerplus.zlibrary.core.network.ZLNetworkContext;
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
import org.geometerplus.zlibrary.core.options.Config;
import org.geometerplus.fbreader.network.*;
@ -65,7 +66,10 @@ public abstract class Util implements UserRegistrationConstants {
final NetworkLibrary library = NetworkLibrary.Instance();
if (!library.isInitialized()) {
try {
library.initialize(nc);
} catch (ZLNetworkException e) {
}
}
if (action != null) {
action.run();

View file

@ -277,7 +277,7 @@ public class NetworkLibrary {
return myIsInitialized;
}
public synchronized void initialize(ZLNetworkContext nc) {
public synchronized void initialize(ZLNetworkContext nc) throws ZLNetworkException {
if (myIsInitialized) {
return;
}
@ -287,7 +287,7 @@ public class NetworkLibrary {
} catch (ZLNetworkException e) {
removeAllLoadedLinks();
fireModelChangedEvent(ChangeListener.Code.InitializationFailed, e.getMessage());
return;
throw e;
}
final NetworkDatabase db = NetworkDatabase.Instance();