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;
|
import org.geometerplus.android.util.UIUtil;
|
||||||
|
|
||||||
public class AddCustomCatalogActivity extends Activity {
|
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_TITLE_KEY = "title";
|
||||||
private static final String ADD_CATALOG_SUMMARY_KEY = "summary";
|
private static final String ADD_CATALOG_SUMMARY_KEY = "summary";
|
||||||
private static final String ADD_CATALOG_ID_KEY = "id";
|
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();
|
final Intent intent = getIntent();
|
||||||
myLink = getLinkFromIntent(intent);
|
myLink = getLinkFromIntent(intent);
|
||||||
final Uri uri = intent.getData();
|
final Uri uri = intent.getData();
|
||||||
|
@ -161,14 +161,20 @@ public class AddCustomCatalogActivity extends Activity {
|
||||||
myLink.setSummary(summary);
|
myLink.setSummary(summary);
|
||||||
myLink.setUrl(UrlInfo.Type.Catalog, uri.toString());
|
myLink.setUrl(UrlInfo.Type.Catalog, uri.toString());
|
||||||
|
|
||||||
Intent intent = new Intent(
|
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||||
ADD_CATALOG,
|
library.addCustomLink(myLink);
|
||||||
|
library.synchronize();
|
||||||
|
|
||||||
|
final Intent intent = new Intent(
|
||||||
|
NetworkLibraryActivity.OPEN_CATALOG_ACTION,
|
||||||
uri,
|
uri,
|
||||||
AddCustomCatalogActivity.this,
|
AddCustomCatalogActivity.this,
|
||||||
NetworkLibraryActivity.class
|
NetworkLibraryActivity.class
|
||||||
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
|
||||||
addLinkToIntent(intent, myLink);
|
addLinkToIntent(intent, myLink);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,14 +44,14 @@ import org.geometerplus.android.fbreader.network.action.*;
|
||||||
import org.geometerplus.android.util.UIUtil;
|
import org.geometerplus.android.util.UIUtil;
|
||||||
|
|
||||||
public class NetworkLibraryActivity extends TreeActivity implements NetworkLibrary.ChangeListener {
|
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 BASIC_AUTHENTICATION_CODE = 1;
|
||||||
protected static final int SIGNUP_CODE = 2;
|
protected static final int SIGNUP_CODE = 2;
|
||||||
protected static final int AUTO_SIGNIN_CODE = 3;
|
protected static final int AUTO_SIGNIN_CODE = 3;
|
||||||
|
|
||||||
BookDownloaderServiceConnection Connection;
|
BookDownloaderServiceConnection Connection;
|
||||||
|
|
||||||
private volatile Intent myDeferredIntent;
|
|
||||||
|
|
||||||
final List<Action> myOptionsMenuActions = new ArrayList<Action>();
|
final List<Action> myOptionsMenuActions = new ArrayList<Action>();
|
||||||
final List<Action> myContextMenuActions = new ArrayList<Action>();
|
final List<Action> myContextMenuActions = new ArrayList<Action>();
|
||||||
final List<Action> myListClickActions = 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);
|
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||||
|
|
||||||
if (getCurrentTree() instanceof RootTree) {
|
if (getCurrentTree() instanceof RootTree) {
|
||||||
myDeferredIntent = getIntent();
|
|
||||||
|
|
||||||
if (!NetworkLibrary.Instance().isInitialized()) {
|
if (!NetworkLibrary.Instance().isInitialized()) {
|
||||||
initLibrary();
|
Util.initLibrary(this);
|
||||||
} else {
|
} else {
|
||||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.InitializationFinished);
|
|
||||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
||||||
if (myDeferredIntent != null) {
|
|
||||||
processIntent(myDeferredIntent);
|
|
||||||
myDeferredIntent = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openTreeByIntent(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -127,11 +122,23 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
||||||
super.onDestroy();
|
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
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
|
if (!openTreeByIntent(intent)) {
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
|
}
|
||||||
processIntent(intent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -354,10 +361,6 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
||||||
break;
|
break;
|
||||||
case InitializationFinished:
|
case InitializationFinished:
|
||||||
NetworkLibrary.Instance().runBackgroundUpdate(false);
|
NetworkLibrary.Instance().runBackgroundUpdate(false);
|
||||||
if (myDeferredIntent != null) {
|
|
||||||
processIntent(myDeferredIntent);
|
|
||||||
myDeferredIntent = null;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Found:
|
case Found:
|
||||||
openTree((NetworkTree)params[0]);
|
openTree((NetworkTree)params[0]);
|
||||||
|
@ -387,39 +390,16 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
||||||
return tree;
|
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
|
@Override
|
||||||
protected void onCurrentTreeChanged() {
|
protected void onCurrentTreeChanged() {
|
||||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
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) {
|
private void showInitLibraryDialog(String error) {
|
||||||
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||||
initLibrary();
|
Util.initLibrary(NetworkLibraryActivity.this);
|
||||||
} else {
|
} else {
|
||||||
finish();
|
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.tree.NetworkBookTree;
|
||||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||||
|
|
||||||
|
import org.geometerplus.android.util.UIUtil;
|
||||||
import org.geometerplus.android.util.PackageUtil;
|
import org.geometerplus.android.util.PackageUtil;
|
||||||
|
|
||||||
public abstract class Util implements UserRegistrationConstants {
|
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)));
|
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) {
|
private static boolean testService(Activity activity, String action, String url) {
|
||||||
return url != null && PackageUtil.canBeStarted(activity, new Intent(action, Uri.parse(url)), true);
|
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;
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
public abstract class TreeActivity extends ListActivity {
|
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 TREE_KEY_KEY = "TreeKey";
|
||||||
public static final String SELECTED_TREE_KEY_KEY = "SelectedTreeKey";
|
public static final String SELECTED_TREE_KEY_KEY = "SelectedTreeKey";
|
||||||
|
|
|
@ -157,6 +157,19 @@ public class NetworkLibrary {
|
||||||
return null;
|
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) {
|
public INetworkLink getLinkBySiteName(String siteName) {
|
||||||
synchronized (myLinks) {
|
synchronized (myLinks) {
|
||||||
for (INetworkLink link : myLinks) {
|
for (INetworkLink link : myLinks) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue