mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
new implementation of add custom catalog/open catalog actions
This commit is contained in:
parent
74a3cb54e5
commit
dec2e84b5f
5 changed files with 63 additions and 46 deletions
|
@ -42,8 +42,6 @@ import org.geometerplus.fbreader.network.urlInfo.*;
|
|||
import org.geometerplus.android.util.UIUtil;
|
||||
|
||||
public class AddCustomCatalogActivity extends Activity {
|
||||
static final String ADD_CATALOG = "android.fbreader.action.ADD_CATALOG";
|
||||
|
||||
private static final String ADD_CATALOG_TITLE_KEY = "title";
|
||||
private static final String ADD_CATALOG_SUMMARY_KEY = "summary";
|
||||
private static final String ADD_CATALOG_ID_KEY = "id";
|
||||
|
@ -113,6 +111,8 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
}
|
||||
);
|
||||
|
||||
Util.initLibrary(this);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
myLink = getLinkFromIntent(intent);
|
||||
final Uri uri = intent.getData();
|
||||
|
@ -161,14 +161,20 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
myLink.setSummary(summary);
|
||||
myLink.setUrl(UrlInfo.Type.Catalog, uri.toString());
|
||||
|
||||
Intent intent = new Intent(
|
||||
ADD_CATALOG,
|
||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||
library.addCustomLink(myLink);
|
||||
library.synchronize();
|
||||
|
||||
final Intent intent = new Intent(
|
||||
NetworkLibraryActivity.OPEN_CATALOG_ACTION,
|
||||
uri,
|
||||
AddCustomCatalogActivity.this,
|
||||
NetworkLibraryActivity.class
|
||||
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
|
||||
addLinkToIntent(intent, myLink);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,14 +44,14 @@ import org.geometerplus.android.fbreader.network.action.*;
|
|||
import org.geometerplus.android.util.UIUtil;
|
||||
|
||||
public class NetworkLibraryActivity extends TreeActivity implements NetworkLibrary.ChangeListener {
|
||||
static final String OPEN_CATALOG_ACTION = "android.fbreader.action.OPEN_NETWORK_CATALOG";
|
||||
|
||||
protected static final int BASIC_AUTHENTICATION_CODE = 1;
|
||||
protected static final int SIGNUP_CODE = 2;
|
||||
protected static final int AUTO_SIGNIN_CODE = 3;
|
||||
|
||||
BookDownloaderServiceConnection Connection;
|
||||
|
||||
private volatile Intent myDeferredIntent;
|
||||
|
||||
final List<Action> myOptionsMenuActions = new ArrayList<Action>();
|
||||
final List<Action> myContextMenuActions = new ArrayList<Action>();
|
||||
final List<Action> myListClickActions = new ArrayList<Action>();
|
||||
|
@ -75,19 +75,14 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
|||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
|
||||
if (getCurrentTree() instanceof RootTree) {
|
||||
myDeferredIntent = getIntent();
|
||||
|
||||
if (!NetworkLibrary.Instance().isInitialized()) {
|
||||
initLibrary();
|
||||
Util.initLibrary(this);
|
||||
} else {
|
||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.InitializationFinished);
|
||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
||||
if (myDeferredIntent != null) {
|
||||
processIntent(myDeferredIntent);
|
||||
myDeferredIntent = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
openTreeByIntent(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -127,11 +122,23 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
|||
super.onDestroy();
|
||||
}
|
||||
|
||||
private boolean openTreeByIntent(Intent intent) {
|
||||
if (OPEN_CATALOG_ACTION.equals(intent.getAction())) {
|
||||
final NetworkTree tree =
|
||||
NetworkLibrary.Instance().getCatalogTreeByUrl(intent.getData().toString());
|
||||
if (tree != null) {
|
||||
openTree(tree);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
if (!openTreeByIntent(intent)) {
|
||||
super.onNewIntent(intent);
|
||||
|
||||
processIntent(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -354,10 +361,6 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
|||
break;
|
||||
case InitializationFinished:
|
||||
NetworkLibrary.Instance().runBackgroundUpdate(false);
|
||||
if (myDeferredIntent != null) {
|
||||
processIntent(myDeferredIntent);
|
||||
myDeferredIntent = null;
|
||||
}
|
||||
break;
|
||||
case Found:
|
||||
openTree((NetworkTree)params[0]);
|
||||
|
@ -387,39 +390,16 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
|||
return tree;
|
||||
}
|
||||
|
||||
private void processIntent(Intent intent) {
|
||||
if (AddCustomCatalogActivity.ADD_CATALOG.equals(intent.getAction())) {
|
||||
final ICustomNetworkLink link = AddCustomCatalogActivity.getLinkFromIntent(intent);
|
||||
if (link != null) {
|
||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||
library.addCustomLink(link);
|
||||
library.synchronize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCurrentTreeChanged() {
|
||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
||||
}
|
||||
|
||||
private void initLibrary() {
|
||||
UIUtil.wait("loadingNetworkLibrary", new Runnable() {
|
||||
public void run() {
|
||||
if (SQLiteNetworkDatabase.Instance() == null) {
|
||||
new SQLiteNetworkDatabase();
|
||||
}
|
||||
|
||||
NetworkLibrary.Instance().initialize();
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
private void showInitLibraryDialog(String error) {
|
||||
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
initLibrary();
|
||||
Util.initLibrary(NetworkLibraryActivity.this);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.geometerplus.fbreader.network.authentication.litres.LitResAuthenticat
|
|||
import org.geometerplus.fbreader.network.tree.NetworkBookTree;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
|
||||
import org.geometerplus.android.util.UIUtil;
|
||||
import org.geometerplus.android.util.PackageUtil;
|
||||
|
||||
public abstract class Util implements UserRegistrationConstants {
|
||||
|
@ -49,6 +50,23 @@ public abstract class Util implements UserRegistrationConstants {
|
|||
return intent.setData(Uri.parse(link.getUrl(UrlInfo.Type.Catalog)));
|
||||
}
|
||||
|
||||
static void initLibrary(Activity activity) {
|
||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||
if (library.isInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
UIUtil.wait("loadingNetworkLibrary", new Runnable() {
|
||||
public void run() {
|
||||
if (SQLiteNetworkDatabase.Instance() == null) {
|
||||
new SQLiteNetworkDatabase();
|
||||
}
|
||||
|
||||
library.initialize();
|
||||
}
|
||||
}, activity);
|
||||
}
|
||||
|
||||
private static boolean testService(Activity activity, String action, String url) {
|
||||
return url != null && PackageUtil.canBeStarted(activity, new Intent(action, Uri.parse(url)), true);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.geometerplus.android.util.UIUtil;
|
|||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
|
||||
public abstract class TreeActivity extends ListActivity {
|
||||
private static final String OPEN_TREE_ACTION = "org.fbreader.intent.OPEN_TREE";
|
||||
private static final String OPEN_TREE_ACTION = "android.fbreader.action.OPEN_TREE";
|
||||
|
||||
public static final String TREE_KEY_KEY = "TreeKey";
|
||||
public static final String SELECTED_TREE_KEY_KEY = "SelectedTreeKey";
|
||||
|
|
|
@ -157,6 +157,19 @@ public class NetworkLibrary {
|
|||
return null;
|
||||
}
|
||||
|
||||
public NetworkTree getCatalogTreeByUrl(String url) {
|
||||
for (FBTree tree : getRootTree().subTrees()) {
|
||||
if (tree instanceof NetworkCatalogRootTree) {
|
||||
final String cUrl =
|
||||
((NetworkCatalogTree)tree).getLink().getUrlInfo(UrlInfo.Type.Catalog).Url;
|
||||
if (url.equals(cUrl)) {
|
||||
return (NetworkTree)tree;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public INetworkLink getLinkBySiteName(String siteName) {
|
||||
synchronized (myLinks) {
|
||||
for (INetworkLink link : myLinks) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue