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

Skip to content
Snippets Groups Projects
Commit 9832779a authored by str4d's avatar str4d
Browse files

New callback system to make getRouterContext() reliable

parent 9f535a32
No related branches found
No related tags found
No related merge requests found
......@@ -406,7 +406,13 @@ public abstract class I2PActivityBase extends ActionBarActivity implements
}
/** callback from ServiceConnection, override as necessary */
protected void onRouterBind(RouterService svc) {}
protected void onRouterBind(RouterService svc) {
Fragment f = getSupportFragmentManager().findFragmentById(R.id.main_fragment);
if (f instanceof I2PFragmentBase)
((I2PFragmentBase) f).onRouterBind();
else if (f instanceof I2PFragmentBase.RouterContextUser)
((I2PFragmentBase.RouterContextUser) f).onRouterBind();
}
/** callback from ServiceConnection, override as necessary */
protected void onRouterUnbind() {}
......
......@@ -9,13 +9,20 @@ import net.i2p.router.peermanager.ProfileOrganizer;
import net.i2p.router.transport.FIFOBandwidthLimiter;
import net.i2p.stat.StatManager;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
public class I2PFragmentBase extends Fragment {
private boolean mOnActivityCreated;
private boolean mOnRouterBind;
RouterContextProvider mCallback;
protected static final String PREF_INSTALLED_VERSION = "app.version";
public interface RouterContextUser {
public void onRouterBind();
}
// Container Activity must implement this interface
public interface RouterContextProvider {
public RouterContext getRouterContext();
......@@ -36,6 +43,23 @@ public class I2PFragmentBase extends Fragment {
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mOnActivityCreated = true;
if (mOnRouterBind)
onRouterConnectionReady();
}
public void onRouterBind() {
mOnRouterBind = true;
if (mOnActivityCreated)
onRouterConnectionReady();
}
/** callback from I2PFragmentBase, override as necessary */
public void onRouterConnectionReady() {}
protected RouterContext getRouterContext() {
return mCallback.getRouterContext();
}
......
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