New callback system to make getRouterContext() reliable
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user