mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-25 09:28:21 -05:00
BibleViewer uses OGHolder pattern too.
This commit is contained in:
parent
915467c465
commit
a0e9939954
@ -1,14 +1,10 @@
|
|||||||
package org.bspeice.minimalbible;
|
package org.bspeice.minimalbible;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import dagger.ObjectGraph;
|
import dagger.ObjectGraph;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,13 +13,22 @@ import dagger.ObjectGraph;
|
|||||||
* everything it could be extended to likely needs to be in
|
* everything it could be extended to likely needs to be in
|
||||||
* an ObjectGraph anyway.
|
* an ObjectGraph anyway.
|
||||||
* This works because getSupportFragmentManager() is scoped to each activity.
|
* This works because getSupportFragmentManager() is scoped to each activity.
|
||||||
* TODO: Prove the above claim.
|
|
||||||
*/
|
*/
|
||||||
public class OGHolder extends Fragment {
|
public class OGHolder extends Fragment {
|
||||||
private final static String TAG = "OGHolder";
|
private final static String TAG = "OGHolder";
|
||||||
|
|
||||||
private ObjectGraph mObjectGraph;
|
private ObjectGraph mObjectGraph;
|
||||||
|
|
||||||
|
public static OGHolder get(FragmentActivity activity) {
|
||||||
|
FragmentManager manager = activity.getSupportFragmentManager();
|
||||||
|
OGHolder holder = (OGHolder) manager.findFragmentByTag(TAG);
|
||||||
|
if (holder == null) {
|
||||||
|
holder = new OGHolder();
|
||||||
|
manager.beginTransaction().add(holder, TAG).commit();
|
||||||
|
}
|
||||||
|
return holder;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -37,14 +42,4 @@ public class OGHolder extends Fragment {
|
|||||||
public ObjectGraph fetchGraph() {
|
public ObjectGraph fetchGraph() {
|
||||||
return mObjectGraph;
|
return mObjectGraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OGHolder get(FragmentActivity activity) {
|
|
||||||
FragmentManager manager = activity.getSupportFragmentManager();
|
|
||||||
OGHolder holder = (OGHolder) manager.findFragmentByTag(TAG);
|
|
||||||
if (holder == null) {
|
|
||||||
holder = new OGHolder();
|
|
||||||
manager.beginTransaction().add(holder, TAG).commit();
|
|
||||||
}
|
|
||||||
return holder;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import android.view.MenuItem;
|
|||||||
|
|
||||||
import org.bspeice.minimalbible.Injector;
|
import org.bspeice.minimalbible.Injector;
|
||||||
import org.bspeice.minimalbible.MinimalBible;
|
import org.bspeice.minimalbible.MinimalBible;
|
||||||
|
import org.bspeice.minimalbible.OGHolder;
|
||||||
import org.bspeice.minimalbible.R;
|
import org.bspeice.minimalbible.R;
|
||||||
import org.bspeice.minimalbible.activity.BaseActivity;
|
import org.bspeice.minimalbible.activity.BaseActivity;
|
||||||
import org.bspeice.minimalbible.activity.BaseNavigationDrawerFragment;
|
import org.bspeice.minimalbible.activity.BaseNavigationDrawerFragment;
|
||||||
@ -32,13 +33,31 @@ public class BibleViewer extends BaseActivity implements
|
|||||||
@Inject BookManager bookManager;
|
@Inject BookManager bookManager;
|
||||||
|
|
||||||
private ObjectGraph bvObjectGraph;
|
private ObjectGraph bvObjectGraph;
|
||||||
|
/**
|
||||||
|
* Fragment managing the behaviors, interactions and presentation of the
|
||||||
|
* navigation drawer.
|
||||||
|
*/
|
||||||
|
private ViewerNavDrawerFragment mNavigationDrawerFragment;
|
||||||
|
/**
|
||||||
|
* Used to store the last screen title. For use in
|
||||||
|
* {@link #restoreActionBar()}.
|
||||||
|
*/
|
||||||
|
private CharSequence mTitle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a scoped object graph for anything used by the DownloadActivity
|
* Build a scoped object graph for anything used by the DownloadActivity
|
||||||
*/
|
*/
|
||||||
private void buildObjGraph() {
|
private void buildObjGraph() {
|
||||||
if (bvObjectGraph == null) {
|
if (bvObjectGraph == null) {
|
||||||
bvObjectGraph = MinimalBible.get(this)
|
OGHolder holder = OGHolder.get(this);
|
||||||
.plus(new BibleViewerModules(this));
|
ObjectGraph holderGraph = holder.fetchGraph();
|
||||||
|
if (holderGraph == null) {
|
||||||
|
bvObjectGraph = MinimalBible.get(this)
|
||||||
|
.plus(new BibleViewerModules(this));
|
||||||
|
holder.persistGraph(holderGraph);
|
||||||
|
} else {
|
||||||
|
bvObjectGraph = holderGraph;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bvObjectGraph.inject(this);
|
bvObjectGraph.inject(this);
|
||||||
}
|
}
|
||||||
@ -49,18 +68,6 @@ public class BibleViewer extends BaseActivity implements
|
|||||||
bvObjectGraph.inject(o);
|
bvObjectGraph.inject(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fragment managing the behaviors, interactions and presentation of the
|
|
||||||
* navigation drawer.
|
|
||||||
*/
|
|
||||||
private ViewerNavDrawerFragment mNavigationDrawerFragment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to store the last screen title. For use in
|
|
||||||
* {@link #restoreActionBar()}.
|
|
||||||
*/
|
|
||||||
private CharSequence mTitle;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Loading…
Reference in New Issue
Block a user