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

Skip to content
Snippets Groups Projects
Commit 01b07fed authored by str4d's avatar str4d
Browse files

Simplified callback system

parent 2fa205da
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,6 @@ public class AddressbookFragment extends ListFragment implements ...@@ -40,7 +40,6 @@ public class AddressbookFragment extends ListFragment implements
private static final int PRIVATE_LOADER_ID = 2; private static final int PRIVATE_LOADER_ID = 2;
private boolean mOnActivityCreated; private boolean mOnActivityCreated;
private boolean mOnRouterBind;
RouterContextProvider mRouterContextProvider; RouterContextProvider mRouterContextProvider;
OnAddressSelectedListener mCallback; OnAddressSelectedListener mCallback;
private AddressEntryAdapter mAdapter; private AddressEntryAdapter mAdapter;
...@@ -94,9 +93,7 @@ public class AddressbookFragment extends ListFragment implements ...@@ -94,9 +93,7 @@ public class AddressbookFragment extends ListFragment implements
setListAdapter(mAdapter); setListAdapter(mAdapter);
mOnActivityCreated = true; mOnActivityCreated = true;
// Check getRouterContext() in case this was not the if (getRouterContext() != null)
// active Fragment when onRouterBind() was called.
if (mOnRouterBind || getRouterContext() != null)
onRouterConnectionReady(); onRouterConnectionReady();
else else
setEmptyText(getResources().getString( setEmptyText(getResources().getString(
...@@ -104,32 +101,22 @@ public class AddressbookFragment extends ListFragment implements ...@@ -104,32 +101,22 @@ public class AddressbookFragment extends ListFragment implements
} }
public void onRouterConnectionReady() { public void onRouterConnectionReady() {
LoaderManager lm = getLoaderManager();
if (mAddWizardData != null) { if (mAddWizardData != null) {
if (getRouterContext() != null) { // Save the new entry
// Save the new entry Bundle entryData = mAddWizardData.getExtras().getBundle(ADD_WIZARD_DATA);
Bundle entryData = mAddWizardData.getExtras().getBundle(ADD_WIZARD_DATA); NamingService ns = NamingServiceUtil.getNamingService(getRouterContext(), mBook);
NamingService ns = NamingServiceUtil.getNamingService(getRouterContext(), mBook); boolean success = NamingServiceUtil.addFromWizard(getActivity(), ns, entryData, false);
boolean success = NamingServiceUtil.addFromWizard(getActivity(), ns, entryData, false); if (success) {
if (success) { // Reload the list
// Reload the list setListShown(false);
setListShown(false); getLoaderManager().restartLoader(PRIVATE_LOADER_ID, null, this);
getLoaderManager().restartLoader(PRIVATE_LOADER_ID, null, this);
}
} }
} else { } else {
// If the Router is running, or there is an existing Loader setEmptyText("No hosts in address book " + mBook);
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); setListShown(false);
lm.initLoader(PRIVATE_BOOK.equals(mBook) ? getLoaderManager().initLoader(PRIVATE_BOOK.equals(mBook) ?
PRIVATE_LOADER_ID : ROUTER_LOADER_ID, null, this); PRIVATE_LOADER_ID : ROUTER_LOADER_ID, null, this);
} else {
setEmptyText(getResources().getString(
R.string.router_not_running));
}
} }
} }
...@@ -195,7 +182,6 @@ public class AddressbookFragment extends ListFragment implements ...@@ -195,7 +182,6 @@ public class AddressbookFragment extends ListFragment implements
// I2PFragmentBase.RouterContextUser // I2PFragmentBase.RouterContextUser
public void onRouterBind() { public void onRouterBind() {
mOnRouterBind = true;
if (mOnActivityCreated) if (mOnActivityCreated)
onRouterConnectionReady(); onRouterConnectionReady();
} }
......
...@@ -14,7 +14,6 @@ import android.support.v4.app.Fragment; ...@@ -14,7 +14,6 @@ import android.support.v4.app.Fragment;
public class I2PFragmentBase extends Fragment { public class I2PFragmentBase extends Fragment {
private boolean mOnActivityCreated; private boolean mOnActivityCreated;
private boolean mOnRouterBind;
RouterContextProvider mCallback; RouterContextProvider mCallback;
protected static final String PREF_INSTALLED_VERSION = "app.version"; protected static final String PREF_INSTALLED_VERSION = "app.version";
...@@ -47,14 +46,13 @@ public class I2PFragmentBase extends Fragment { ...@@ -47,14 +46,13 @@ public class I2PFragmentBase extends Fragment {
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mOnActivityCreated = true; mOnActivityCreated = true;
// Check getRouterContext() in case this was not the if (getRouterContext() != null)
// active Fragment when onRouterBind() was called.
if (mOnRouterBind || getRouterContext() != null)
onRouterConnectionReady(); onRouterConnectionReady();
else
onRouterConnectionNotReady();
} }
public void onRouterBind() { public void onRouterBind() {
mOnRouterBind = true;
if (mOnActivityCreated) if (mOnActivityCreated)
onRouterConnectionReady(); onRouterConnectionReady();
} }
...@@ -62,6 +60,9 @@ public class I2PFragmentBase extends Fragment { ...@@ -62,6 +60,9 @@ public class I2PFragmentBase extends Fragment {
/** callback from I2PFragmentBase, override as necessary */ /** callback from I2PFragmentBase, override as necessary */
public void onRouterConnectionReady() {} public void onRouterConnectionReady() {}
/** callback from I2PFragmentBase, override as necessary */
public void onRouterConnectionNotReady() {}
protected RouterContext getRouterContext() { protected RouterContext getRouterContext() {
return mCallback.getRouterContext(); return mCallback.getRouterContext();
} }
......
...@@ -35,7 +35,6 @@ public class NetDbListFragment extends ListFragment implements ...@@ -35,7 +35,6 @@ public class NetDbListFragment extends ListFragment implements
private static final String STATE_ACTIVATED_POSITION = "activated_position"; private static final String STATE_ACTIVATED_POSITION = "activated_position";
private boolean mOnActivityCreated; private boolean mOnActivityCreated;
private boolean mOnRouterBind;
RouterContextProvider mRouterContextProvider; RouterContextProvider mRouterContextProvider;
OnEntrySelectedListener mEntrySelectedCallback; OnEntrySelectedListener mEntrySelectedCallback;
private NetDbEntryAdapter mAdapter; private NetDbEntryAdapter mAdapter;
...@@ -108,9 +107,7 @@ public class NetDbListFragment extends ListFragment implements ...@@ -108,9 +107,7 @@ public class NetDbListFragment extends ListFragment implements
setListAdapter(mAdapter); setListAdapter(mAdapter);
mOnActivityCreated = true; mOnActivityCreated = true;
// Check getRouterContext() in case this was not the if (getRouterContext() != null)
// active Fragment when onRouterBind() was called.
if (mOnRouterBind || getRouterContext() != null)
onRouterConnectionReady(); onRouterConnectionReady();
else else
setEmptyText(getResources().getString( setEmptyText(getResources().getString(
...@@ -118,21 +115,13 @@ public class NetDbListFragment extends ListFragment implements ...@@ -118,21 +115,13 @@ public class NetDbListFragment extends ListFragment implements
} }
public void onRouterConnectionReady() { public void onRouterConnectionReady() {
LoaderManager lm = getLoaderManager(); setEmptyText(getResources().getString((mRouters ?
// If the Router is running, or there is an existing Loader R.string.netdb_routers_empty :
if (getRouterContext() != null || lm.getLoader(mRouters ?
ROUTER_LOADER_ID : LEASESET_LOADER_ID) != null) {
setEmptyText(getResources().getString((mRouters ?
R.string.netdb_routers_empty :
R.string.netdb_leases_empty))); R.string.netdb_leases_empty)));
setListShown(false); setListShown(false);
lm.initLoader(mRouters ? ROUTER_LOADER_ID getLoaderManager().initLoader(mRouters ? ROUTER_LOADER_ID
: LEASESET_LOADER_ID, null, this); : LEASESET_LOADER_ID, null, this);
} else {
setEmptyText(getResources().getString(
R.string.router_not_running));
}
} }
@Override @Override
...@@ -199,7 +188,6 @@ public class NetDbListFragment extends ListFragment implements ...@@ -199,7 +188,6 @@ public class NetDbListFragment extends ListFragment implements
// I2PFragmentBase.RouterContextUser // I2PFragmentBase.RouterContextUser
public void onRouterBind() { public void onRouterBind() {
mOnRouterBind = true;
if (mOnActivityCreated) if (mOnActivityCreated)
onRouterConnectionReady(); onRouterConnectionReady();
} }
......
...@@ -58,14 +58,12 @@ public class NetDbSummaryPagerFragment extends I2PFragmentBase implements ...@@ -58,14 +58,12 @@ public class NetDbSummaryPagerFragment extends I2PFragmentBase implements
@Override @Override
public void onRouterConnectionReady() { public void onRouterConnectionReady() {
LoaderManager lm = getLoaderManager(); getLoaderManager().initLoader(0, null, this);
// If the Router is running, or there is an existing Loader }
if (getRouterContext() != null || lm.getLoader(0) != null) {
lm.initLoader(0, null, this); @Override
} else { public void onRouterConnectionNotReady() {
// Router is not running or is not bound yet. Util.i("Router not running or not bound to NetDbSummaryPagerFragment");
Util.i("Router not running or not bound to NetDbSummaryPagerFragment");
}
} }
@Override @Override
...@@ -78,10 +76,12 @@ public class NetDbSummaryPagerFragment extends I2PFragmentBase implements ...@@ -78,10 +76,12 @@ public class NetDbSummaryPagerFragment extends I2PFragmentBase implements
// Handle presses on the action bar items // Handle presses on the action bar items
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_refresh: case R.id.action_refresh:
Util.i("Refresh called, restarting Loader"); if (getRouterContext() != null) {
mNetDbPagerAdapter.setData(null); Util.i("Refresh called, restarting Loader");
mViewPager.invalidate(); mNetDbPagerAdapter.setData(null);
getLoaderManager().restartLoader(0, null, this); mViewPager.invalidate();
getLoaderManager().restartLoader(0, null, this);
}
return true; return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
......
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