I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 2c8e9d62 authored by str4d's avatar str4d
Browse files

Use new callbacks in AddressbookFragment

parent 9832779a
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ import net.i2p.client.naming.NamingService;
import net.i2p.router.RouterContext;
public class AddressbookFragment extends ListFragment implements
I2PFragmentBase.RouterContextUser,
LoaderManager.LoaderCallbacks<List<AddressEntry>> {
public static final String BOOK_NAME = "book_name";
public static final String ROUTER_BOOK = "hosts.txt";
......@@ -38,12 +39,17 @@ public class AddressbookFragment extends ListFragment implements
private static final int ROUTER_LOADER_ID = 1;
private static final int PRIVATE_LOADER_ID = 2;
private boolean mOnActivityCreated;
private boolean mOnRouterBind;
RouterContextProvider mRouterContextProvider;
OnAddressSelectedListener mCallback;
private AddressEntryAdapter mAdapter;
private String mBook;
private String mCurFilter;
// Set in onActivityResult()
private Intent mAddWizardData;
// Container Activity must implement this interface
public interface OnAddressSelectedListener {
public void onAddressSelected(CharSequence host);
......@@ -87,18 +93,38 @@ public class AddressbookFragment extends ListFragment implements
setListAdapter(mAdapter);
mOnActivityCreated = true;
if (mOnRouterBind)
onRouterConnectionReady();
}
public void onRouterConnectionReady() {
LoaderManager lm = getLoaderManager();
// If the Router is running, or there is an existing Loader
if (getRouterContext() != null || lm.getLoader(PRIVATE_BOOK.equals(mBook) ?
PRIVATE_LOADER_ID : ROUTER_LOADER_ID) != null) {
setEmptyText("No hosts in address book " + mBook);
setListShown(false);
lm.initLoader(PRIVATE_BOOK.equals(mBook) ?
PRIVATE_LOADER_ID : ROUTER_LOADER_ID, null, this);
if (mAddWizardData != null) {
if (getRouterContext() != null) {
// Save the new entry
Bundle entryData = mAddWizardData.getExtras().getBundle(ADD_WIZARD_DATA);
NamingService ns = NamingServiceUtil.getNamingService(getRouterContext(), mBook);
boolean success = NamingServiceUtil.addFromWizard(getActivity(), ns, entryData, false);
if (success) {
// Reload the list
setListShown(false);
getLoaderManager().restartLoader(PRIVATE_LOADER_ID, null, this);
}
}
} else {
setEmptyText(getResources().getString(
R.string.router_not_running));
// If the Router is running, or there is an existing Loader
if (getRouterContext() != null || lm.getLoader(PRIVATE_BOOK.equals(mBook) ?
PRIVATE_LOADER_ID : ROUTER_LOADER_ID) != null) {
setEmptyText("No hosts in address book " + mBook);
setListShown(false);
lm.initLoader(PRIVATE_BOOK.equals(mBook) ?
PRIVATE_LOADER_ID : ROUTER_LOADER_ID, null, this);
} else {
setEmptyText(getResources().getString(
R.string.router_not_running));
}
}
}
......@@ -145,17 +171,7 @@ public class AddressbookFragment extends ListFragment implements
if (requestCode == ADD_WIZARD_REQUEST &&
resultCode == Activity.RESULT_OK &&
PRIVATE_BOOK.equals(mBook)) {
if (getRouterContext() != null) {
// Save the new entry
Bundle entryData = data.getExtras().getBundle(ADD_WIZARD_DATA);
NamingService ns = NamingServiceUtil.getNamingService(getRouterContext(), mBook);
boolean success = NamingServiceUtil.addFromWizard(getActivity(), ns, entryData, false);
if (success) {
// Reload the list
setListShown(false);
getLoaderManager().restartLoader(PRIVATE_LOADER_ID, null, this);
}
}
mAddWizardData = data;
}
}
......@@ -171,6 +187,14 @@ public class AddressbookFragment extends ListFragment implements
return mRouterContextProvider.getRouterContext();
}
// I2PFragmentBase.RouterContextUser
public void onRouterBind() {
mOnRouterBind = true;
if (mOnActivityCreated)
onRouterConnectionReady();
}
// LoaderManager.LoaderCallbacks<List<AddressEntry>>
public Loader<List<AddressEntry>> onCreateLoader(int id, Bundle args) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment