Fix NPE in AddressEntryLoader
This commit is contained in:
@ -1,38 +1,43 @@
|
|||||||
package net.i2p.android.router.addressbook;
|
package net.i2p.android.router.addressbook;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v4.content.AsyncTaskLoader;
|
||||||
|
|
||||||
|
import net.i2p.android.router.I2PFragmentBase;
|
||||||
|
import net.i2p.android.router.util.NamingServiceUtil;
|
||||||
|
import net.i2p.android.router.util.Util;
|
||||||
|
import net.i2p.client.naming.NamingService;
|
||||||
|
import net.i2p.data.Destination;
|
||||||
|
import net.i2p.router.RouterContext;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import net.i2p.android.router.util.NamingServiceUtil;
|
|
||||||
import net.i2p.android.router.util.Util;
|
|
||||||
import net.i2p.client.naming.NamingService;
|
|
||||||
import net.i2p.data.Destination;
|
|
||||||
import net.i2p.router.RouterContext;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.support.v4.content.AsyncTaskLoader;
|
|
||||||
|
|
||||||
public class AddressEntryLoader extends AsyncTaskLoader<List<AddressEntry>> {
|
public class AddressEntryLoader extends AsyncTaskLoader<List<AddressEntry>> {
|
||||||
private RouterContext mRContext;
|
private I2PFragmentBase.RouterContextProvider mRContextProvider;
|
||||||
private String mBook;
|
private String mBook;
|
||||||
private String mFilter;
|
private String mFilter;
|
||||||
private List<AddressEntry> mData;
|
private List<AddressEntry> mData;
|
||||||
|
|
||||||
public AddressEntryLoader(Context context, RouterContext rContext,
|
public AddressEntryLoader(Context context, I2PFragmentBase.RouterContextProvider rContextProvider,
|
||||||
String book, String filter) {
|
String book, String filter) {
|
||||||
super(context);
|
super(context);
|
||||||
mRContext = rContext;
|
mRContextProvider = rContextProvider;
|
||||||
mBook = book;
|
mBook = book;
|
||||||
mFilter = filter;
|
mFilter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AddressEntry> loadInBackground() {
|
public List<AddressEntry> loadInBackground() {
|
||||||
|
RouterContext routerContext = mRContextProvider.getRouterContext();
|
||||||
|
if (routerContext == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
// get the names
|
// get the names
|
||||||
NamingService ns = NamingServiceUtil.getNamingService(mRContext, mBook);
|
NamingService ns = NamingServiceUtil.getNamingService(routerContext, mBook);
|
||||||
Util.d("NamingService: " + ns.getName());
|
Util.d("NamingService: " + ns.getName());
|
||||||
// After router shutdown we get nothing... why?
|
// After router shutdown we get nothing... why?
|
||||||
List<AddressEntry> ret = new ArrayList<AddressEntry>();
|
List<AddressEntry> ret = new ArrayList<AddressEntry>();
|
||||||
|
@ -249,27 +249,32 @@ public class AddressbookFragment extends ListFragment implements
|
|||||||
|
|
||||||
public Loader<List<AddressEntry>> onCreateLoader(int id, Bundle args) {
|
public Loader<List<AddressEntry>> onCreateLoader(int id, Bundle args) {
|
||||||
return new AddressEntryLoader(getActivity(),
|
return new AddressEntryLoader(getActivity(),
|
||||||
getRouterContext(), mBook, mCurFilter);
|
mRouterContextProvider, mBook, mCurFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLoadFinished(Loader<List<AddressEntry>> loader,
|
public void onLoadFinished(Loader<List<AddressEntry>> loader,
|
||||||
List<AddressEntry> data) {
|
List<AddressEntry> data) {
|
||||||
if (loader.getId() == (PRIVATE_BOOK.equals(mBook) ?
|
if (loader.getId() == (PRIVATE_BOOK.equals(mBook) ?
|
||||||
PRIVATE_LOADER_ID : ROUTER_LOADER_ID)) {
|
PRIVATE_LOADER_ID : ROUTER_LOADER_ID)) {
|
||||||
mAdapter.setData(data);
|
if (data == null)
|
||||||
|
setEmptyText(getResources().getString(
|
||||||
|
R.string.router_not_running));
|
||||||
|
else {
|
||||||
|
mAdapter.setData(data);
|
||||||
|
|
||||||
TextView v = (TextView) getListView().findViewWithTag("addressbook_header");
|
TextView v = (TextView) getListView().findViewWithTag("addressbook_header");
|
||||||
if (mCurFilter != null)
|
if (mCurFilter != null)
|
||||||
v.setText(getActivity().getResources().getString(
|
v.setText(getActivity().getResources().getString(
|
||||||
R.string.addressbook_search_header,
|
R.string.addressbook_search_header,
|
||||||
data.size()));
|
data.size()));
|
||||||
else
|
else
|
||||||
v.setText("");
|
v.setText("");
|
||||||
|
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
setListShown(true);
|
setListShown(true);
|
||||||
} else {
|
} else {
|
||||||
setListShownNoAnimation(true);
|
setListShownNoAnimation(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user